mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Warn once for repeated pack warnings
- Warn once per pack, type and key for missing resources in the resource loaders - Warn once per file for unreadable resources and report the stack only the first time - Warn once for unknown loot materials, missing loot tables and objects without a load key - Add IrisLogging.forgetOnceKeys(prefix) for scoped resets - Forget a pack's warn-once keys on clearLists() and hotloaded() so a rebroken key warns again - Add tests for scoped reset, loader misses, read failures, loot and marker warnings
This commit is contained in:
1 parent
d7c5526eab
commit
00b0509219
16 files changed
+705
-48
No files matched your search
+62
@@ -0,0 +1,62 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.testsupport.CapturedLog;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class PlacementMarkerOnceWarningTest {
|
||||
private static final String SKIPPED = "Skipping placement marker write";
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private CapturedLog log;
|
||||
|
||||
@Before
|
||||
public void captureLog() {
|
||||
log = CapturedLog.bind();
|
||||
}
|
||||
|
||||
@After
|
||||
public void releaseLog() {
|
||||
log.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anObjectWithoutALoadKeyWarnsOncePerContextNoMatterTheId() {
|
||||
IrisObject object = new IrisObject(0, 0, 0);
|
||||
|
||||
assertNull(MantleObjectComponent.placementMarker(object, 1, "surface"));
|
||||
assertNull(MantleObjectComponent.placementMarker(object, 2, "surface"));
|
||||
assertNull(MantleObjectComponent.placementMarker(new IrisObject(0, 0, 0), 3, "surface"));
|
||||
|
||||
assertEquals(1, log.warnings(SKIPPED).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDifferentContextWarnsSeparately() {
|
||||
IrisObject object = new IrisObject(0, 0, 0);
|
||||
|
||||
MantleObjectComponent.placementMarker(object, 1, "surface");
|
||||
MantleObjectComponent.placementMarker(object, 1, "procedural");
|
||||
|
||||
assertEquals(2, log.warnings(SKIPPED).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLoadKeyedObjectNeverWarns() {
|
||||
IrisObject object = new IrisObject(0, 0, 0);
|
||||
object.setLoadKey("trees/oak");
|
||||
|
||||
assertEquals("trees/oak@7", MantleObjectComponent.placementMarker(object, 7, "surface"));
|
||||
|
||||
assertEquals(0, log.warnings(SKIPPED).size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
package art.arcane.iris.pack.loading;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PreservationRegistry;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.world.history.GenerationRegistryContract;
|
||||
import art.arcane.iris.testsupport.CapturedLog;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* A pack typo is reached per chunk, so a loader miss or an unreadable file must be stated once per pack,
|
||||
* resource type and key, and stated again after the pack's caches are cleared (hotload).
|
||||
*/
|
||||
public class ResourceLoaderOnceWarningTest {
|
||||
private static final String MISSING = "Couldn't find ";
|
||||
private static final String UNREADABLE = "Couldn't read ";
|
||||
private static final byte[] GARBAGE = {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
private CapturedLog log;
|
||||
private IrisData data;
|
||||
|
||||
@Before
|
||||
public void openPack() throws Exception {
|
||||
log = CapturedLog.bind(temporaryFolder.newFolder("platform-data"));
|
||||
IrisServices.register(PreservationRegistry.class, mock(PreservationRegistry.class));
|
||||
data = openPack("pack");
|
||||
assertNotNull(log.messages() + " " + log.reportedErrors(), data.getObjectLoader());
|
||||
}
|
||||
|
||||
private IrisData openPack(String name) throws Exception {
|
||||
IrisData opened = IrisData.openRuntime(temporaryFolder.newFolder(name));
|
||||
opened.bindGenerationRegistryContract(GenerationRegistryContract.empty());
|
||||
return opened;
|
||||
}
|
||||
|
||||
@After
|
||||
public void closePack() {
|
||||
data.close();
|
||||
IrisServices.remove(PreservationRegistry.class);
|
||||
log.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSameMissingKeyWarnsOnce() {
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
data.getObjectLoader().findFile("trees/typo");
|
||||
|
||||
assertEquals(1, log.warnings(MISSING).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDifferentKeyWarnsSeparately() {
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
data.getObjectLoader().load("trees/other-typo");
|
||||
|
||||
assertEquals(2, log.warnings(MISSING).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSameKeyInAnotherResourceTypeWarnsSeparately() {
|
||||
data.getObjectLoader().load("shared");
|
||||
data.getMatterLoader().load("shared");
|
||||
data.getImageLoader().load("shared");
|
||||
|
||||
assertEquals(3, log.warnings(MISSING).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSameKeyInAnotherPackWarnsSeparately() throws Exception {
|
||||
IrisData other = openPack("other-pack");
|
||||
try {
|
||||
data.getObjectLoader().load("shared");
|
||||
other.getObjectLoader().load("shared");
|
||||
|
||||
assertEquals(2, log.warnings(MISSING).size());
|
||||
} finally {
|
||||
other.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void literalNullRefusalWarnsOnce() {
|
||||
data.getObjectLoader().load("null");
|
||||
data.getObjectLoader().load("null");
|
||||
data.getObjectLoader().findFile("null");
|
||||
data.getObjectLoader().findFile("null");
|
||||
|
||||
assertEquals(2, log.warnings("Refusing ").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearingTheListsLetsTheSameMissingKeyWarnAgain() {
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
assertEquals(1, log.warnings(MISSING).size());
|
||||
|
||||
data.clearLists();
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
|
||||
assertEquals(2, log.warnings(MISSING).size());
|
||||
}
|
||||
|
||||
/** Studio hotload rebuilds the pack's loaders through hotloaded() (or reopens it) without clearLists(). */
|
||||
@Test
|
||||
public void rebuildingThePackLoadersLetsTheSameMissingKeyWarnAgain() {
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
|
||||
data.hotloaded();
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
|
||||
assertEquals(2, log.warnings(MISSING).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reopeningThePackFolderLetsTheSameMissingKeyWarnAgain() {
|
||||
data.getObjectLoader().load("trees/typo");
|
||||
|
||||
IrisData reopened = IrisData.openRuntime(data.getDataFolder());
|
||||
try {
|
||||
reopened.getObjectLoader().load("trees/typo");
|
||||
|
||||
assertEquals(2, log.warnings(MISSING).size());
|
||||
} finally {
|
||||
reopened.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearingOnePackKeepsAnotherPacksKeysClaimed() throws Exception {
|
||||
IrisData other = openPack("other-pack");
|
||||
try {
|
||||
data.getObjectLoader().load("shared");
|
||||
other.getObjectLoader().load("shared");
|
||||
|
||||
data.clearLists();
|
||||
data.getObjectLoader().load("shared");
|
||||
other.getObjectLoader().load("shared");
|
||||
|
||||
assertEquals(3, log.warnings(MISSING).size());
|
||||
} finally {
|
||||
other.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackWhosePathIsAPrefixOfAnotherIsNotReset() throws Exception {
|
||||
IrisData longer = openPack("pack-two");
|
||||
try {
|
||||
longer.getObjectLoader().load("shared");
|
||||
|
||||
data.clearLists();
|
||||
longer.getObjectLoader().load("shared");
|
||||
|
||||
assertEquals(1, log.warnings(MISSING).size());
|
||||
} finally {
|
||||
longer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anUnreadableObjectWarnsOnceAndReportsItsStackOnce() throws Exception {
|
||||
writeGarbage(data.getObjectLoader(), "broken.iob");
|
||||
|
||||
data.getObjectLoader().load("broken");
|
||||
data.getObjectLoader().load("broken");
|
||||
data.getObjectLoader().load("broken");
|
||||
|
||||
assertEquals(1, log.warnings(UNREADABLE).size());
|
||||
assertEquals(1, log.reportedErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anUnreadableMatterObjectWarnsOnceAndReportsItsStackOnce() throws Exception {
|
||||
writeGarbage(data.getMatterLoader(), "broken.mat");
|
||||
|
||||
data.getMatterLoader().load("broken");
|
||||
data.getMatterLoader().load("broken");
|
||||
|
||||
assertEquals(1, log.warnings(UNREADABLE).size());
|
||||
assertEquals(1, log.reportedErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anUnreadableImageWarnsOnce() throws Exception {
|
||||
writeGarbage(data.getImageLoader(), "broken.png");
|
||||
|
||||
data.getImageLoader().load("broken");
|
||||
data.getImageLoader().load("broken");
|
||||
|
||||
assertEquals(1, log.warnings(UNREADABLE).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDifferentUnreadableFileWarnsSeparately() throws Exception {
|
||||
writeGarbage(data.getObjectLoader(), "broken.iob");
|
||||
writeGarbage(data.getObjectLoader(), "also-broken.iob");
|
||||
|
||||
data.getObjectLoader().load("broken");
|
||||
data.getObjectLoader().load("also-broken");
|
||||
|
||||
assertEquals(2, log.warnings(UNREADABLE).size());
|
||||
assertEquals(2, log.reportedErrors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearingTheListsReportsTheStackAgainForTheNextFirstWarning() throws Exception {
|
||||
writeGarbage(data.getObjectLoader(), "broken.iob");
|
||||
data.getObjectLoader().load("broken");
|
||||
|
||||
data.clearLists();
|
||||
data.getObjectLoader().load("broken");
|
||||
|
||||
assertEquals(2, log.warnings(UNREADABLE).size());
|
||||
assertEquals(2, log.reportedErrors().size());
|
||||
}
|
||||
|
||||
private void writeGarbage(ResourceLoader<?> loader, String fileName) throws Exception {
|
||||
File folder = new File(temporaryFolder.getRoot(), "pack/" + loader.getFolderName());
|
||||
Files.createDirectories(folder.toPath());
|
||||
Files.write(new File(folder, fileName).toPath(), GARBAGE);
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,34 @@ public class IrisLoggingTest {
|
||||
assertEquals(List.of(LogLevel.WARN), levels);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forgettingAPrefixReleasesOnlyTheKeysUnderIt() {
|
||||
String scope = uniqueKey() + "|";
|
||||
String otherScope = uniqueKey() + "|";
|
||||
assertTrue(IrisLogging.warnOnce(scope + "a", "a"));
|
||||
assertTrue(IrisLogging.warnOnce(scope + "b", "b"));
|
||||
assertTrue(IrisLogging.warnOnce(otherScope + "a", "other"));
|
||||
levels.clear();
|
||||
|
||||
IrisLogging.forgetOnceKeys(scope);
|
||||
|
||||
assertTrue(IrisLogging.warnOnce(scope + "a", "a"));
|
||||
assertTrue(IrisLogging.warnOnce(scope + "b", "b"));
|
||||
assertFalse(IrisLogging.warnOnce(otherScope + "a", "other"));
|
||||
assertEquals(List.of(LogLevel.WARN, LogLevel.WARN, LogLevel.DEBUG), levels);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forgettingANullOrEmptyPrefixKeepsEveryKeyClaimed() {
|
||||
String key = uniqueKey();
|
||||
assertTrue(IrisLogging.warnOnce(key, "claimed"));
|
||||
|
||||
IrisLogging.forgetOnceKeys(null);
|
||||
IrisLogging.forgetOnceKeys("");
|
||||
|
||||
assertFalse(IrisLogging.warnOnce(key, "claimed"));
|
||||
}
|
||||
|
||||
private void bindCapturingPlatform() {
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
capturingPlatform = platform;
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PreservationRegistry;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.testsupport.CapturedLog;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import art.arcane.iris.world.history.GenerationRegistryContract;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class IrisObjectPlacementOnceWarningTest {
|
||||
private static final String MISSING_TABLE = "Couldn't find loot table ";
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
private CapturedLog log;
|
||||
private IrisData data;
|
||||
|
||||
@Before
|
||||
public void openPack() throws Exception {
|
||||
log = CapturedLog.bind(temporaryFolder.newFolder("platform-data"));
|
||||
IrisServices.register(PreservationRegistry.class, mock(PreservationRegistry.class));
|
||||
data = IrisData.openRuntime(temporaryFolder.newFolder("pack"));
|
||||
data.bindGenerationRegistryContract(GenerationRegistryContract.empty());
|
||||
}
|
||||
|
||||
@After
|
||||
public void closePack() {
|
||||
data.close();
|
||||
IrisServices.remove(PreservationRegistry.class);
|
||||
log.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aMissingLootTableWarnsOnceAcrossPlacements() {
|
||||
lookUpTable(placementWithLoot("chests/typo"));
|
||||
lookUpTable(placementWithLoot("chests/typo"));
|
||||
|
||||
assertEquals(1, log.warnings(MISSING_TABLE).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDifferentMissingLootTableWarnsSeparately() {
|
||||
lookUpTable(placementWithLoot("chests/typo"));
|
||||
lookUpTable(placementWithLoot("chests/other-typo"));
|
||||
|
||||
assertEquals(2, log.warnings(MISSING_TABLE).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearingThePackListsLetsTheSameMissingLootTableWarnAgain() {
|
||||
lookUpTable(placementWithLoot("chests/typo"));
|
||||
|
||||
data.clearLists();
|
||||
lookUpTable(placementWithLoot("chests/typo"));
|
||||
|
||||
assertEquals(2, log.warnings(MISSING_TABLE).size());
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement placementWithLoot(String tableName) {
|
||||
IrisObjectLoot loot = new IrisObjectLoot();
|
||||
loot.setName(tableName);
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setLoot(new KList<IrisObjectLoot>().qadd(loot));
|
||||
return placement;
|
||||
}
|
||||
|
||||
private void lookUpTable(IrisObjectPlacement placement) {
|
||||
placement.getCache(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package art.arcane.iris.testsupport;
|
||||
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.LogLevel;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Binds a mock platform that records every log line and reported stack trace. {@link #close()} unbinds it,
|
||||
* which also clears the JVM-global warn-once keys, so tests using it do not depend on order.
|
||||
*/
|
||||
public final class CapturedLog implements AutoCloseable {
|
||||
private final List<LogLevel> levels = new ArrayList<>();
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
private final List<Throwable> reportedErrors = new ArrayList<>();
|
||||
|
||||
private CapturedLog() {
|
||||
}
|
||||
|
||||
public static CapturedLog bind() {
|
||||
return bind(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataRoot where the platform keeps its data files (settings are read from there on first use);
|
||||
* null for a platform that has none
|
||||
*/
|
||||
public static CapturedLog bind(File dataRoot) {
|
||||
IrisPlatforms.unbind();
|
||||
CapturedLog log = new CapturedLog();
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
if (dataRoot != null) {
|
||||
doReturn(dataRoot).when(platform).dataFolder();
|
||||
doAnswer(invocation -> {
|
||||
Object[] segments = invocation.getArguments();
|
||||
return new File(dataRoot, String.join(File.separator, Arrays.copyOf(segments, segments.length, String[].class)));
|
||||
}).when(platform).dataFile(any(String[].class));
|
||||
}
|
||||
doAnswer(invocation -> {
|
||||
log.levels.add(invocation.getArgument(0, LogLevel.class));
|
||||
log.messages.add(invocation.getArgument(1, String.class));
|
||||
return null;
|
||||
}).when(platform).log(any(LogLevel.class), anyString());
|
||||
doAnswer(invocation -> {
|
||||
log.reportedErrors.add(invocation.getArgument(0, Throwable.class));
|
||||
return null;
|
||||
}).when(platform).reportError(any(Throwable.class));
|
||||
IrisPlatforms.bind(platform);
|
||||
return log;
|
||||
}
|
||||
|
||||
/** Messages logged at WARN that start with {@code prefix}. */
|
||||
public List<String> warnings(String prefix) {
|
||||
List<String> found = new ArrayList<>();
|
||||
for (int index = 0; index < messages.size(); index++) {
|
||||
if (levels.get(index) == LogLevel.WARN && messages.get(index).startsWith(prefix)) {
|
||||
found.add(messages.get(index));
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
public List<String> messages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public List<Throwable> reportedErrors() {
|
||||
return reportedErrors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
IrisPlatforms.unbind();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package art.arcane.iris.world.loot;
|
||||
|
||||
import art.arcane.iris.integration.ExternalDataSVC;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.testsupport.CapturedLog;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisLootOnceWarningTest {
|
||||
private static final String UNKNOWN_MATERIAL = "Unknown Material: ";
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private CapturedLog log;
|
||||
|
||||
@Before
|
||||
public void captureLogAndRegisterEmptyProvider() {
|
||||
log = CapturedLog.bind();
|
||||
ExternalDataSVC external = mock(ExternalDataSVC.class);
|
||||
when(external.getItemStack(any(), any())).thenReturn(Optional.empty());
|
||||
IrisServices.register(ExternalDataSVC.class, external);
|
||||
}
|
||||
|
||||
@After
|
||||
public void release() {
|
||||
IrisServices.remove(ExternalDataSVC.class);
|
||||
log.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anUnknownMaterialWarnsOncePerType() {
|
||||
IrisLoot loot = lootOf("mymod:ruby");
|
||||
|
||||
resolve(loot, 1);
|
||||
resolve(loot, 2);
|
||||
resolve(lootOf("mymod:ruby"), 3);
|
||||
|
||||
assertEquals(1, log.warnings(UNKNOWN_MATERIAL).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDifferentUnknownMaterialWarnsSeparately() {
|
||||
resolve(lootOf("mymod:ruby"), 1);
|
||||
resolve(lootOf("mymod:sapphire"), 1);
|
||||
|
||||
assertEquals(2, log.warnings(UNKNOWN_MATERIAL).size());
|
||||
}
|
||||
|
||||
private static IrisLoot lootOf(String type) {
|
||||
IrisLoot loot = new IrisLoot();
|
||||
loot.setType(type);
|
||||
return loot;
|
||||
}
|
||||
|
||||
/**
|
||||
* The warning is logged before the AIR fallback is built, and building an ItemStack needs a Bukkit
|
||||
* server this test does not have.
|
||||
*/
|
||||
private static void resolve(IrisLoot loot, long seed) {
|
||||
try {
|
||||
loot.get(false, new RNG(seed));
|
||||
} catch (NullPointerException noBukkitServer) {
|
||||
// expected: see above
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user