Java 11 migration: patterns (t-v) (#1085)
* Moves visitor pattern to java 11 * Moves value-object pattern to java 11 * Moves unit-of-work pattern to java 11 * Moves typeobjectpattern pattern to java 11 * Moves twin pattern to java 11 * Moves trampoline pattern to java 11 * Moves tolerant-reader pattern to java 11 * Moves tls pattern to java 11 * Moves throttling pattern to java 11 * Moves thread-pool pattern to java 11 * Moves template-method pattern to java 11
This commit is contained in:
committed by
Ilkka Seppälä
parent
160b737dcc
commit
50467c9e76
@ -26,15 +26,12 @@ package com.iluwatar.twin;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
App.main(new String[]{});
|
||||
}
|
||||
}
|
||||
|
@ -34,11 +34,10 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
@ -62,27 +61,26 @@ public class BallItemTest {
|
||||
|
||||
@Test
|
||||
public void testClick() {
|
||||
final BallThread ballThread = mock(BallThread.class);
|
||||
final BallItem ballItem = new BallItem();
|
||||
final var ballThread = mock(BallThread.class);
|
||||
final var ballItem = new BallItem();
|
||||
ballItem.setTwin(ballThread);
|
||||
|
||||
final InOrder inOrder = inOrder(ballThread);
|
||||
final var inOrder = inOrder(ballThread);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
IntStream.range(0, 10).forEach(i -> {
|
||||
ballItem.click();
|
||||
inOrder.verify(ballThread).suspendMe();
|
||||
|
||||
ballItem.click();
|
||||
inOrder.verify(ballThread).resumeMe();
|
||||
}
|
||||
});
|
||||
|
||||
inOrder.verifyNoMoreInteractions();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoDraw() {
|
||||
final BallItem ballItem = new BallItem();
|
||||
final BallThread ballThread = mock(BallThread.class);
|
||||
final var ballItem = new BallItem();
|
||||
final var ballThread = mock(BallThread.class);
|
||||
ballItem.setTwin(ballThread);
|
||||
|
||||
ballItem.draw();
|
||||
@ -95,8 +93,8 @@ public class BallItemTest {
|
||||
|
||||
@Test
|
||||
public void testMove() {
|
||||
final BallItem ballItem = new BallItem();
|
||||
final BallThread ballThread = mock(BallThread.class);
|
||||
final var ballItem = new BallItem();
|
||||
final var ballThread = mock(BallThread.class);
|
||||
ballItem.setTwin(ballThread);
|
||||
|
||||
ballItem.move();
|
||||
|
@ -23,15 +23,19 @@
|
||||
|
||||
package com.iluwatar.twin;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.lang.Thread.UncaughtExceptionHandler;
|
||||
import static java.lang.Thread.sleep;
|
||||
import static java.time.Duration.ofMillis;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeout;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Date: 12/30/15 - 18:55 PM
|
||||
@ -44,11 +48,11 @@ public class BallThreadTest {
|
||||
* Verify if the {@link BallThread} can be resumed
|
||||
*/
|
||||
@Test
|
||||
public void testSuspend() throws Exception {
|
||||
public void testSuspend() {
|
||||
assertTimeout(ofMillis(5000), () -> {
|
||||
final BallThread ballThread = new BallThread();
|
||||
final var ballThread = new BallThread();
|
||||
|
||||
final BallItem ballItem = mock(BallItem.class);
|
||||
final var ballItem = mock(BallItem.class);
|
||||
ballThread.setTwin(ballItem);
|
||||
|
||||
ballThread.start();
|
||||
@ -72,9 +76,9 @@ public class BallThreadTest {
|
||||
@Test
|
||||
public void testResume() {
|
||||
assertTimeout(ofMillis(5000), () -> {
|
||||
final BallThread ballThread = new BallThread();
|
||||
final var ballThread = new BallThread();
|
||||
|
||||
final BallItem ballItem = mock(BallItem.class);
|
||||
final var ballItem = mock(BallItem.class);
|
||||
ballThread.setTwin(ballItem);
|
||||
|
||||
ballThread.suspendMe();
|
||||
@ -102,8 +106,8 @@ public class BallThreadTest {
|
||||
@Test
|
||||
public void testInterrupt() {
|
||||
assertTimeout(ofMillis(5000), () -> {
|
||||
final BallThread ballThread = new BallThread();
|
||||
final UncaughtExceptionHandler exceptionHandler = mock(UncaughtExceptionHandler.class);
|
||||
final var ballThread = new BallThread();
|
||||
final var exceptionHandler = mock(UncaughtExceptionHandler.class);
|
||||
ballThread.setUncaughtExceptionHandler(exceptionHandler);
|
||||
ballThread.setTwin(mock(BallItem.class));
|
||||
ballThread.start();
|
||||
|
Reference in New Issue
Block a user