mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-25 13:30:10 +00:00
add registry tests
This commit is contained in:
1 parent
e1a6cdb484
commit
dc688e49ce
1 file changed
+32
-7
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package registry;
|
package registry;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -35,19 +36,19 @@ public class RegistryTest {
|
|||||||
public void openRegistry() {
|
public void openRegistry() {
|
||||||
OpenRegistry<String> test = new OpenRegistryImpl<>(TypeKey.of(String.class));
|
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
|
@Test
|
||||||
public void openRegistryChecked() {
|
public void openRegistryChecked() {
|
||||||
OpenRegistry<String> test = new OpenRegistryImpl<>(TypeKey.of(String.class));
|
OpenRegistry<String> test = new OpenRegistryImpl<>(TypeKey.of(String.class));
|
||||||
|
|
||||||
test.registerChecked("test", "bazinga");
|
test.registerChecked(RegistryKey.parse("test:test"), "bazinga");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
test.registerChecked("test", "bazinga2");
|
test.registerChecked(RegistryKey.parse("test:test"), "bazinga2");
|
||||||
fail("Shouldn't be able to re-register with #registerChecked!");
|
fail("Shouldn't be able to re-register with #registerChecked!");
|
||||||
} catch(DuplicateEntryException ignore) {
|
} catch(DuplicateEntryException ignore) {
|
||||||
|
|
||||||
@@ -58,15 +59,39 @@ public class RegistryTest {
|
|||||||
public void checkedRegistry() {
|
public void checkedRegistry() {
|
||||||
CheckedRegistry<String> test = new CheckedRegistryImpl<>(new OpenRegistryImpl<>(TypeKey.of(String.class)));
|
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 {
|
try {
|
||||||
test.register("test", "bazinga2");
|
test.register(RegistryKey.parse("test:test"), "bazinga2");
|
||||||
fail("Shouldn't be able to re-register in CheckedRegistry!");
|
fail("Shouldn't be able to re-register in CheckedRegistry!");
|
||||||
} catch(DuplicateEntryException ignore) {
|
} 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