fix: 单元测试

This commit is contained in:
2024-07-11 09:33:48 +08:00
parent 600076bc59
commit 3b4fdf64dd

View File

@@ -9,6 +9,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.Scanner;
import java.util.concurrent.*;
/**
* @Author: lyd
@@ -32,9 +33,9 @@ public class ApplicationTest {
System.out.println("请输入第一个数:");
int c = scanner.nextInt();
//求最小值
int min = (((a < b) ? a : b) < c) ?((a < b) ? a : b):c;
int min = (((a < b) ? a : b) < c) ? ((a < b) ? a : b) : c;
//求最大值
int max = (((a > b) ? a : b) > c) ?((a > b) ? a : b):c;
int max = (((a > b) ? a : b) > c) ? ((a > b) ? a : b) : c;
//求中间值
int mid = a + b + c - max - min;
//排序
@@ -50,10 +51,32 @@ public class ApplicationTest {
}
@org.testng.annotations.Test
@Test
void demo1() {
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
try {
Thread.sleep(3000); // 假设这是一个耗时的操作
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted", e);
}
return "Result";
});
try {
String result = future.get(2, TimeUnit.SECONDS); // 设置超时时间为2秒
System.out.println(result);
} catch (CompletionException e) {
Throwable cause = e.getCause();
if (cause instanceof TimeoutException) {
System.out.println("Operation timed out");
} else {
throw e; // rethrow other exceptions
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}