Migrate to JUnit5

This commit is contained in:
Artur Mogozov 2017-12-31 16:29:48 +09:00
parent a20e54d0a7
commit 6694d742a3
408 changed files with 2656 additions and 2165 deletions

View File

@ -34,8 +34,13 @@
<artifactId>abstract-document</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.abstractdocument;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap;
@ -30,8 +30,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* AbstractDocument test class

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.abstractdocument;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Simple App test

View File

@ -28,13 +28,13 @@ import com.iluwatar.abstractdocument.domain.HasParts;
import com.iluwatar.abstractdocument.domain.HasPrice;
import com.iluwatar.abstractdocument.domain.HasType;
import com.iluwatar.abstractdocument.domain.Part;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import static junit.framework.TestCase.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Part and Car

View File

@ -34,8 +34,13 @@
<artifactId>abstract-factory</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,14 +22,14 @@
*/
package com.iluwatar.abstractfactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.iluwatar.abstractfactory.App.FactoryMaker;
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Test for abstract factory
@ -40,7 +40,7 @@ public class AbstractFactoryTest {
private KingdomFactory elfFactory;
private KingdomFactory orcFactory;
@Before
@BeforeEach
public void setUp() {
elfFactory = FactoryMaker.makeFactory(KingdomType.ELF);
orcFactory = FactoryMaker.makeFactory(KingdomType.ORC);

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.abstractfactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;

View File

@ -34,8 +34,13 @@
<artifactId>adapter</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,8 +22,8 @@
*/
package com.iluwatar.adapter;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
@ -46,7 +46,7 @@ public class AdapterPatternTest {
/**
* This method runs before the test execution and sets the bean objects in the beans Map.
*/
@Before
@BeforeEach
public void setup() {
beans = new HashMap<>();

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.adapter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;

View File

@ -54,8 +54,13 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,15 +22,15 @@
*/
package com.iluwatar.aggregator.microservices;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
/**
* Test Aggregation of domain objects
*/
@ -45,7 +45,7 @@ public class AggregatorTest {
@Mock
private ProductInventoryClient inventoryClient;
@Before
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
}

View File

@ -54,8 +54,13 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,8 +22,9 @@
*/
package com.iluwatar.information.microservice;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Information Rest Controller
@ -36,7 +37,7 @@ public class InformationControllerTest {
String title = infoController.getProductTitle();
Assert.assertEquals("The Product Title.", title);
assertEquals("The Product Title.", title);
}
}

View File

@ -54,8 +54,13 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,8 +22,9 @@
*/
package com.iluwatar.inventory.microservice;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test Inventory Rest Controller
@ -35,6 +36,6 @@ public class InventoryControllerTest {
int numberOfInventories = inventoryController.getProductInventories();
Assert.assertEquals(5, numberOfInventories);
assertEquals(5, numberOfInventories);
}
}

View File

@ -53,8 +53,13 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,15 +22,15 @@
*/
package com.iluwatar.api.gateway;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
/**
* Test API Gateway Pattern
*/
@ -45,7 +45,7 @@ public class ApiGatewayTest {
@Mock
private PriceClient priceClient;
@Before
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
}

View File

@ -54,8 +54,13 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,8 +22,9 @@
*/
package com.iluwatar.image.microservice;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Image Rest Controller
@ -35,6 +36,6 @@ public class ImageControllerTest {
String imagePath = imageController.getImagePath();
Assert.assertEquals("/product-image.png", imagePath);
assertEquals("/product-image.png", imagePath);
}
}

View File

@ -54,8 +54,13 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,9 +22,9 @@
*/
package com.iluwatar.price.microservice;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Price Rest Controller
@ -36,6 +36,6 @@ public class PriceControllerTest {
String price = priceController.getPrice();
Assert.assertEquals("20", price);
assertEquals("20", price);
}
}

View File

@ -34,8 +34,13 @@
<artifactId>async-method-invocation</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.async.method.invocation;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.async.method.invocation;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Matchers;
@ -30,8 +30,21 @@ import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static java.time.Duration.ofMillis;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTimeout;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.internal.verification.VerificationModeFactory.times;
/**
@ -44,205 +57,217 @@ public class ThreadAsyncExecutorTest {
/**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)}
*/
@Test(timeout = 3000)
@Test
public void testSuccessfulTaskWithoutCallback() throws Exception {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
assertTimeout(ofMillis(3000), () -> {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenReturn(result);
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenReturn(result);
final AsyncResult<Object> asyncResult = executor.startProcess(task);
assertNotNull(asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
final AsyncResult<Object> asyncResult = executor.startProcess(task);
assertNotNull(asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
// Our task should only execute once ...
verify(task, times(1)).call();
// Our task should only execute once ...
verify(task, times(1)).call();
// ... and the result should be exactly the same object
assertSame(result, asyncResult.getValue());
// ... and the result should be exactly the same object
assertSame(result, asyncResult.getValue());
});
}
/**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)}
*/
@Test(timeout = 3000)
@Test
public void testSuccessfulTaskWithCallback() throws Exception {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
assertTimeout(ofMillis(3000), () -> {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenReturn(result);
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenReturn(result);
final AsyncCallback callback = mock(AsyncCallback.class);
final AsyncResult<Object> asyncResult = executor.startProcess(task, callback);
assertNotNull(asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
final AsyncCallback callback = mock(AsyncCallback.class);
final AsyncResult<Object> asyncResult = executor.startProcess(task, callback);
assertNotNull(asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
// Our task should only execute once ...
verify(task, times(1)).call();
// Our task should only execute once ...
verify(task, times(1)).call();
// ... same for the callback, we expect our object
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class);
verify(callback, times(1)).onComplete(eq(result), optionalCaptor.capture());
// ... same for the callback, we expect our object
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class);
verify(callback, times(1)).onComplete(eq(result), optionalCaptor.capture());
final Optional<Exception> optionalException = optionalCaptor.getValue();
assertNotNull(optionalException);
assertFalse(optionalException.isPresent());
final Optional<Exception> optionalException = optionalCaptor.getValue();
assertNotNull(optionalException);
assertFalse(optionalException.isPresent());
// ... and the result should be exactly the same object
assertSame(result, asyncResult.getValue());
// ... and the result should be exactly the same object
assertSame(result, asyncResult.getValue());
});
}
/**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)} when a task takes a while
* to execute
*/
@Test(timeout = 5000)
@Test
public void testLongRunningTaskWithoutCallback() throws Exception {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
assertTimeout(ofMillis(5000), () -> {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenAnswer(i -> {
Thread.sleep(1500);
return result;
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenAnswer(i -> {
Thread.sleep(1500);
return result;
});
final AsyncResult<Object> asyncResult = executor.startProcess(task);
assertNotNull(asyncResult);
assertFalse(asyncResult.isCompleted());
try {
asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) {
assertNotNull(e.getMessage());
}
// Our task should only execute once, but it can take a while ...
verify(task, timeout(3000).times(1)).call();
// Prevent timing issues, and wait until the result is available
asyncResult.await();
assertTrue(asyncResult.isCompleted());
verifyNoMoreInteractions(task);
// ... and the result should be exactly the same object
assertSame(result, asyncResult.getValue());
});
final AsyncResult<Object> asyncResult = executor.startProcess(task);
assertNotNull(asyncResult);
assertFalse(asyncResult.isCompleted());
try {
asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) {
assertNotNull(e.getMessage());
}
// Our task should only execute once, but it can take a while ...
verify(task, timeout(3000).times(1)).call();
// Prevent timing issues, and wait until the result is available
asyncResult.await();
assertTrue(asyncResult.isCompleted());
verifyNoMoreInteractions(task);
// ... and the result should be exactly the same object
assertSame(result, asyncResult.getValue());
}
/**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when a task
* takes a while to execute
*/
@Test(timeout = 5000)
@Test
public void testLongRunningTaskWithCallback() throws Exception {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
assertTimeout(ofMillis(5000), () -> {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenAnswer(i -> {
Thread.sleep(1500);
return result;
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenAnswer(i -> {
Thread.sleep(1500);
return result;
});
final AsyncCallback<Object> callback = mock(AsyncCallback.class);
final AsyncResult<Object> asyncResult = executor.startProcess(task, callback);
assertNotNull(asyncResult);
assertFalse(asyncResult.isCompleted());
verifyZeroInteractions(callback);
try {
asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) {
assertNotNull(e.getMessage());
}
// Our task should only execute once, but it can take a while ...
verify(task, timeout(3000).times(1)).call();
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class);
verify(callback, timeout(3000).times(1)).onComplete(eq(result), optionalCaptor.capture());
final Optional<Exception> optionalException = optionalCaptor.getValue();
assertNotNull(optionalException);
assertFalse(optionalException.isPresent());
// Prevent timing issues, and wait until the result is available
asyncResult.await();
assertTrue(asyncResult.isCompleted());
verifyNoMoreInteractions(task, callback);
// ... and the result should be exactly the same object
assertSame(result, asyncResult.getValue());
});
final AsyncCallback<Object> callback = mock(AsyncCallback.class);
final AsyncResult<Object> asyncResult = executor.startProcess(task, callback);
assertNotNull(asyncResult);
assertFalse(asyncResult.isCompleted());
verifyZeroInteractions(callback);
try {
asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) {
assertNotNull(e.getMessage());
}
// Our task should only execute once, but it can take a while ...
verify(task, timeout(3000).times(1)).call();
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class);
verify(callback, timeout(3000).times(1)).onComplete(eq(result), optionalCaptor.capture());
final Optional<Exception> optionalException = optionalCaptor.getValue();
assertNotNull(optionalException);
assertFalse(optionalException.isPresent());
// Prevent timing issues, and wait until the result is available
asyncResult.await();
assertTrue(asyncResult.isCompleted());
verifyNoMoreInteractions(task, callback);
// ... and the result should be exactly the same object
assertSame(result, asyncResult.getValue());
}
/**
* Test used to verify the happy path of {@link ThreadAsyncExecutor#startProcess(Callable)} when a task takes a while
* to execute, while waiting on the result using {@link ThreadAsyncExecutor#endProcess(AsyncResult)}
*/
@Test(timeout = 5000)
@Test
public void testEndProcess() throws Exception {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
assertTimeout(ofMillis(5000), () -> {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenAnswer(i -> {
Thread.sleep(1500);
return result;
final Object result = new Object();
final Callable<Object> task = mock(Callable.class);
when(task.call()).thenAnswer(i -> {
Thread.sleep(1500);
return result;
});
final AsyncResult<Object> asyncResult = executor.startProcess(task);
assertNotNull(asyncResult);
assertFalse(asyncResult.isCompleted());
try {
asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) {
assertNotNull(e.getMessage());
}
assertSame(result, executor.endProcess(asyncResult));
verify(task, times(1)).call();
assertTrue(asyncResult.isCompleted());
// Calling end process a second time while already finished should give the same result
assertSame(result, executor.endProcess(asyncResult));
verifyNoMoreInteractions(task);
});
final AsyncResult<Object> asyncResult = executor.startProcess(task);
assertNotNull(asyncResult);
assertFalse(asyncResult.isCompleted());
try {
asyncResult.getValue();
fail("Expected IllegalStateException when calling AsyncResult#getValue on a non-completed task");
} catch (IllegalStateException e) {
assertNotNull(e.getMessage());
}
assertSame(result, executor.endProcess(asyncResult));
verify(task, times(1)).call();
assertTrue(asyncResult.isCompleted());
// Calling end process a second time while already finished should give the same result
assertSame(result, executor.endProcess(asyncResult));
verifyNoMoreInteractions(task);
}
/**
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable)} when the callable is 'null'
*/
@Test(timeout = 3000)
@Test
public void testNullTask() throws Exception {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final AsyncResult<Object> asyncResult = executor.startProcess(null);
assertTimeout(ofMillis(3000), () -> {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final AsyncResult<Object> asyncResult = executor.startProcess(null);
assertNotNull("The AsyncResult should not be 'null', even though the task was 'null'.", asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
assertNotNull(asyncResult, "The AsyncResult should not be 'null', even though the task was 'null'.");
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
try {
asyncResult.getValue();
fail("Expected ExecutionException with NPE as cause");
} catch (final ExecutionException e) {
assertNotNull(e.getMessage());
assertNotNull(e.getCause());
assertEquals(NullPointerException.class, e.getCause().getClass());
}
try {
asyncResult.getValue();
fail("Expected ExecutionException with NPE as cause");
} catch (final ExecutionException e) {
assertNotNull(e.getMessage());
assertNotNull(e.getCause());
assertEquals(NullPointerException.class, e.getCause().getClass());
}
});
}
@ -250,36 +275,38 @@ public class ThreadAsyncExecutorTest {
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when the
* callable is 'null', but the asynchronous callback is provided
*/
@Test(timeout = 3000)
@Test
public void testNullTaskWithCallback() throws Exception {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final AsyncCallback<Object> callback = mock(AsyncCallback.class);
final AsyncResult<Object> asyncResult = executor.startProcess(null, callback);
assertTimeout(ofMillis(3000), () -> {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final AsyncCallback<Object> callback = mock(AsyncCallback.class);
final AsyncResult<Object> asyncResult = executor.startProcess(null, callback);
assertNotNull("The AsyncResult should not be 'null', even though the task was 'null'.", asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
assertNotNull(asyncResult, "The AsyncResult should not be 'null', even though the task was 'null'.");
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class);
verify(callback, times(1)).onComplete(Matchers.isNull(), optionalCaptor.capture());
final ArgumentCaptor<Optional<Exception>> optionalCaptor = ArgumentCaptor.forClass((Class) Optional.class);
verify(callback, times(1)).onComplete(Matchers.isNull(), optionalCaptor.capture());
final Optional<Exception> optionalException = optionalCaptor.getValue();
assertNotNull(optionalException);
assertTrue(optionalException.isPresent());
final Optional<Exception> optionalException = optionalCaptor.getValue();
assertNotNull(optionalException);
assertTrue(optionalException.isPresent());
final Exception exception = optionalException.get();
assertNotNull(exception);
assertEquals(NullPointerException.class, exception.getClass());
final Exception exception = optionalException.get();
assertNotNull(exception);
assertEquals(NullPointerException.class, exception.getClass());
try {
asyncResult.getValue();
fail("Expected ExecutionException with NPE as cause");
} catch (final ExecutionException e) {
assertNotNull(e.getMessage());
assertNotNull(e.getCause());
assertEquals(NullPointerException.class, e.getCause().getClass());
}
try {
asyncResult.getValue();
fail("Expected ExecutionException with NPE as cause");
} catch (final ExecutionException e) {
assertNotNull(e.getMessage());
assertNotNull(e.getCause());
assertEquals(NullPointerException.class, e.getCause().getClass());
}
});
}
@ -287,24 +314,29 @@ public class ThreadAsyncExecutorTest {
* Test used to verify the behaviour of {@link ThreadAsyncExecutor#startProcess(Callable, AsyncCallback)} when both
* the callable and the asynchronous callback are 'null'
*/
@Test(timeout = 3000)
@Test
public void testNullTaskWithNullCallback() throws Exception {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final AsyncResult<Object> asyncResult = executor.startProcess(null, null);
assertTimeout(ofMillis(3000), () -> {
// Instantiate a new executor and start a new 'null' task ...
final ThreadAsyncExecutor executor = new ThreadAsyncExecutor();
final AsyncResult<Object> asyncResult = executor.startProcess(null, null);
assertNotNull("The AsyncResult should not be 'null', even though the task and callback were 'null'.", asyncResult);
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
assertNotNull(
asyncResult,
"The AsyncResult should not be 'null', even though the task and callback were 'null'."
);
asyncResult.await(); // Prevent timing issues, and wait until the result is available
assertTrue(asyncResult.isCompleted());
try {
asyncResult.getValue();
fail("Expected ExecutionException with NPE as cause");
} catch (final ExecutionException e) {
assertNotNull(e.getMessage());
assertNotNull(e.getCause());
assertEquals(NullPointerException.class, e.getCause().getClass());
}
try {
asyncResult.getValue();
fail("Expected ExecutionException with NPE as cause");
} catch (final ExecutionException e) {
assertNotNull(e.getMessage());
assertNotNull(e.getCause());
assertEquals(NullPointerException.class, e.getCause().getClass());
}
});
}

View File

@ -36,8 +36,13 @@
<artifactId>balking</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -23,7 +23,7 @@
package com.iluwatar.balking;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Application test

View File

@ -22,13 +22,13 @@
*/
package com.iluwatar.balking;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests for {@link WashingMachine}

View File

@ -34,8 +34,13 @@
<artifactId>bridge</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.bridge;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -22,11 +22,10 @@
*/
package com.iluwatar.bridge;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
/**
* Tests for hammer

View File

@ -22,11 +22,10 @@
*/
package com.iluwatar.bridge;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
/**
* Tests for sword

View File

@ -22,10 +22,11 @@
*/
package com.iluwatar.bridge;
import static org.junit.Assert.assertNotNull;
import org.junit.jupiter.api.Disabled;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.internal.verification.VerificationModeFactory.times;
/**
* Base class for weapon tests

View File

@ -34,8 +34,13 @@
<artifactId>builder</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.builder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -22,10 +22,11 @@
*/
package com.iluwatar.builder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Date: 12/6/15 - 11:01 PM
@ -37,17 +38,17 @@ public class HeroTest {
/**
* Test if we get the expected exception when trying to create a hero without a profession
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void testMissingProfession() throws Exception {
new Hero.Builder(null, "Sir without a job");
assertThrows(IllegalArgumentException.class, () -> new Hero.Builder(null, "Sir without a job"));
}
/**
* Test if we get the expected exception when trying to create a hero without a name
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void testMissingName() throws Exception {
new Hero.Builder(Profession.THIEF, null);
assertThrows(IllegalArgumentException.class, () -> new Hero.Builder(Profession.THIEF, null));
}
/**

View File

@ -35,8 +35,13 @@
<artifactId>business-delegate</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.business.delegate;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;

View File

@ -22,13 +22,13 @@
*/
package com.iluwatar.business.delegate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Before;
import org.junit.Test;
/**
* The Business Delegate pattern adds an abstraction layer between the presentation and business
* tiers. By using the pattern we gain loose coupling between the tiers. The Business Delegate
@ -53,7 +53,7 @@ public class BusinessDelegateTest {
* This method sets up the instance variables of this test class. It is executed before the
* execution of every test.
*/
@Before
@BeforeEach
public void setup() {
ejbService = spy(new EjbService());
jmsService = spy(new JmsService());

View File

@ -34,8 +34,13 @@
<artifactId>caching</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.caching;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;

View File

@ -22,8 +22,8 @@
*/
package com.iluwatar.caching;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
*
@ -36,7 +36,7 @@ public class CachingTest {
/**
* Setup of application test includes: initializing DB connection and cache size/capacity.
*/
@Before
@BeforeEach
public void setUp() {
AppManager.initDb(false); // VirtualDB (instead of MongoDB) was used in running the JUnit tests
// to avoid Maven compilation errors. Set flag to true to run the

View File

@ -34,8 +34,13 @@
<artifactId>callback</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.callback;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;

View File

@ -22,9 +22,9 @@
*/
package com.iluwatar.callback;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Add a field as a counter. Every time the callback method is called increment this field. Unit
@ -47,15 +47,15 @@ public class CallbackTest {
Task task = new SimpleTask();
assertEquals("Initial calling count of 0", new Integer(0), callingCount);
assertEquals(new Integer(0), callingCount, "Initial calling count of 0");
task.executeWith(callback);
assertEquals("Callback called once", new Integer(1), callingCount);
assertEquals(new Integer(1), callingCount, "Callback called once");
task.executeWith(callback);
assertEquals("Callback called twice", new Integer(2), callingCount);
assertEquals(new Integer(2), callingCount, "Callback called twice");
}
@ -65,15 +65,15 @@ public class CallbackTest {
Task task = new SimpleTask();
assertEquals("Initial calling count of 0", new Integer(0), callingCount);
assertEquals(new Integer(0), callingCount, "Initial calling count of 0");
task.executeWith(callback);
assertEquals("Callback called once", new Integer(1), callingCount);
assertEquals(new Integer(1), callingCount, "Callback called once");
task.executeWith(callback);
assertEquals("Callback called twice", new Integer(2), callingCount);
assertEquals(new Integer(2), callingCount, "Callback called twice");
}
}

View File

@ -34,8 +34,13 @@
<artifactId>chain</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.chain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -22,9 +22,9 @@
*/
package com.iluwatar.chain;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Date: 12/6/15 - 9:29 PM
@ -49,8 +49,8 @@ public class OrcKingTest {
for (final Request request : REQUESTS) {
king.makeRequest(request);
assertTrue(
"Expected all requests from King to be handled, but [" + request + "] was not!",
request.isHandled()
request.isHandled(),
"Expected all requests from King to be handled, but [" + request + "] was not!"
);
}

View File

@ -179,7 +179,7 @@
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test, Before, After, Parameters, Given, When, BeforeClass, AfterClass, Parameterized"/>
<property name="allowedAnnotations" value="Override, Test, Before, After, Parameters, Given, When, BeforeClass, AfterClass, Parameterized, ParameterizedTest, BeforeAll, BeforeEach"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
<module name="JavadocType">

View File

@ -34,13 +34,13 @@
<artifactId>command</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.command;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;

View File

@ -22,9 +22,9 @@
*/
package com.iluwatar.command;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The Command pattern is a behavioral design pattern in which an object is used to encapsulate all
@ -85,9 +85,9 @@ public class CommandTest {
*/
private void verifyGoblin(Goblin goblin, String expectedName, Size expectedSize,
Visibility expectedVisibility) {
assertEquals("Goblin's name must be same as expectedName", expectedName, goblin.toString());
assertEquals("Goblin's size must be same as expectedSize", expectedSize, goblin.getSize());
assertEquals("Goblin's visibility must be same as expectedVisibility", expectedVisibility,
goblin.getVisibility());
assertEquals(expectedName, goblin.toString(), "Goblin's name must be same as expectedName");
assertEquals(expectedSize, goblin.getSize(), "Goblin's size must be same as expectedSize");
assertEquals(expectedVisibility, goblin.getVisibility(),
"Goblin's visibility must be same as expectedVisibility");
}
}

View File

@ -34,8 +34,13 @@
<artifactId>composite</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.composite;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -22,15 +22,15 @@
*/
package com.iluwatar.composite;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Date: 12/11/15 - 8:12 PM
@ -52,7 +52,7 @@ public class MessengerTest {
/**
* Inject the mocked std-out {@link PrintStream} into the {@link System} class before each test
*/
@Before
@BeforeEach
public void setUp() {
this.stdOutBuffer = new ByteArrayOutputStream();
System.setOut(new PrintStream(stdOutBuffer));
@ -61,7 +61,7 @@ public class MessengerTest {
/**
* Removed the mocked std-out {@link PrintStream} again from the {@link System} class
*/
@After
@AfterEach
public void tearDown() {
System.setOut(realStdOut);
}

View File

@ -34,8 +34,13 @@
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.converter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* App running test

View File

@ -23,13 +23,13 @@
package com.iluwatar.converter;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static junit.framework.TestCase.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests for {@link Converter}
@ -41,7 +41,8 @@ public class ConverterTest {
/**
* Tests whether a converter created of opposite functions holds equality as a bijection.
*/
@Test public void testConversionsStartingFromDomain() {
@Test
public void testConversionsStartingFromDomain() {
User u1 = new User("Tom", "Hanks", true, "tom@hanks.com");
User u2 = userConverter.convertFromDto(userConverter.convertFromEntity(u1));
assertEquals(u1, u2);
@ -50,7 +51,8 @@ public class ConverterTest {
/**
* Tests whether a converter created of opposite functions holds equality as a bijection.
*/
@Test public void testConversionsStartingFromDto() {
@Test
public void testConversionsStartingFromDto() {
UserDto u1 = new UserDto("Tom", "Hanks", true, "tom@hanks.com");
UserDto u2 = userConverter.convertFromEntity(userConverter.convertFromDto(u1));
assertEquals(u1, u2);
@ -60,7 +62,8 @@ public class ConverterTest {
* Tests the custom users converter. Thanks to Java8 lambdas, converter can be easily and
* cleanly instantiated allowing various different conversion strategies to be implemented.
*/
@Test public void testCustomConverter() {
@Test
public void testCustomConverter() {
Converter<UserDto, User> converter = new Converter<>(
userDto -> new User(userDto.getFirstName(), userDto.getLastName(), userDto.isActive(),
String.valueOf(new Random().nextInt())),
@ -75,7 +78,8 @@ public class ConverterTest {
* Test whether converting a collection of Users to DTO Users and then converting them back to domain
* users returns an equal collection.
*/
@Test public void testCollectionConversion() {
@Test
public void testCollectionConversion() {
ArrayList<User> users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"),
new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243"));
List<User> fromDtos = userConverter.createFromDtos(userConverter.createFromEntities(users));

View File

@ -26,8 +26,13 @@
<artifactId>cqrs</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,21 +22,20 @@
*/
package com.iluwatar.cqrs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.math.BigInteger;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import com.iluwatar.cqrs.commandes.CommandServiceImpl;
import com.iluwatar.cqrs.commandes.ICommandService;
import com.iluwatar.cqrs.dto.Author;
import com.iluwatar.cqrs.dto.Book;
import com.iluwatar.cqrs.queries.IQueryService;
import com.iluwatar.cqrs.queries.QueryServiceImpl;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Integration test of IQueryService and ICommandService with h2 data
@ -47,14 +46,11 @@ public class IntegrationTest {
private static IQueryService queryService;
private static ICommandService commandService;
@BeforeClass
public static void initialize() {
@BeforeAll
public static void initializeAndPopulateDatabase() {
commandService = new CommandServiceImpl();
queryService = new QueryServiceImpl();
}
@BeforeClass
public static void populateDatabase() {
// create first author1
commandService.authorCreated("username1", "name1", "email1");
@ -94,7 +90,7 @@ public class IntegrationTest {
public void testGetBook() {
Book book = queryService.getBook("title1");
assertEquals("title1", book.getTitle());
assertEquals(10, book.getPrice(), 0);
assertEquals(10, book.getPrice(), 0.01);
}
@Test

View File

@ -36,8 +36,13 @@
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@ -48,10 +53,6 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>de.bechte.junit</groupId>
<artifactId>junit-hierarchicalcontextrunner</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>

View File

@ -23,7 +23,7 @@
package com.iluwatar.dao;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests that DAO example runs without errors.

View File

@ -23,11 +23,11 @@
package com.iluwatar.dao;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Tests {@link Customer}.
@ -39,7 +39,7 @@ public class CustomerTest {
private static final String FIRSTNAME = "Winston";
private static final String LASTNAME = "Churchill";
@Before
@BeforeEach
public void setUp() {
customer = new Customer(ID, FIRSTNAME, LASTNAME);
}

View File

@ -22,38 +22,32 @@
*/
package com.iluwatar.dao;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.stream.Stream;
import javax.sql.DataSource;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import de.bechte.junit.runners.context.HierarchicalContextRunner;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
/**
* Tests {@link DbCustomerDao}.
*/
@RunWith(HierarchicalContextRunner.class)
public class DbCustomerDaoTest {
private static final String DB_URL = "jdbc:h2:~/dao";
@ -64,7 +58,7 @@ public class DbCustomerDaoTest {
* Creates customers schema.
* @throws SQLException if there is any error while creating schema.
*/
@Before
@BeforeEach
public void createSchema() throws SQLException {
try (Connection connection = DriverManager.getConnection(DB_URL);
Statement statement = connection.createStatement()) {
@ -75,13 +69,14 @@ public class DbCustomerDaoTest {
/**
* Represents the scenario where DB connectivity is present.
*/
@Nested
public class ConnectionSuccess {
/**
* Setup for connection success scenario.
* @throws Exception if any error occurs.
*/
@Before
@BeforeEach
public void setUp() throws Exception {
JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL(DB_URL);
@ -93,6 +88,7 @@ public class DbCustomerDaoTest {
/**
* Represents the scenario when DAO operations are being performed on a non existing customer.
*/
@Nested
public class NonExistingCustomer {
@Test
@ -141,6 +137,7 @@ public class DbCustomerDaoTest {
* customer.
*
*/
@Nested
public class ExistingCustomer {
@Test
@ -184,20 +181,21 @@ public class DbCustomerDaoTest {
* DB service unavailable.
*
*/
@Nested
public class ConnectivityIssue {
private static final String EXCEPTION_CAUSE = "Connection not available";
@Rule public ExpectedException exception = ExpectedException.none();
//@Rule public ExpectedException exception = ExpectedException.none();
/**
* setup a connection failure scenario.
* @throws SQLException if any error occurs.
*/
@Before
@BeforeEach
public void setUp() throws SQLException {
dao = new DbCustomerDao(mockedDatasource());
exception.expect(Exception.class);
exception.expectMessage(EXCEPTION_CAUSE);
//exception.expect(Exception.class);
//exception.expectMessage(EXCEPTION_CAUSE);
}
private DataSource mockedDatasource() throws SQLException {
@ -210,31 +208,40 @@ public class DbCustomerDaoTest {
}
@Test
public void addingACustomerFailsWithExceptionAsFeedbackToClient() throws Exception {
dao.add(new Customer(2, "Bernard", "Montgomery"));
public void addingACustomerFailsWithExceptionAsFeedbackToClient() {
assertThrows(Exception.class, () -> {
dao.add(new Customer(2, "Bernard", "Montgomery"));
});
}
@Test
public void deletingACustomerFailsWithExceptionAsFeedbackToTheClient() throws Exception {
dao.delete(existingCustomer);
public void deletingACustomerFailsWithExceptionAsFeedbackToTheClient() {
assertThrows(Exception.class, () -> {
dao.delete(existingCustomer);
});
}
@Test
public void updatingACustomerFailsWithFeedbackToTheClient() throws Exception {
public void updatingACustomerFailsWithFeedbackToTheClient() {
final String newFirstname = "Bernard";
final String newLastname = "Montgomery";
dao.update(new Customer(existingCustomer.getId(), newFirstname, newLastname));
assertThrows(Exception.class, () -> {
dao.update(new Customer(existingCustomer.getId(), newFirstname, newLastname));
});
}
@Test
public void retrievingACustomerByIdFailsWithExceptionAsFeedbackToClient() throws Exception {
dao.getById(existingCustomer.getId());
public void retrievingACustomerByIdFailsWithExceptionAsFeedbackToClient() {
assertThrows(Exception.class, () -> {
dao.getById(existingCustomer.getId());
});
}
@Test
public void retrievingAllCustomersFailsWithExceptionAsFeedbackToClient() throws Exception {
dao.getAll();
public void retrievingAllCustomersFailsWithExceptionAsFeedbackToClient() {
assertThrows(Exception.class, () -> {
dao.getAll();
});
}
}
@ -243,7 +250,7 @@ public class DbCustomerDaoTest {
* Delete customer schema for fresh setup per test.
* @throws SQLException if any error occurs.
*/
@After
@AfterEach
public void deleteSchema() throws SQLException {
try (Connection connection = DriverManager.getConnection(DB_URL);
Statement statement = connection.createStatement()) {

View File

@ -23,31 +23,27 @@
package com.iluwatar.dao;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.util.Optional;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import de.bechte.junit.runners.context.HierarchicalContextRunner;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* Tests {@link InMemoryCustomerDao}.
*/
@RunWith(HierarchicalContextRunner.class)
public class InMemoryCustomerDaoTest {
private InMemoryCustomerDao dao;
private static final Customer CUSTOMER = new Customer(1, "Freddy", "Krueger");
@Before
@BeforeEach
public void setUp() {
dao = new InMemoryCustomerDao();
assertTrue(dao.add(CUSTOMER));
@ -57,6 +53,7 @@ public class InMemoryCustomerDaoTest {
* Represents the scenario when the DAO operations are being performed on a non existent
* customer.
*/
@Nested
public class NonExistingCustomer {
@Test
@ -104,6 +101,7 @@ public class InMemoryCustomerDaoTest {
* Represents the scenario when the DAO operations are being performed on an already existing
* customer.
*/
@Nested
public class ExistingCustomer {
@Test

View File

@ -38,8 +38,13 @@
<artifactId>data-bus</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,8 +22,8 @@
*/
package com.iluwatar.databus;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@ -43,7 +43,7 @@ public class DataBusTest {
@Mock
private DataType event;
@Before
@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);
}

View File

@ -24,11 +24,13 @@ package com.iluwatar.databus.members;
import com.iluwatar.databus.data.MessageData;
import com.iluwatar.databus.data.StartingData;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for {@link MessageCollectorMember}.
*
@ -45,7 +47,7 @@ public class MessageCollectorMemberTest {
//when
collector.accept(messageData);
//then
Assert.assertTrue(collector.getMessages().contains(message));
assertTrue(collector.getMessages().contains(message));
}
@Test
@ -56,7 +58,7 @@ public class MessageCollectorMemberTest {
//when
collector.accept(startingData);
//then
Assert.assertEquals(0, collector.getMessages().size());
assertEquals(0, collector.getMessages().size());
}
}

View File

@ -26,12 +26,14 @@ import com.iluwatar.databus.DataBus;
import com.iluwatar.databus.data.MessageData;
import com.iluwatar.databus.data.StartingData;
import com.iluwatar.databus.data.StoppingData;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import java.time.Month;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Tests for {@link StatusMember}.
*
@ -48,7 +50,7 @@ public class StatusMemberTest {
//when
statusMember.accept(startingData);
//then
Assert.assertEquals(startTime, statusMember.getStarted());
assertEquals(startTime, statusMember.getStarted());
}
@Test
@ -61,7 +63,7 @@ public class StatusMemberTest {
//when
statusMember.accept(stoppingData);
//then
Assert.assertEquals(stop, statusMember.getStopped());
assertEquals(stop, statusMember.getStopped());
}
@Test
@ -72,8 +74,8 @@ public class StatusMemberTest {
//when
statusMember.accept(messageData);
//then
Assert.assertNull(statusMember.getStarted());
Assert.assertNull(statusMember.getStopped());
assertNull(statusMember.getStarted());
assertNull(statusMember.getStopped());
}
}

View File

@ -33,8 +33,13 @@
<artifactId>data-mapper</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -18,8 +18,7 @@
*/
package com.iluwatar.datamapper;
import com.iluwatar.datamapper.App;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests that Data-Mapper example runs without errors.

View File

@ -18,13 +18,9 @@
*/
package com.iluwatar.datamapper;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import com.iluwatar.datamapper.Student;
import com.iluwatar.datamapper.StudentDataMapper;
import com.iluwatar.datamapper.StudentDataMapperImpl;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The Data Mapper (DM) is a layer of software that separates the in-memory objects from the

View File

@ -18,10 +18,10 @@
*/
package com.iluwatar.datamapper;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests {@link Student}.

View File

@ -33,8 +33,13 @@
<artifactId>data-transfer-object</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -24,12 +24,12 @@
package com.iluwatar.datatransfer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* tests {@link CustomerResource}.

View File

@ -34,8 +34,13 @@
<artifactId>decorator</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.decorator;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -22,10 +22,12 @@
*/
package com.iluwatar.decorator;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.internal.verification.VerificationModeFactory.times;
/**

View File

@ -25,15 +25,15 @@ package com.iluwatar.decorator;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests for {@link SimpleTroll}
@ -42,12 +42,12 @@ public class SimpleTrollTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender(SimpleTroll.class);
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}

View File

@ -38,13 +38,13 @@
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -22,7 +22,8 @@
*/
package com.iluwatar.delegation.simple;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Application Test Entry
*/

View File

@ -22,20 +22,21 @@
*/
package com.iluwatar.delegation.simple;
import static org.junit.Assert.assertEquals;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import com.iluwatar.delegation.simple.printers.CanonPrinter;
import com.iluwatar.delegation.simple.printers.EpsonPrinter;
import com.iluwatar.delegation.simple.printers.HpPrinter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
import java.util.LinkedList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Delegation Pattern
@ -44,12 +45,12 @@ public class DelegateTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender();
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}

View File

@ -34,13 +34,13 @@
<artifactId>dependency-injection</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -23,11 +23,12 @@
package com.iluwatar.dependency.injection;
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals;
/**
* Date: 28/04/17 - 7:40 AM
@ -39,12 +40,12 @@ public class AdvancedSorceressTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender(Tobacco.class);
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}

View File

@ -23,11 +23,12 @@
package com.iluwatar.dependency.injection;
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals;
/**
* Date: 12/10/15 - 8:40 PM
@ -38,12 +39,12 @@ public class AdvancedWizardTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender(Tobacco.class);
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.dependency.injection;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -26,11 +26,11 @@ import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/10/15 - 8:57 PM
@ -41,12 +41,12 @@ public class GuiceWizardTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender(Tobacco.class);
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}

View File

@ -23,11 +23,11 @@
package com.iluwatar.dependency.injection;
import com.iluwatar.dependency.injection.utils.InMemoryAppender;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/10/15 - 8:26 PM
@ -38,12 +38,12 @@ public class SimpleWizardTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender(Tobacco.class);
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}

View File

@ -32,8 +32,13 @@
<artifactId>double-checked-locking</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.doublechecked.locking;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -25,9 +25,9 @@ package com.iluwatar.doublechecked.locking;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
import java.util.LinkedList;
@ -36,9 +36,11 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static java.time.Duration.ofMillis;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTimeout;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Date: 12/10/15 - 9:34 PM
@ -49,12 +51,12 @@ public class InventoryTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender(Inventory.class);
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}
@ -76,32 +78,34 @@ public class InventoryTest {
* of order, it means that the locking is not ok, increasing the risk of going over the inventory
* item limit.
*/
@Test(timeout = 10000)
@Test
public void testAddItem() throws Exception {
// Create a new inventory with a limit of 1000 items and put some load on the add method
final Inventory inventory = new Inventory(INVENTORY_SIZE);
final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
for (int i = 0; i < THREAD_COUNT; i++) {
executorService.execute(() -> {
while (inventory.addItem(new Item())) {};
});
}
assertTimeout(ofMillis(10000), () -> {
// Create a new inventory with a limit of 1000 items and put some load on the add method
final Inventory inventory = new Inventory(INVENTORY_SIZE);
final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
for (int i = 0; i < THREAD_COUNT; i++) {
executorService.execute(() -> {
while (inventory.addItem(new Item())) {};
});
}
// Wait until all threads have finished
executorService.shutdown();
executorService.awaitTermination(5, TimeUnit.SECONDS);
// Wait until all threads have finished
executorService.shutdown();
executorService.awaitTermination(5, TimeUnit.SECONDS);
// Check the number of items in the inventory. It should not have exceeded the allowed maximum
final List<Item> items = inventory.getItems();
assertNotNull(items);
assertEquals(INVENTORY_SIZE, items.size());
// Check the number of items in the inventory. It should not have exceeded the allowed maximum
final List<Item> items = inventory.getItems();
assertNotNull(items);
assertEquals(INVENTORY_SIZE, items.size());
assertEquals(INVENTORY_SIZE, appender.getLogSize());
assertEquals(INVENTORY_SIZE, appender.getLogSize());
// ... and check if the inventory size is increasing continuously
for (int i = 0; i < items.size(); i++) {
assertTrue(appender.log.get(i).getFormattedMessage().contains("items.size()=" + (i + 1)));
}
// ... and check if the inventory size is increasing continuously
for (int i = 0; i < items.size(); i++) {
assertTrue(appender.log.get(i).getFormattedMessage().contains("items.size()=" + (i + 1)));
}
});
}

View File

@ -34,8 +34,13 @@
<artifactId>double-dispatch</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.doubledispatch;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
*

View File

@ -22,10 +22,10 @@
*/
package com.iluwatar.doubledispatch;
import static org.junit.Assert.assertEquals;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/10/15 - 8:37 PM
* Test for Collision
@ -86,7 +86,7 @@ public abstract class CollisionTest<O extends GameObject> {
? "Expected [" + targetName + "] to be on fire after colliding with [" + otherName + "] but it was not!"
: "Expected [" + targetName + "] not to be on fire after colliding with [" + otherName + "] but it was!";
assertEquals(errorMessage, expectTargetOnFire, target.isOnFire());
assertEquals(expectTargetOnFire, target.isOnFire(), errorMessage);
}
/**
@ -105,7 +105,7 @@ public abstract class CollisionTest<O extends GameObject> {
? "Expected [" + targetName + "] to be damaged after colliding with [" + otherName + "] but it was not!"
: "Expected [" + targetName + "] not to be damaged after colliding with [" + otherName + "] but it was!";
assertEquals(errorMessage, expectedDamage, target.isDamaged());
assertEquals(expectedDamage, target.isDamaged(), errorMessage);
}
}

View File

@ -22,11 +22,11 @@
*/
package com.iluwatar.doubledispatch;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Date: 12/10/15 - 11:31 PM

View File

@ -22,10 +22,10 @@
*/
package com.iluwatar.doubledispatch;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* Date: 12/10/15 - 11:31 PM

View File

@ -22,11 +22,11 @@
*/
package com.iluwatar.doubledispatch;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Unit test for Rectangle

View File

@ -22,10 +22,10 @@
*/
package com.iluwatar.doubledispatch;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* Date: 12/10/15 - 11:31 PM

View File

@ -22,10 +22,10 @@
*/
package com.iluwatar.doubledispatch;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* Date: 12/10/15 - 11:31 PM

View File

@ -48,6 +48,21 @@
</dependency>
<!-- Testing -->
<dependency>
<groupId>com.github.sbrannen</groupId>
<artifactId>spring-test-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

Some files were not shown because too many files have changed in this diff Show More