From 6fc1e1cf48f2f277ae68795c1ced933f58abe518 Mon Sep 17 00:00:00 2001 From: GoldenGnu Date: Sun, 27 Oct 2024 02:37:48 +0200 Subject: [PATCH] Code: Updated and fixed EveRefGetterOnlineTest --- .../io/online/EveRefGetterOnlineTest.java | 143 +++++++++++------- 1 file changed, 88 insertions(+), 55 deletions(-) diff --git a/src/test/java/net/nikr/eve/jeveasset/io/online/EveRefGetterOnlineTest.java b/src/test/java/net/nikr/eve/jeveasset/io/online/EveRefGetterOnlineTest.java index 65bc292c5..9612f51a2 100644 --- a/src/test/java/net/nikr/eve/jeveasset/io/online/EveRefGetterOnlineTest.java +++ b/src/test/java/net/nikr/eve/jeveasset/io/online/EveRefGetterOnlineTest.java @@ -25,9 +25,9 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.TreeSet; import net.nikr.eve.jeveasset.CliOptions; import net.nikr.eve.jeveasset.TestUtil; import net.nikr.eve.jeveasset.data.sde.IndustryMaterial; @@ -40,12 +40,14 @@ import net.nikr.eve.jeveasset.io.online.EveRefGetter.EveRefType; import net.nikr.eve.jeveasset.io.shared.ApiIdConverter; import net.nikr.eve.jeveasset.io.shared.ThreadWoker; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.Matchers.closeTo; import org.junit.AfterClass; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import org.junit.Test; import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.ErrorCollector; public class EveRefGetterOnlineTest extends TestUtil { @@ -64,6 +66,9 @@ public static void tearDownClass() { setLoggingLevel(Level.INFO); } + @ClassRule + public static ErrorCollector collector = new ErrorCollector(); + /** * Download test * @param args @@ -80,7 +85,7 @@ public static void main(final String[] args) throws InterruptedException { @Test public void testDownloadItemsThreads() throws InterruptedException { List updates = new ArrayList<>(); - Set typeIDs = new HashSet<>(); + Set typeIDs = new TreeSet<>(); List all = new ArrayList<>(StaticData.get().getItems().keySet()); if (MAX_RUNS > 0) { Collections.shuffle(all); //Randomize @@ -88,18 +93,24 @@ public void testDownloadItemsThreads() throws InterruptedException { } else { typeIDs.addAll(all); } - //Wrong data in SDE 2024-10-06 - typeIDs.remove(24548); //Manufacturing Wrong - typeIDs.remove(57481); //Portion size 1 != 20 - typeIDs.remove(57482); //Portion size 1 != 20 - typeIDs.remove(57484); //Portion size 1 != 20 - typeIDs.remove(57485); //Portion size 1 != 20 - typeIDs.remove(73431); //Expired - typeIDs.remove(73432); //Expired - typeIDs.remove(84166); //Pattern name - typeIDs.remove(84171); //Pattern name - typeIDs.remove(84172); //Pattern name - typeIDs.remove(84212); //Pattern name + //Wrong data in SDE 2024-10-26 + typeIDs.remove(84271); //Tech: Limited Time + typeIDs.remove(84272); //Tech: Limited Time + typeIDs.remove(84273); //Tech: Limited Time + for (int i = 84297; i <= 84328; i++) { + typeIDs.remove(i); //Tech: Limited Time + } + typeIDs.remove(85279); //Tech: Limited Time + typeIDs.remove(85747); //ReprocessedMaterial + typeIDs.remove(85748); //BlueprintTypeIDs/ReprocessedMaterial + typeIDs.remove(85749); //ProductTypeID + typeIDs.remove(85750); //BlueprintTypeIDs/Tech/ReprocessedMaterial + typeIDs.remove(85751); //ProductTypeID + typeIDs.remove(85929); //Tech: Premium + typeIDs.remove(85930); //Tech: Premium + typeIDs.remove(85931); //Tech: Premium + typeIDs.remove(85932); //Tech: Premium + for (int typeID : typeIDs) { updates.add(new Download(typeID)); } @@ -151,31 +162,29 @@ public void test(final int typeID) { private static void testItem(Item itemSDE, Item itemEveRef) { String msg = "TypeID: " + itemSDE.getTypeID(); - assertNotNull(msg, itemSDE); - assertNotNull(msg, itemEveRef); - assertEquals(msg, itemSDE.getTypeID(), itemEveRef.getTypeID()); - if (itemEveRef.getPriceBase() == 0 || itemEveRef.getPriceBase() == -1) { - assertTrue(msg, itemSDE.getPriceBase() == 0 || itemSDE.getPriceBase() == -1); - } else { - assertEquals(msg, itemSDE.getPriceBase(), itemEveRef.getPriceBase(), DELTA); + assertNotNull(msg + " itemSDE is null", itemSDE); + assertNotNull(msg + " itemEveRef is null", itemEveRef); + assertEquals(msg + " TypeID", itemSDE.getTypeID(), itemEveRef.getTypeID()); + if (itemEveRef.getPriceBase() != 0 && itemEveRef.getPriceBase() != -1) { + assertEquals(msg + " PriceBase", itemSDE.getPriceBase(), itemEveRef.getPriceBase(), DELTA); } - assertEquals(msg, itemSDE.getVolume(), itemEveRef.getVolume(), DELTA); - assertEquals(msg, itemSDE.getVolumePackaged(), itemEveRef.getVolumePackaged(), DELTA); - assertEquals(msg, itemSDE.getCapacity(), itemEveRef.getCapacity(), DELTA); - assertEquals(msg, itemSDE.getMeta(), itemEveRef.getMeta()); - assertEquals(msg, itemSDE.isMarketGroup(), itemEveRef.isMarketGroup()); - assertEquals(msg, itemSDE.isPiMaterial(), itemEveRef.isPiMaterial()); - assertEquals(msg, itemSDE.getPortion(), itemEveRef.getPortion()); - assertEquals(msg, itemSDE.getProductTypeID(), itemEveRef.getProductTypeID()); - testLists(msg, itemSDE.getBlueprintTypeIDs(), itemEveRef.getBlueprintTypeIDs(), new Tester() { + assertEquals(msg + " Volume", itemSDE.getVolume(), itemEveRef.getVolume(), DELTA); + assertEquals(msg + " VolumePackaged", itemSDE.getVolumePackaged(), itemEveRef.getVolumePackaged(), DELTA); + assertEquals(msg + " Capacity", itemSDE.getCapacity(), itemEveRef.getCapacity(), DELTA); + assertEquals(msg + " Meta", itemSDE.getMeta(), itemEveRef.getMeta()); + assertEquals(msg + " MarketGroup", itemSDE.isMarketGroup(), itemEveRef.isMarketGroup()); + assertEquals(msg + " PiMaterial", itemSDE.isPiMaterial(), itemEveRef.isPiMaterial()); + assertEquals(msg + " Portion", itemSDE.getPortion(), itemEveRef.getPortion()); + assertEquals(msg + " ProductTypeID", itemSDE.getProductTypeID(), itemEveRef.getProductTypeID()); + testLists(msg + " BlueprintTypeIDs size", itemSDE.getBlueprintTypeIDs(), itemEveRef.getBlueprintTypeIDs(), new Tester() { @Override public void test(Integer sde, Integer eveRef) { - assertEquals(msg, sde, eveRef); + assertEquals(msg + " BlueprintTypeIDs", sde, eveRef); } }); - assertEquals(msg, itemSDE.getProductQuantity(), itemEveRef.getProductQuantity()); - assertEquals(msg, itemSDE.isBlueprint(), itemEveRef.isBlueprint()); - assertEquals(msg, itemSDE.isFormula(), itemEveRef.isFormula()); + assertEquals(msg + " ProductQuantity", itemSDE.getProductQuantity(), itemEveRef.getProductQuantity()); + assertEquals(msg + " Blueprint", itemSDE.isBlueprint(), itemEveRef.isBlueprint()); + assertEquals(msg + " Formula", itemSDE.isFormula(), itemEveRef.isFormula()); /* //Don't test dynamic values assertEquals(msg, itemSDE.getPriceReprocessed(), itemEveRef.getPriceReprocessed(), DELTA); @@ -185,16 +194,16 @@ public void test(Integer sde, Integer eveRef) { if (itemSDE.getTypeName().endsWith(".type")) { System.out.println("Ignorering: " + itemSDE.getTypeName()); } else { - assertEquals(msg, itemSDE.getTypeName(), itemEveRef.getTypeName()); + assertEquals(msg + " TypeName", itemSDE.getTypeName(), itemEveRef.getTypeName()); } - assertEquals(msg, itemSDE.getGroup(), itemEveRef.getGroup()); - assertEquals(msg, itemSDE.getCategory(), itemEveRef.getCategory()); - assertEquals(msg, itemSDE.getTech(), itemEveRef.getTech()); - assertEquals(msg, null, itemSDE.getVersion()); - assertEquals(msg, itemEveRef.getVersion(), EsiItemsGetter.ESI_ITEM_VERSION); - assertEquals(msg, itemSDE.getSlot(), itemEveRef.getSlot()); - assertEquals(msg, itemSDE.getChargeSize(), itemEveRef.getChargeSize()); - testLists(msg, itemSDE.getReprocessedMaterial(), itemEveRef.getReprocessedMaterial(), new Comparator() { + assertEquals(msg + " Group", itemSDE.getGroup(), itemEveRef.getGroup()); + assertEquals(msg + " Category", itemSDE.getCategory(), itemEveRef.getCategory()); + assertEquals(msg + " Tech", itemSDE.getTech(), itemEveRef.getTech()); + assertEquals(msg + " itemSDE Version", null, itemSDE.getVersion()); + assertEquals(msg + " itemEveRef Version", itemEveRef.getVersion(), EsiItemsGetter.ESI_ITEM_VERSION); + assertEquals(msg + " Slot", itemSDE.getSlot(), itemEveRef.getSlot()); + assertEquals(msg + " ChargeSize", itemSDE.getChargeSize(), itemEveRef.getChargeSize()); + testLists(msg + " ReprocessedMaterial", itemSDE.getReprocessedMaterial(), itemEveRef.getReprocessedMaterial(), new Comparator() { @Override public int compare(ReprocessedMaterial o1, ReprocessedMaterial o2) { return Integer.compare(o1.getTypeID(), o2.getTypeID()); @@ -202,9 +211,9 @@ public int compare(ReprocessedMaterial o1, ReprocessedMaterial o2) { } , new Tester() { @Override public void test(ReprocessedMaterial sde, ReprocessedMaterial eveRef) { - assertEquals(msg, sde.getTypeID(), eveRef.getTypeID()); - assertEquals(msg, sde.getQuantity(), eveRef.getQuantity()); - assertEquals(msg, sde.getPortionSize(), eveRef.getPortionSize()); + assertEquals(msg + " ReprocessedMaterial TypeID", sde.getTypeID(), eveRef.getTypeID()); + assertEquals(msg + " ReprocessedMaterial Quantity", sde.getQuantity(), eveRef.getQuantity()); + assertEquals(msg + " ReprocessedMaterial PortionSize", sde.getPortionSize(), eveRef.getPortionSize()); } }); testLists(msg, itemSDE.getManufacturingMaterials(), itemEveRef.getManufacturingMaterials(), new Comparator() { @@ -215,8 +224,8 @@ public int compare(IndustryMaterial o1, IndustryMaterial o2) { } , new Tester() { @Override public void test(IndustryMaterial sde, IndustryMaterial eveRef) { - assertEquals(msg, sde.getTypeID(), eveRef.getTypeID()); - assertEquals(msg, sde.getQuantity(), eveRef.getQuantity()); + assertEquals(msg + " ManufacturingMaterials TypeID", sde.getTypeID(), eveRef.getTypeID()); + assertEquals(msg + " ManufacturingMaterials Quantity", sde.getQuantity(), eveRef.getQuantity()); } }); testLists(msg, itemSDE.getReactionMaterials(), itemEveRef.getReactionMaterials(), new Comparator() { @@ -227,12 +236,37 @@ public int compare(IndustryMaterial o1, IndustryMaterial o2) { } , new Tester() { @Override public void test(IndustryMaterial sde, IndustryMaterial eveRef) { - assertEquals(msg, sde.getTypeID(), eveRef.getTypeID()); - assertEquals(msg, sde.getQuantity(), eveRef.getQuantity()); + assertEquals(msg + " ReactionMaterials TypeID", sde.getTypeID(), eveRef.getTypeID()); + assertEquals(msg + " ReactionMaterials Quantity", sde.getQuantity(), eveRef.getQuantity()); } }); } + public static void assertNotNull(String message, Object object) { + collector.checkThat(message, object, notNullValue()); + } + + public static void assertNotNull(Object object) { + collector.checkThat(object, notNullValue()); + } + + public static void assertEquals(String message, Object expected, Object actual) { + collector.checkThat(message, expected, equalTo(actual)); + } + + public static void assertEquals(Object expected, Object actual) { + collector.checkThat(expected, equalTo(actual)); + } + + public static void assertEquals(String message, double expected, double actual, double delta) { + collector.checkThat(message, expected, closeTo(actual, delta)); + } + + public static void assertEquals(double expected, double actual, double delta) { + collector.checkThat(expected, closeTo(actual, delta)); + } + + private static void testLists(String msg, List sde, List eveRef, Comparator comparator, Tester tester) { Collections.sort(eveRef, comparator); Collections.sort(sde, comparator); @@ -244,7 +278,6 @@ private static > void testLists(String msg, Coll } private static > void testLists(String msg, List sde, List eveRef, Tester tester) { - assertEquals(sde.size(), eveRef.size()); Collections.sort(eveRef); Collections.sort(sde); testSortedLists(msg, sde, eveRef, tester);