Skip to content

Instantly share code, notes, and snippets.

@emilybache
Created May 31, 2024 13:28
Show Gist options
  • Save emilybache/0a3386840bf4c495ddfc0ad35e038575 to your computer and use it in GitHub Desktop.
Save emilybache/0a3386840bf4c495ddfc0ad35e038575 to your computer and use it in GitHub Desktop.
Sample approval test in Java that covers the Gilded Rose functionality
package com.gildedrose;
import org.approvaltests.Approvals;
import org.approvaltests.combinations.CombinationApprovals;
import org.approvaltests.reporters.DiffReporter;
import org.approvaltests.reporters.UseReporter;
import org.junit.jupiter.api.Test;
@UseReporter(DiffReporter.class)
public class GildedRoseApprovalTest {
@Test
public void updateQuality() {
CombinationApprovals.verifyAllCombinations(
this::doUpdateQuality,
new String[]{"foo", "Aged Brie", "Backstage passes to a TAFKAL80ETC concert", "Sulfuras, Hand of Ragnaros"},
new Integer[] {-1, 0, 5, 6, 10, 11}, // sellIn
new Integer[] {0, 1, 2, 49, 50} // quality
);
}
public String doUpdateQuality(String name, Integer sellIn, Integer quality) {
Item[] items = new Item[]{new Item(name, sellIn, quality)};
GildedRose app = new GildedRose(items);
app.updateQuality();
Item item = items[0];
return itemPrinter(item);
}
static String itemPrinter(Item item) {
return item.name + ", sellIn: " + item.sellIn + ", Quality: " + item.quality;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment