mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
add registry tests
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
package registry;
|
||||
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -35,19 +36,19 @@ public class RegistryTest {
|
||||
public void openRegistry() {
|
||||
OpenRegistry<String> test = new OpenRegistryImpl<>(TypeKey.of(String.class));
|
||||
|
||||
test.register("test", "bazinga");
|
||||
test.register(RegistryKey.parse("test:test"), "bazinga");
|
||||
|
||||
assertEquals(test.getIDMatches("test").orElseThrow(), "bazinga");
|
||||
assertEquals(test.get(RegistryKey.parse("test:test")).orElseThrow(), "bazinga");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openRegistryChecked() {
|
||||
OpenRegistry<String> test = new OpenRegistryImpl<>(TypeKey.of(String.class));
|
||||
|
||||
test.registerChecked("test", "bazinga");
|
||||
test.registerChecked(RegistryKey.parse("test:test"), "bazinga");
|
||||
|
||||
try {
|
||||
test.registerChecked("test", "bazinga2");
|
||||
test.registerChecked(RegistryKey.parse("test:test"), "bazinga2");
|
||||
fail("Shouldn't be able to re-register with #registerChecked!");
|
||||
} catch(DuplicateEntryException ignore) {
|
||||
|
||||
@@ -58,15 +59,39 @@ public class RegistryTest {
|
||||
public void checkedRegistry() {
|
||||
CheckedRegistry<String> test = new CheckedRegistryImpl<>(new OpenRegistryImpl<>(TypeKey.of(String.class)));
|
||||
|
||||
test.register("test", "bazinga");
|
||||
test.register(RegistryKey.parse("test:test"), "bazinga");
|
||||
|
||||
assertEquals(test.getIDMatches("test").orElseThrow(), "bazinga");
|
||||
assertEquals(test.get(RegistryKey.parse("test:test")).orElseThrow(), "bazinga");
|
||||
|
||||
try {
|
||||
test.register("test", "bazinga2");
|
||||
test.register(RegistryKey.parse("test:test"), "bazinga2");
|
||||
fail("Shouldn't be able to re-register in CheckedRegistry!");
|
||||
} catch(DuplicateEntryException ignore) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getID() {
|
||||
OpenRegistry<String> test = new OpenRegistryImpl<>(TypeKey.of(String.class));
|
||||
|
||||
test.register(RegistryKey.parse("test:test"), "bazinga");
|
||||
|
||||
assertEquals(test.getByID("test").orElseThrow(), "bazinga");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIDAmbiguous() {
|
||||
OpenRegistry<String> test = new OpenRegistryImpl<>(TypeKey.of(String.class));
|
||||
|
||||
test.registerChecked(RegistryKey.parse("test:test"), "bazinga");
|
||||
test.registerChecked(RegistryKey.parse("test2:test"), "bazinga");
|
||||
|
||||
try {
|
||||
test.getByID("test");
|
||||
fail("Shouldn't be able to get with ambiguous ID!");
|
||||
} catch(IllegalArgumentException ignore) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user