0

Мне нужно достать из листа строку в виде двух геттеров через " - "

public class GildedRoseTest extends TestCase {
    private final GildedRose test = new GildedRose();
    private final List<Item> items = new ArrayList<>();

    @Before
    public void setUp() {
        items.add(new Item("+5 Dexterity Vest", 10, 20));
        items.add(new Item("Aged Brie", 2, 0));
        items.add(new Item("Elixir of the Mongoose", 5, 7));
        items.add(new Item("Sulfuras, Hand of Ragnaros", 0, 80));
        items.add(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
        items.add(new Item("Conjured Mana Cake", 3, 6));
    }

    public void testUpdateQualityFor5DexterityVest() {
        test.updateQuality(items);
        String actual = items.stream()
                .filter(s -> s.getName().equals("+5 Dexterity Vest"))
                .reduce((s) -> s.getSellIn() + " - " + s.getQuality());
        // так не получается
        assertEquals("9 - 19", actual);         
    }

}

1 ответ 1

1

Вроде так. Писал тут, не проверял.

public class GildedRoseTest extends TestCase {

    private final GildedRose test = new GildedRose();
    private final List<Item> items = new ArrayList<>();

    @Before
    public void setUp() {
        items.add(new Item("+5 Dexterity Vest", 10, 20));
        items.add(new Item("Aged Brie", 2, 0));
        items.add(new Item("Elixir of the Mongoose", 5, 7));
        items.add(new Item("Sulfuras, Hand of Ragnaros", 0, 80));
        items.add(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
        items.add(new Item("Conjured Mana Cake", 3, 6));
    }

    public void testUpdateQualityFor5DexterityVest() {
        test.updateQuality(items);
        Optional<String> actual = items.stream()
                .filter(s -> s.getName().equals("+5 Dexterity Vest"))
                .map(s -> s.getSellIn() + " - " + s.getQuality())
                .findFirst();

        assertEquals("9 - 19", actual.get());         
    }
}
1
  • Спасибо! Все пошло!!!!!!!
    – LE_1984
    16 дек 2020 в 8:17

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.