From 5e676c855e96d52d6efc4a2a52fa74d99b50dcbd Mon Sep 17 00:00:00 2001 From: eugenp Date: Tue, 25 Oct 2016 11:15:13 +0300 Subject: [PATCH] testing work --- core-java/pom.xml | 2 + ...CompletableFutureLongRunningUnitTest.java} | 42 ++++--------------- ...tegrationTest.java => JavaIoUnitTest.java} | 2 +- ...java => JavaTimerLongRunningUnitTest.java} | 2 +- ...grationTest.java => JavaFileUnitTest.java} | 2 +- ...est.java => JavaReadFromFileUnitTest.java} | 2 +- ...tionTest.java => JavaScannerUnitTest.java} | 2 +- ...Test.java => JavaWriteToFileUnitTest.java} | 2 +- ...itTest.java => SandboxJavaManualTest.java} | 2 +- 9 files changed, 18 insertions(+), 40 deletions(-) rename core-java/src/test/java/com/baeldung/completablefuture/{CompletableFutureTest.java => CompletableFutureLongRunningUnitTest.java} (96%) rename core-java/src/test/java/org/baeldung/java/{JavaIoIntegrationTest.java => JavaIoUnitTest.java} (98%) rename core-java/src/test/java/org/baeldung/java/{JavaTimerUnitTest.java => JavaTimerLongRunningUnitTest.java} (98%) rename core-java/src/test/java/org/baeldung/java/io/{JavaFileIntegrationTest.java => JavaFileUnitTest.java} (99%) rename core-java/src/test/java/org/baeldung/java/io/{JavaReadFromFileIntegrationTest.java => JavaReadFromFileUnitTest.java} (99%) rename core-java/src/test/java/org/baeldung/java/io/{JavaScannerIntegrationTest.java => JavaScannerUnitTest.java} (99%) rename core-java/src/test/java/org/baeldung/java/io/{JavaWriteToFileIntegrationTest.java => JavaWriteToFileUnitTest.java} (99%) rename core-java/src/test/java/org/baeldung/java/sandbox/{SandboxJavaUnitTest.java => SandboxJavaManualTest.java} (98%) diff --git a/core-java/pom.xml b/core-java/pom.xml index 75608b59ba..b39e356977 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -162,6 +162,8 @@ **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java diff --git a/core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureTest.java b/core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java similarity index 96% rename from core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureTest.java rename to core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java index d337382934..2500bf590a 100644 --- a/core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureTest.java +++ b/core-java/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java @@ -1,24 +1,26 @@ package com.baeldung.completablefuture; -import java.util.concurrent.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class CompletableFutureTest { +public class CompletableFutureLongRunningUnitTest { @Test public void whenRunningCompletableFutureAsynchronously_thenGetMethodWaitsForResult() throws InterruptedException, ExecutionException { - Future completableFuture = calculateAsync(); String result = completableFuture.get(); assertEquals("Hello", result); - } public Future calculateAsync() throws InterruptedException { @@ -35,12 +37,10 @@ public class CompletableFutureTest { @Test public void whenRunningCompletableFutureWithResult_thenGetMethodReturnsImmediately() throws InterruptedException, ExecutionException { - Future completableFuture = CompletableFuture.completedFuture("Hello"); String result = completableFuture.get(); assertEquals("Hello", result); - } public Future calculateAsyncWithCancellation() throws InterruptedException { @@ -57,82 +57,65 @@ public class CompletableFutureTest { @Test(expected = CancellationException.class) public void whenCancelingTheFuture_thenThrowsCancellationException() throws ExecutionException, InterruptedException { - Future future = calculateAsyncWithCancellation(); future.get(); - } @Test public void whenCreatingCompletableFutureWithSupplyAsync_thenFutureReturnsValue() throws ExecutionException, InterruptedException { - CompletableFuture future = CompletableFuture.supplyAsync(() -> "Hello"); assertEquals("Hello", future.get()); - } @Test public void whenAddingThenAcceptToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException { - CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> "Hello"); CompletableFuture future = completableFuture.thenAccept(s -> System.out.println("Computation returned: " + s)); future.get(); - } @Test public void whenAddingThenRunToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException { - CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> "Hello"); CompletableFuture future = completableFuture.thenRun(() -> System.out.println("Computation finished.")); future.get(); - } @Test public void whenAddingThenApplyToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException { - CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> "Hello"); CompletableFuture future = completableFuture.thenApply(s -> s + " World"); assertEquals("Hello World", future.get()); - } @Test public void whenUsingThenCompose_thenFuturesExecuteSequentially() throws ExecutionException, InterruptedException { - CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> "Hello").thenCompose(s -> CompletableFuture.supplyAsync(() -> s + " World")); assertEquals("Hello World", completableFuture.get()); - } @Test public void whenUsingThenCombine_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException { - CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> "Hello").thenCombine(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> s1 + s2); assertEquals("Hello World", completableFuture.get()); - } @Test public void whenUsingThenAcceptBoth_thenWaitForExecutionOfBothFutures() throws ExecutionException, InterruptedException { - CompletableFuture.supplyAsync(() -> "Hello").thenAcceptBoth(CompletableFuture.supplyAsync(() -> " World"), (s1, s2) -> System.out.println(s1 + s2)); - } @Test public void whenFutureCombinedWithAllOfCompletes_thenAllFuturesAreDone() throws ExecutionException, InterruptedException { - CompletableFuture future1 = CompletableFuture.supplyAsync(() -> "Hello"); CompletableFuture future2 = CompletableFuture.supplyAsync(() -> "Beautiful"); CompletableFuture future3 = CompletableFuture.supplyAsync(() -> "World"); @@ -150,12 +133,10 @@ public class CompletableFutureTest { String combined = Stream.of(future1, future2, future3).map(CompletableFuture::join).collect(Collectors.joining(" ")); assertEquals("Hello Beautiful World", combined); - } @Test public void whenFutureThrows_thenHandleMethodReceivesException() throws ExecutionException, InterruptedException { - String name = null; // ... @@ -168,12 +149,10 @@ public class CompletableFutureTest { }).handle((s, t) -> s != null ? s : "Hello, Stranger!"); assertEquals("Hello, Stranger!", completableFuture.get()); - } @Test(expected = ExecutionException.class) public void whenCompletingFutureExceptionally_thenGetMethodThrows() throws ExecutionException, InterruptedException { - CompletableFuture completableFuture = new CompletableFuture<>(); // ... @@ -183,18 +162,15 @@ public class CompletableFutureTest { // ... completableFuture.get(); - } @Test public void whenAddingThenApplyAsyncToFuture_thenFunctionExecutesAfterComputationIsFinished() throws ExecutionException, InterruptedException { - CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> "Hello"); CompletableFuture future = completableFuture.thenApplyAsync(s -> s + " World"); assertEquals("Hello World", future.get()); - } } \ No newline at end of file diff --git a/core-java/src/test/java/org/baeldung/java/JavaIoIntegrationTest.java b/core-java/src/test/java/org/baeldung/java/JavaIoUnitTest.java similarity index 98% rename from core-java/src/test/java/org/baeldung/java/JavaIoIntegrationTest.java rename to core-java/src/test/java/org/baeldung/java/JavaIoUnitTest.java index ff92410bc4..501f2ffca0 100644 --- a/core-java/src/test/java/org/baeldung/java/JavaIoIntegrationTest.java +++ b/core-java/src/test/java/org/baeldung/java/JavaIoUnitTest.java @@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Charsets; import com.google.common.io.Files; -public class JavaIoIntegrationTest { +public class JavaIoUnitTest { protected final Logger logger = LoggerFactory.getLogger(getClass()); // tests - iterate lines in a file diff --git a/core-java/src/test/java/org/baeldung/java/JavaTimerUnitTest.java b/core-java/src/test/java/org/baeldung/java/JavaTimerLongRunningUnitTest.java similarity index 98% rename from core-java/src/test/java/org/baeldung/java/JavaTimerUnitTest.java rename to core-java/src/test/java/org/baeldung/java/JavaTimerLongRunningUnitTest.java index fcc74dbe64..da316aa885 100644 --- a/core-java/src/test/java/org/baeldung/java/JavaTimerUnitTest.java +++ b/core-java/src/test/java/org/baeldung/java/JavaTimerLongRunningUnitTest.java @@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit; import org.junit.Test; -public class JavaTimerUnitTest { +public class JavaTimerLongRunningUnitTest { // tests diff --git a/core-java/src/test/java/org/baeldung/java/io/JavaFileIntegrationTest.java b/core-java/src/test/java/org/baeldung/java/io/JavaFileUnitTest.java similarity index 99% rename from core-java/src/test/java/org/baeldung/java/io/JavaFileIntegrationTest.java rename to core-java/src/test/java/org/baeldung/java/io/JavaFileUnitTest.java index 24213ba869..f39ba80c08 100644 --- a/core-java/src/test/java/org/baeldung/java/io/JavaFileIntegrationTest.java +++ b/core-java/src/test/java/org/baeldung/java/io/JavaFileUnitTest.java @@ -13,7 +13,7 @@ import java.nio.file.Paths; import org.apache.commons.io.FileUtils; import org.junit.Test; -public class JavaFileIntegrationTest { +public class JavaFileUnitTest { // create a file diff --git a/core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileIntegrationTest.java b/core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java similarity index 99% rename from core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileIntegrationTest.java rename to core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java index b87f6e606f..2aa3b366ba 100644 --- a/core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileIntegrationTest.java +++ b/core-java/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java @@ -23,7 +23,7 @@ import java.util.Scanner; import org.junit.Test; -public class JavaReadFromFileIntegrationTest { +public class JavaReadFromFileUnitTest { @Test public void whenReadWithBufferedReader_thenCorrect() throws IOException { diff --git a/core-java/src/test/java/org/baeldung/java/io/JavaScannerIntegrationTest.java b/core-java/src/test/java/org/baeldung/java/io/JavaScannerUnitTest.java similarity index 99% rename from core-java/src/test/java/org/baeldung/java/io/JavaScannerIntegrationTest.java rename to core-java/src/test/java/org/baeldung/java/io/JavaScannerUnitTest.java index 89a84d9d7d..5af286dbca 100644 --- a/core-java/src/test/java/org/baeldung/java/io/JavaScannerIntegrationTest.java +++ b/core-java/src/test/java/org/baeldung/java/io/JavaScannerUnitTest.java @@ -15,7 +15,7 @@ import java.util.Scanner; import org.junit.Test; -public class JavaScannerIntegrationTest { +public class JavaScannerUnitTest { @Test public void whenReadFileWithScanner_thenCorrect() throws IOException { diff --git a/core-java/src/test/java/org/baeldung/java/io/JavaWriteToFileIntegrationTest.java b/core-java/src/test/java/org/baeldung/java/io/JavaWriteToFileUnitTest.java similarity index 99% rename from core-java/src/test/java/org/baeldung/java/io/JavaWriteToFileIntegrationTest.java rename to core-java/src/test/java/org/baeldung/java/io/JavaWriteToFileUnitTest.java index 54b40a070c..9ff95c4e16 100644 --- a/core-java/src/test/java/org/baeldung/java/io/JavaWriteToFileIntegrationTest.java +++ b/core-java/src/test/java/org/baeldung/java/io/JavaWriteToFileUnitTest.java @@ -26,7 +26,7 @@ import java.nio.file.Paths; import org.junit.Test; -public class JavaWriteToFileIntegrationTest { +public class JavaWriteToFileUnitTest { private String fileName = "src/test/resources/test_write.txt"; private String fileName1 = "src/test/resources/test_write_1.txt"; diff --git a/core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaUnitTest.java b/core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaManualTest.java similarity index 98% rename from core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaUnitTest.java rename to core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaManualTest.java index 6bd29982dc..bb849d6a13 100644 --- a/core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaUnitTest.java +++ b/core-java/src/test/java/org/baeldung/java/sandbox/SandboxJavaManualTest.java @@ -6,7 +6,7 @@ import java.util.TimerTask; import org.junit.Test; -public class SandboxJavaUnitTest { +public class SandboxJavaManualTest { @Test public void givenUsingTimer_whenSchedulingTimerTaskOnce_thenCorrect() throws InterruptedException {