diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 00000000000..966d5f56a99 --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/build-logic/src/main/kotlin/terasology-metrics.gradle.kts b/build-logic/src/main/kotlin/terasology-metrics.gradle.kts index 123664364e4..20aef4e38bc 100644 --- a/build-logic/src/main/kotlin/terasology-metrics.gradle.kts +++ b/build-logic/src/main/kotlin/terasology-metrics.gradle.kts @@ -14,6 +14,9 @@ plugins { } dependencies { + // workaround to maake spotbugs @SuppressFBWarnings work. + implementation("com.github.spotbugs:spotbugs-annotations:4.8.0") + pmd("net.sourceforge.pmd:pmd-core:6.55.0") pmd("net.sourceforge.pmd:pmd-java:6.55.0") diff --git a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/Serializer.java b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/Serializer.java index 7cd7a19059b..1361e671f7f 100644 --- a/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/Serializer.java +++ b/subsystems/TypeHandlerLibrary/src/main/java/org/terasology/persistence/typeHandling/Serializer.java @@ -18,8 +18,8 @@ public class Serializer { private static final Logger logger = LoggerFactory.getLogger(Serializer.class); - private ClassMetadata classMetadata; - private Map, TypeHandler> fieldHandlers; + private final ClassMetadata classMetadata; + private final Map, TypeHandler> fieldHandlers; public Serializer(ClassMetadata classMetadata, Map, TypeHandler> fieldHandlers) { this.fieldHandlers = fieldHandlers; diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/FutureTypeHandlerTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/FutureTypeHandlerTest.java index bd485d52815..48bc0b57aba 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/FutureTypeHandlerTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/FutureTypeHandlerTest.java @@ -27,30 +27,6 @@ public class FutureTypeHandlerTest { private final TypeHandlerLibrary typeHandlerLibrary = Mockito.spy(new TypeHandlerLibrary(reflections)); - private static final class RecursiveType { - final T data; - final List> children; - - @SafeVarargs - private RecursiveType(T data, RecursiveType... children) { - this.data = data; - this.children = Lists.newArrayList(children); - } - } - - private class ResultCaptor implements Answer { - private T result = null; - public T getResult() { - return result; - } - - @Override - public T answer(InvocationOnMock invocationOnMock) throws Throwable { - result = (T) invocationOnMock.callRealMethod(); - return result; - } - } - @Test public void testRecursiveType() { ResultCaptor>>> resultCaptor = new ResultCaptor<>(); @@ -77,4 +53,28 @@ public void testRecursiveType() { assertEquals(typeHandler, future.typeHandler); } + + private static final class RecursiveType { + final T data; + final List> children; + + @SafeVarargs + private RecursiveType(T data, RecursiveType... children) { + this.data = data; + this.children = Lists.newArrayList(children); + } + } + + private class ResultCaptor implements Answer { + private T result = null; + public T getResult() { + return result; + } + + @Override + public T answer(InvocationOnMock invocationOnMock) throws Throwable { + result = (T) invocationOnMock.callRealMethod(); + return result; + } + } } diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/InMemorySerializerTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/InMemorySerializerTest.java index 8d77751f98b..f407648ebc3 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/InMemorySerializerTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/InMemorySerializerTest.java @@ -39,7 +39,7 @@ class InMemorySerializerTest { - private InMemoryPersistedDataSerializer serializer = new InMemoryPersistedDataSerializer(); + private final InMemoryPersistedDataSerializer serializer = new InMemoryPersistedDataSerializer(); public static Stream types() { return Stream.of( @@ -123,30 +123,6 @@ void serializeStrings() { Assertions.assertThrows(ClassCastException.class, data::getAsDouble); } - //TODO remove it - public void template(PersistedData data) { - Assertions.assertFalse(data.isString()); - Assertions.assertFalse(data.isArray()); - Assertions.assertFalse(data.isNull()); - Assertions.assertFalse(data.isNumber()); - Assertions.assertFalse(data.isBoolean()); - Assertions.assertFalse(data.isBytes()); - Assertions.assertFalse(data.isValueMap()); - - Assertions.assertThrows(IllegalStateException.class, data::getAsValueMap); - Assertions.assertThrows(IllegalStateException.class, data::getAsArray); - - Assertions.assertThrows(DeserializationException.class, data::getAsByteBuffer); - Assertions.assertThrows(DeserializationException.class, data::getAsBytes); - - Assertions.assertThrows(ClassCastException.class, data::getAsString); - Assertions.assertThrows(ClassCastException.class, data::getAsBoolean); - Assertions.assertThrows(ClassCastException.class, data::getAsInteger); - Assertions.assertThrows(ClassCastException.class, data::getAsLong); - Assertions.assertThrows(ClassCastException.class, data::getAsFloat); - Assertions.assertThrows(ClassCastException.class, data::getAsDouble); - } - @Test void serializeOneAsStrings() { PersistedData data = serializer.serialize(new String[]{"foo"}); @@ -306,7 +282,7 @@ void serializeBytes() { Assertions.assertEquals(PersistedBytes.class, data.getClass()); Assertions.assertTrue(data.isBytes()); - Assertions.assertEquals(value, data.getAsBytes()); + Assertions.assertArrayEquals(value, data.getAsBytes()); Assertions.assertEquals(ByteBuffer.wrap(value), data.getAsByteBuffer()); Assertions.assertFalse(data.isString()); @@ -335,7 +311,7 @@ void serializeByteBuffer() { Assertions.assertEquals(PersistedBytes.class, data.getClass()); Assertions.assertTrue(data.isBytes()); - Assertions.assertEquals(value, data.getAsBytes()); + Assertions.assertArrayEquals(value, data.getAsBytes()); Assertions.assertEquals(ByteBuffer.wrap(value), data.getAsByteBuffer()); Assertions.assertFalse(data.isString()); @@ -469,7 +445,7 @@ private void checkValueArray(PersistedData data, PersistedData entry, Set Assertions.assertEquals(typeGetter.getGetter().apply(entry), typeGetter.getGetter().apply(data)) diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/TypeHandlerLibraryTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/TypeHandlerLibraryTest.java index 6d027341def..09659522ebe 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/TypeHandlerLibraryTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/TypeHandlerLibraryTest.java @@ -22,19 +22,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue; class TypeHandlerLibraryTest { - private static Reflections reflections; private static TypeHandlerLibrary typeHandlerLibrary; @BeforeAll public static void setup() { - reflections = new Reflections(TypeHandlerLibraryTest.class.getClassLoader()); + Reflections reflections = new Reflections(TypeHandlerLibraryTest.class.getClassLoader()); typeHandlerLibrary = new TypeHandlerLibrary(reflections); TypeHandlerLibrary.populateBuiltInHandlers(typeHandlerLibrary); } - @MappedContainer - private static class AMappedContainer { } - @Test public void testMappedContainerHandler() { TypeHandler handler = typeHandlerLibrary.getTypeHandler(AMappedContainer.class).get(); @@ -93,4 +89,7 @@ void testGetBaseTypeHandler() { } private enum AnEnum { } + + @MappedContainer + private static class AMappedContainer { } } diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/BytesTypeHandlerTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/BytesTypeHandlerTest.java index f0d9690bbb7..dff71f2ae62 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/BytesTypeHandlerTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/BytesTypeHandlerTest.java @@ -39,10 +39,10 @@ void byteArraySerializeDeserialize() { byte[] expectedObj = new byte[]{(byte) 0xFF}; PersistedBytes data = serialize(expectedObj, new ByteArrayTypeHandler()); - Assertions.assertEquals(expectedObj, data.getAsBytes()); + Assertions.assertArrayEquals(expectedObj, data.getAsBytes()); byte[] obj = deserialize(data, new ByteArrayTypeHandler()); - Assertions.assertEquals(expectedObj, obj); + Assertions.assertArrayEquals(expectedObj, obj); } private R serialize(T obj, TypeHandler typeHandler) { diff --git a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactoryTest.java b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactoryTest.java index 3451b19d965..d82ed38444e 100644 --- a/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactoryTest.java +++ b/subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactoryTest.java @@ -3,6 +3,7 @@ package org.terasology.persistence.typeHandling.coreTypes.factories; import com.google.common.collect.Maps; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.junit.jupiter.api.Test; import org.terasology.persistence.typeHandling.TypeHandler; import org.terasology.persistence.typeHandling.TypeHandlerContext; @@ -30,11 +31,6 @@ public class ObjectFieldMapTypeHandlerFactoryTest { private final TypeHandlerContext context = new TypeHandlerContext(typeHandlerLibrary, mock(SerializationSandbox.class)); - private static class SomeClass { - private T t; - private List list; - } - @Test public void testObject() { Optional>> typeHandler = @@ -48,4 +44,11 @@ public void testObject() { verify(typeHandlerLibrary).getTypeHandler(eq(new TypeInfo>() { }.getType())); } + + private static class SomeClass { + @SuppressFBWarnings + private T t; + @SuppressFBWarnings + private List list; + } }