mirror of
https://github.com/MovingBlocks/Terasology
synced 2026-05-24 09:28:22 +00:00
test: add private serialisation cases to type serialiser tests (#5217)
This commit is contained in:
parent
23b83d6a38
commit
ed7a3d64e4
2 changed files with 31 additions and 0 deletions
|
|
@ -110,15 +110,19 @@ void testJsonSerializeDeserialize() throws IOException {
|
|||
assertEquals(INSTANCE, deserializedInstance);
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.UnusedPrivateField")
|
||||
public static final class SomeClass<T> {
|
||||
@SerializedName("generic-t")
|
||||
public T data;
|
||||
public List<T> list = Lists.newArrayList();
|
||||
public Set<Animal<?>> animals = Sets.newHashSet();
|
||||
public Animal<T> singleAnimal;
|
||||
@SerializedName("private-generic-t")
|
||||
private final T privateData;
|
||||
|
||||
SomeClass(T data) {
|
||||
this.data = data;
|
||||
this.privateData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -55,6 +55,16 @@ public void testMultiTypeClassTypeHandlerCreationViaFactory() {
|
|||
assertTrue(typeHandler.get() instanceof ObjectFieldMapTypeHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test that type handler is correctly created via type handler factory")
|
||||
public void testMixedVisibilityTypeClassTypeHandlerCreationViaFactory() {
|
||||
Optional<TypeHandler<PublicPrivateMixedClass<Integer, List<Integer>>>> typeHandler =
|
||||
typeHandlerFactory.create(new TypeInfo<PublicPrivateMixedClass<Integer, List<Integer>>>() { }, context);
|
||||
|
||||
assertTrue(typeHandler.isPresent());
|
||||
assertTrue(typeHandler.get() instanceof ObjectFieldMapTypeHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test implicit type handler loading for plain old java objects (pojo)")
|
||||
public void testPojo() {
|
||||
|
|
@ -91,6 +101,18 @@ public void testMultipleObjectsOfSameType() {
|
|||
verify(typeHandlerLibrary, never()).getTypeHandler((TypeInfo<Object>) any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test implicit type handler loading for multiple objects of same type but differing visibility")
|
||||
public void testMixedVisibilityMultipleObjectsOfSameType() {
|
||||
typeHandlerFactory.create(new TypeInfo<PublicPrivateMixedClass<Integer, Integer>>() { }, context);
|
||||
|
||||
// Verify that the Integer TypeHandler loading was called on the TypeHandlerLibrary
|
||||
verify(typeHandlerLibrary, times(1)).getTypeHandler((Type) any());
|
||||
verify(typeHandlerLibrary, times(1)).getTypeHandler(eq(TypeInfo.of(Integer.class).getType()));
|
||||
verify(typeHandlerLibrary, never()).getTypeHandler((Class<Object>) any());
|
||||
verify(typeHandlerLibrary, never()).getTypeHandler((TypeInfo<Object>) any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test implicit type handler loading for multiple objects of different type")
|
||||
public void testMultipleObjectsOfDifferentType() {
|
||||
|
|
@ -113,6 +135,11 @@ private static class MultiTypeClass<T, U> {
|
|||
public U u;
|
||||
}
|
||||
|
||||
private static class PublicPrivateMixedClass<T, U> {
|
||||
public T t;
|
||||
private U u;
|
||||
}
|
||||
|
||||
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
|
||||
value = "UUF_UNUSED_FIELD",
|
||||
justification = "Direct member access is not expected. TypeHandler factory dynamically loads type handlers on type handler" +
|
||||
|
|
|
|||
Loading…
Reference in a new issue