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

@ -35,8 +35,18 @@
<artifactId>front-controller</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>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

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

View File

@ -22,9 +22,9 @@
*/
package com.iluwatar.front.controller;
import static org.junit.Assert.assertSame;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertSame;
/**
* Date: 12/13/15 - 1:35 PM

View File

@ -23,40 +23,36 @@
package com.iluwatar.front.controller;
import com.iluwatar.front.controller.utils.InMemoryAppender;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/13/15 - 1:39 PM
*
* @author Jeroen Meulemeester
*/
@RunWith(Parameterized.class)
public class CommandTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender();
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}
@Parameters
public static List<Object[]> data() {
static List<Object[]> dataProvider() {
final List<Object[]> parameters = new ArrayList<>();
parameters.add(new Object[]{"Archer", "Displaying archers"});
parameters.add(new Object[]{"Catapult", "Displaying catapults"});
@ -65,28 +61,12 @@ public class CommandTest {
}
/**
* The view that's been tested
*/
private final String request;
/**
* The expected display message
*/
private final String displayMessage;
/**
* Create a new instance of the {@link CommandTest} with the given view and expected message
*
* @param request The request that's been tested
* @param displayMessage The expected display message
*/
public CommandTest(final String request, final String displayMessage) {
this.displayMessage = displayMessage;
this.request = request;
}
@Test
public void testDisplay() {
@ParameterizedTest
@MethodSource("dataProvider")
public void testDisplay(String request, String displayMessage) {
final FrontController frontController = new FrontController();
assertEquals(0, appender.getLogSize());
frontController.handleRequest(request);

View File

@ -23,40 +23,36 @@
package com.iluwatar.front.controller;
import com.iluwatar.front.controller.utils.InMemoryAppender;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/13/15 - 1:39 PM
*
* @author Jeroen Meulemeester
*/
@RunWith(Parameterized.class)
public class FrontControllerTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender();
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}
@Parameters
public static List<Object[]> data() {
static List<Object[]> dataProvider() {
final List<Object[]> parameters = new ArrayList<>();
parameters.add(new Object[]{new ArcherCommand(), "Displaying archers"});
parameters.add(new Object[]{new CatapultCommand(), "Displaying catapults"});
@ -65,30 +61,14 @@ public class FrontControllerTest {
}
/**
* The view that's been tested
*/
private final Command command;
/**
* The expected display message
*/
private final String displayMessage;
/**
* Create a new instance of the {@link FrontControllerTest} with the given view and expected message
*
* @param command The command that's been tested
* @param displayMessage The expected display message
*/
public FrontControllerTest(final Command command, final String displayMessage) {
this.displayMessage = displayMessage;
this.command = command;
}
@Test
public void testDisplay() {
@ParameterizedTest
@MethodSource("dataProvider")
public void testDisplay(Command command, String displayMessage) {
assertEquals(0, appender.getLogSize());
this.command.process();
command.process();
assertEquals(displayMessage, appender.getLastMessage());
assertEquals(1, appender.getLogSize());
}

View File

@ -23,40 +23,36 @@
package com.iluwatar.front.controller;
import com.iluwatar.front.controller.utils.InMemoryAppender;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Date: 12/13/15 - 1:39 PM
*
* @author Jeroen Meulemeester
*/
@RunWith(Parameterized.class)
public class ViewTest {
private InMemoryAppender appender;
@Before
@BeforeEach
public void setUp() {
appender = new InMemoryAppender();
}
@After
@AfterEach
public void tearDown() {
appender.stop();
}
@Parameters
public static List<Object[]> data() {
static List<Object[]> dataProvider() {
final List<Object[]> parameters = new ArrayList<>();
parameters.add(new Object[]{new ArcherView(), "Displaying archers"});
parameters.add(new Object[]{new CatapultView(), "Displaying catapults"});
@ -65,30 +61,14 @@ public class ViewTest {
}
/**
* The view that's been tested
*/
private final View view;
/**
* The expected display message
*/
private final String displayMessage;
/**
* Create a new instance of the {@link ViewTest} with the given view and expected message
*
* @param view The view that's been tested
* @param displayMessage The expected display message
*/
public ViewTest(final View view, final String displayMessage) {
this.displayMessage = displayMessage;
this.view = view;
}
@Test
public void testDisplay() {
@ParameterizedTest
@MethodSource("dataProvider")
public void testDisplay(View view, String displayMessage) {
assertEquals(0, appender.getLogSize());
this.view.display();
view.display();
assertEquals(displayMessage, appender.getLastMessage());
assertEquals(1, appender.getLogSize());
}