🔨 update tests, add static import

This commit is contained in:
Velizar Todorov 2021-11-30 18:54:20 +01:00
parent 5f64e3fb2e
commit 4c7e41537d
2 changed files with 9 additions and 9 deletions

View File

@ -8,8 +8,9 @@ import com.gildedrose.items.NormalItem;
import com.gildedrose.main.Item; import com.gildedrose.main.Item;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream; import static java.util.stream.Collectors.toMap;
import static java.util.stream.Stream.of;
public class ItemFactory { public class ItemFactory {
@ -26,9 +27,9 @@ public class ItemFactory {
} }
private static Map<String, ItemType> getItems(Item item) { private static Map<String, ItemType> getItems(Item item) {
return Stream.of(new NormalItem(item), new AgedBrieItem(item), new LegendaryItem(item), return of(new NormalItem(item), new AgedBrieItem(item), new LegendaryItem(item),
new BackstagePassItem(item), new ConjuredItem(item)) new BackstagePassItem(item), new ConjuredItem(item))
.collect(Collectors.toMap(ItemType::getName, itemType -> itemType)); .collect(toMap(ItemType::getName, itemType -> itemType));
} }
} }

View File

@ -5,21 +5,20 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import static com.gildedrose.items.AgedBrieItem.AGED_BRIE;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@TestMethodOrder(OrderAnnotation.class) @TestMethodOrder(OrderAnnotation.class)
class ItemClassTest { class ItemClassTest {
private final Item item = new Item(AGED_BRIE, 5, 20); private final Item item = new Item("foo", 5, 20);
@Test @Test
@Order(1) @Order(1)
void testItemSuccess() { void testItemSuccess() {
assertEquals(AGED_BRIE, item.name); assertEquals("foo", item.name);
assertEquals(5, item.sellIn); assertEquals(5, item.sellIn);
assertEquals(20, item.quality); assertEquals(20, item.quality);
assertEquals("Aged Brie, 5, 20", item.toString()); assertEquals("foo, 5, 20", item.toString());
} }
} }