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

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

View File

@ -22,23 +22,21 @@
*/
package com.iluwatar.iterator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
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.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Date: 12/14/15 - 2:58 PM
*
* @author Jeroen Meulemeester
*/
@RunWith(Parameterized.class)
public class TreasureChestTest {
/**
@ -46,8 +44,7 @@ public class TreasureChestTest {
*
* @return The set of all expected items in the chest
*/
@Parameterized.Parameters
public static List<Object[]> data() {
public static List<Object[]> dataProvider() {
final List<Object[]> parameters = new ArrayList<>();
parameters.add(new Object[]{new Item(ItemType.POTION, "Potion of courage")});
parameters.add(new Object[]{new Item(ItemType.RING, "Ring of shadows")});
@ -62,25 +59,12 @@ public class TreasureChestTest {
return parameters;
}
/**
* One of the expected items in the chest
*/
private final Item expectedItem;
/**
* Create a new test instance, test if the given expected item can be retrieved from the chest
*
* @param expectedItem One of the items that should be in the chest
*/
public TreasureChestTest(final Item expectedItem) {
this.expectedItem = expectedItem;
}
/**
* Test if the expected item can be retrieved from the chest using the {@link ItemIterator}
*/
@Test
public void testIterator() {
@ParameterizedTest
@MethodSource("dataProvider")
public void testIterator(Item expectedItem) {
final TreasureChest chest = new TreasureChest();
final ItemIterator iterator = chest.iterator(expectedItem.getType());
assertNotNull(iterator);
@ -88,16 +72,16 @@ public class TreasureChestTest {
while (iterator.hasNext()) {
final Item item = iterator.next();
assertNotNull(item);
assertEquals(this.expectedItem.getType(), item.getType());
assertEquals(expectedItem.getType(), item.getType());
final String name = item.toString();
assertNotNull(name);
if (this.expectedItem.toString().equals(name)) {
if (expectedItem.toString().equals(name)) {
return;
}
}
fail("Expected to find item [" + this.expectedItem + "] using iterator, but we didn't.");
fail("Expected to find item [" + expectedItem + "] using iterator, but we didn't.");
}
@ -105,8 +89,9 @@ public class TreasureChestTest {
* Test if the expected item can be retrieved from the chest using the {@link
* TreasureChest#getItems()} method
*/
@Test
public void testGetItems() throws Exception {
@ParameterizedTest
@MethodSource("dataProvider")
public void testGetItems(Item expectedItem) throws Exception {
final TreasureChest chest = new TreasureChest();
final List<Item> items = chest.getItems();
assertNotNull(items);
@ -116,14 +101,14 @@ public class TreasureChestTest {
assertNotNull(item.getType());
assertNotNull(item.toString());
final boolean sameType = this.expectedItem.getType() == item.getType();
final boolean sameName = this.expectedItem.toString().equals(item.toString());
final boolean sameType = expectedItem.getType() == item.getType();
final boolean sameName = expectedItem.toString().equals(item.toString());
if (sameType && sameName) {
return;
}
}
fail("Expected to find item [" + this.expectedItem + "] in the item list, but we didn't.");
fail("Expected to find item [" + expectedItem + "] in the item list, but we didn't.");
}