Skip to content

Commit

Permalink
typehandlerlibrary qa, spotbugs
Browse files Browse the repository at this point in the history
see #3859
  • Loading branch information
soloturn committed Oct 28, 2023
1 parent 07176f7 commit 93e51cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@


class InMemorySerializerTest {
private InMemoryPersistedDataSerializer serializer = new InMemoryPersistedDataSerializer();
private final InMemoryPersistedDataSerializer serializer = new InMemoryPersistedDataSerializer();

public static Stream<Arguments> types() {
return Stream.of(
Expand Down Expand Up @@ -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"});
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -469,7 +445,7 @@ private void checkValueArray(PersistedData data, PersistedData entry, Set<TypeGe
Assertions.assertEquals(PersistedValueArray.class, data.getClass());

Assertions.assertEquals(entry, data.getAsArray().getArrayItem(0));
typeGetters.stream()
typeGetters
.forEach(typeGetter ->
Assertions.assertEquals(typeGetter.getGetter().apply(entry),
typeGetter.getGetter().apply(data))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends PersistedData, T> R serialize(T obj, TypeHandler<T> typeHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class ObjectFieldMapTypeHandlerFactoryTest {
private static class SomeClass<T> {

Check warning on line 33 in subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactoryTest.java

View check run for this annotation

Terasology Jenkins.io / CheckStyle

FinalClassCheck

NORMAL: Class SomeClass should be declared as final.
Raw output
<p>Since Checkstyle 3.1</p><p> Checks that a class which has only private constructors is declared as final. Doesn't check for classes nested in interfaces or annotations, as they are always <code>final</code> there. </p>
private T t;
private List<T> list;

private SomeClass(T t) {
this.t = t;
}
}

@Test

Check warning on line 42 in subsystems/TypeHandlerLibrary/src/test/java/org/terasology/persistence/typeHandling/coreTypes/factories/ObjectFieldMapTypeHandlerFactoryTest.java

View check run for this annotation

Terasology Jenkins.io / CheckStyle

InnerTypeLastCheck

LOW: Init blocks, constructors, fields and methods should be before inner types.
Raw output
<p>Since Checkstyle 5.2</p><p> Check nested (inner) classes/interfaces are declared at the bottom of the class after all method and field declarations. </p>
Expand Down

0 comments on commit 93e51cf

Please sign in to comment.