Skip to content

Commit 5e676c8

Browse files
author
eugenp
committed
testing work
1 parent 2ab201d commit 5e676c8

9 files changed

Lines changed: 18 additions & 40 deletions

File tree

‎core-java/pom.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@
162162
<configuration>
163163
<excludes>
164164
<exclude>**/*IntegrationTest.java</exclude>
165+
<exclude>**/*LongRunningUnitTest.java</exclude>
166+
<exclude>**/*ManualTest.java</exclude>
165167
</excludes>
166168
</configuration>
167169
</plugin>

core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureTest.java renamed to core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package com.baeldung.completablefuture;
22

3-
import java.util.concurrent.*;
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import java.util.concurrent.CancellationException;
7+
import java.util.concurrent.CompletableFuture;
8+
import java.util.concurrent.ExecutionException;
9+
import java.util.concurrent.Executors;
10+
import java.util.concurrent.Future;
411
import java.util.stream.Collectors;
512
import java.util.stream.Stream;
613

714
import org.junit.Test;
815

9-
import static org.junit.Assert.assertEquals;
10-
import static org.junit.Assert.assertTrue;
11-
12-
public class CompletableFutureTest {
16+
public class CompletableFutureLongRunningUnitTest {
1317

1418
@Test
1519
public void whenRunningCompletableFutureAsynchronously_thenGetMethodWaitsForResult() throws InterruptedException, ExecutionException {
16-
1720
Future<String> completableFuture = calculateAsync();
1821

1922
String result = completableFuture.get();
2023
assertEquals("Hello", result);
21-
2224
}
2325

2426
public Future<String> calculateAsync() throws InterruptedException {
@@ -35,12 +37,10 @@ public Future<String> calculateAsync() throws InterruptedException {
3537

3638
@Test
3739
public void whenRunningCompletableFutureWithResult_thenGetMethodReturnsImmediately() throws InterruptedException, ExecutionException {
38-
3940
Future<String> completableFuture = CompletableFuture.completedFuture("Hello");
4041

4142
String result = completableFuture.get();
4243
assertEquals("Hello", result);
43-
4444
}
4545

4646
public Future<String> calculateAsyncWithCancellation() throws InterruptedException {
@@ -57,82 +57,65 @@ public Future<String> calculateAsyncWithCancellation() throws InterruptedExcepti
5757

5858
@Test(expected = CancellationException.class)
5959
public void whenCancelingTheFuture_thenThrowsCancellationException() throws ExecutionException, InterruptedException {
60-
6160
Future<String> future = calculateAsyncWithCancellation();
6261
future.get();
63-
6462
}
6563

6664
@Test
6765
public void whenCreatingCompletableFutureWithSupplyAsync_thenFutureReturnsValue() throws ExecutionException, InterruptedException {
68-
6966
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> "Hello");
7067

7168
assertEquals("Hello", future.get());
72-
7369
}
7470

7571
@Test
7672
public void whenAddingThenAcceptToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException {
77-
7873
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello");
7974

8075
CompletableFuture<Void> future = completableFuture.thenAccept(s -> System.out.println("Computation returned: " + s));
8176

8277
future.get();
83-
8478
}
8579

8680
@Test
8781
public void whenAddingThenRunToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException {
88-
8982
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello");
9083

9184
CompletableFuture<Void> future = completableFuture.thenRun(() -> System.out.println("Computation finished."));
9285

9386
future.get();
94-
9587
}
9688

9789
@Test
9890
public void whenAddingThenApplyToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException {
99-
10091
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello");
10192

10293
CompletableFuture<String> future = completableFuture.thenApply(s -> s + " World");
10394

10495
assertEquals("Hello World", future.get());
105-
10696
}
10797

10898
@Test
10999
public void whenUsingThenCompose_thenFuturesExecuteSequentially() throws ExecutionException, InterruptedException {
110-
111100
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello").thenCompose(s -> CompletableFuture.supplyAsync(() -> s + " World"));
112101

113102
assertEquals("Hello World", completableFuture.get());
114-
115103
}
116104

117105
@Test
118106
public void whenUsingThenCombine_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException {
119-
120107
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello").thenCombine(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> s1 + s2);
121108

122109
assertEquals("Hello World", completableFuture.get());
123-
124110
}
125111

126112
@Test
127113
public void whenUsingThenAcceptBoth_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException {
128-
129114
CompletableFuture.supplyAsync(() -> "Hello").thenAcceptBoth(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> System.out.println(s1 + s2));
130-
131115
}
132116

133117
@Test
134118
public void whenFutureCombinedWithAllOfCompletes_thenAllFuturesAreDone() throws ExecutionException, InterruptedException {
135-
136119
CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> "Hello");
137120
CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> "Beautiful");
138121
CompletableFuture<String> future3 = CompletableFuture.supplyAsync(() -> "World");
@@ -150,12 +133,10 @@ public void whenFutureCombinedWithAllOfCompletes_thenAllFuturesAreDone() throws
150133
String combined = Stream.of(future1, future2, future3).map(CompletableFuture::join).collect(Collectors.joining(" "));
151134

152135
assertEquals("Hello Beautiful World", combined);
153-
154136
}
155137

156138
@Test
157139
public void whenFutureThrows_thenHandleMethodReceivesException() throws ExecutionException, InterruptedException {
158-
159140
String name = null;
160141

161142
// ...
@@ -168,12 +149,10 @@ public void whenFutureThrows_thenHandleMethodReceivesException() throws Executio
168149
}).handle((s, t) -> s != null ? s : "Hello, Stranger!");
169150

170151
assertEquals("Hello, Stranger!", completableFuture.get());
171-
172152
}
173153

174154
@Test(expected = ExecutionException.class)
175155
public void whenCompletingFutureExceptionally_thenGetMethodThrows() throws ExecutionException, InterruptedException {
176-
177156
CompletableFuture<String> completableFuture = new CompletableFuture<>();
178157

179158
// ...
@@ -183,18 +162,15 @@ public void whenCompletingFutureExceptionally_thenGetMethodThrows() throws Execu
183162
// ...
184163

185164
completableFuture.get();
186-
187165
}
188166

189167
@Test
190168
public void whenAddingThenApplyAsyncToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException {
191-
192169
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> "Hello");
193170

194171
CompletableFuture<String> future = completableFuture.thenApplyAsync(s -> s + " World");
195172

196173
assertEquals("Hello World", future.get());
197-
198174
}
199175

200176
}

core-java/src/test/java/org/baeldung/java/JavaIoIntegrationTest.java renamed to core-java/src/test/java/org/baeldung/java/JavaIoUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import com.google.common.base.Charsets;
1515
import com.google.common.io.Files;
1616

17-
public class JavaIoIntegrationTest {
17+
public class JavaIoUnitTest {
1818
protected final Logger logger = LoggerFactory.getLogger(getClass());
1919

2020
// tests - iterate lines in a file

core-java/src/test/java/org/baeldung/java/JavaTimerUnitTest.java renamed to core-java/src/test/java/org/baeldung/java/JavaTimerLongRunningUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import org.junit.Test;
1111

12-
public class JavaTimerUnitTest {
12+
public class JavaTimerLongRunningUnitTest {
1313

1414
// tests
1515

core-java/src/test/java/org/baeldung/java/io/JavaFileIntegrationTest.java renamed to core-java/src/test/java/org/baeldung/java/io/JavaFileUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.apache.commons.io.FileUtils;
1414
import org.junit.Test;
1515

16-
public class JavaFileIntegrationTest {
16+
public class JavaFileUnitTest {
1717

1818
// create a file
1919

core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileIntegrationTest.java renamed to core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import org.junit.Test;
2525

26-
public class JavaReadFromFileIntegrationTest {
26+
public class JavaReadFromFileUnitTest {
2727

2828
@Test
2929
public void whenReadWithBufferedReader_thenCorrect() throws IOException {

core-java/src/test/java/org/baeldung/java/io/JavaScannerIntegrationTest.java renamed to core-java/src/test/java/org/baeldung/java/io/JavaScannerUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import org.junit.Test;
1717

18-
public class JavaScannerIntegrationTest {
18+
public class JavaScannerUnitTest {
1919

2020
@Test
2121
public void whenReadFileWithScanner_thenCorrect() throws IOException {

core-java/src/test/java/org/baeldung/java/io/JavaWriteToFileIntegrationTest.java renamed to core-java/src/test/java/org/baeldung/java/io/JavaWriteToFileUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import org.junit.Test;
2828

29-
public class JavaWriteToFileIntegrationTest {
29+
public class JavaWriteToFileUnitTest {
3030

3131
private String fileName = "src/test/resources/test_write.txt";
3232
private String fileName1 = "src/test/resources/test_write_1.txt";

core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaUnitTest.java renamed to core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaManualTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import org.junit.Test;
88

9-
public class SandboxJavaUnitTest {
9+
public class SandboxJavaManualTest {
1010

1111
@Test
1212
public void givenUsingTimer_whenSchedulingTimerTaskOnce_thenCorrect() throws InterruptedException {

0 commit comments

Comments
 (0)