@@ -0,0 +1,3380 @@
+/*%0A * Copyright 2018 MovingBlocks%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.terasology.persistence.typeHandling.gson;%0A%0Aimport com.google.gson.Gson;%0Aimport com.google.gson.GsonBuilder;%0Aimport com.google.gson.stream.JsonReader;%0Aimport com.google.gson.stream.JsonWriter;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.terasology.persistence.typeHandling.extensionTypes.ColorTypeHandler;%0Aimport org.terasology.rendering.nui.Color;%0A%0Aimport java.util.Objects;%0A%0Apublic class GsonTypeHandlerAdapterTest %7B%0A    private static final String OBJECT_JSON_ARRAY = %22%7B%5C%22color%5C%22:%5B222,173,190,239%5D,%5C%22i%5C%22:-123%7D%22;%0A    private static final String OBJECT_JSON_HEX = %22%7B%5C%22color%5C%22:DEADBEEF,%5C%22i%5C%22:-123%7D%22;%0A    private static final TestClass OBJECT = new TestClass(new Color(0xDEADBEEF), -123);%0A%0A    private final ColorTypeHandler typeHandler = new ColorTypeHandler();%0A%0A    private final GsonTypeHandlerAdapterFactory typeHandlerAdapterFactory = new GsonTypeHandlerAdapterFactory() %7B%7B%0A        addTypeHandler(Color.class, typeHandler);%0A    %7D%7D;%0A%0A    private final Gson gson = new GsonBuilder()%0A            .registerTypeAdapterFactory(typeHandlerAdapterFactory)%0A            .create();%0A%0A    /**%0A     * %7B@link GsonTypeHandlerAdapter#read(JsonReader)%7D is tested by deserializing an object from JSON%0A     * via Gson with a registered %7B@link GsonTypeHandlerAdapterFactory%7D which creates instances of%0A     * %7B@link GsonTypeHandlerAdapter%7D.%0A     */%0A    @Test%0A    public void testRead() %7B%0A        // Deserialize object with color as JSON array%0A        TestClass deserializedObject = gson.fromJson(OBJECT_JSON_ARRAY, TestClass.class);%0A%0A        Assert.assertEquals(OBJECT, deserializedObject);%0A%0A        // Deserialize object with color as hex string%0A        deserializedObject = gson.fromJson(OBJECT_JSON_HEX, TestClass.class);%0A%0A        Assert.assertEquals(OBJECT, deserializedObject);%0A    %7D%0A%0A    /**%0A     * %7B@link GsonTypeHandlerAdapter#write(JsonWriter, Object)%7D is tested by serializing an object to JSON%0A     * via Gson with a registered %7B@link GsonTypeHandlerAdapterFactory%7D which creates instances of%0A     * %7B@link GsonTypeHandlerAdapter%7D.%0A     */%0A    @Test%0A    public void testWrite() %7B%0A        String serializedObject = gson.toJson(OBJECT);%0A%0A        Assert.assertEquals(OBJECT_JSON_ARRAY, serializedObject);%0A    %7D%0A%0A    private static class TestClass %7B%0A        private final Color color;%0A        private final int i;%0A%0A        private TestClass(Color color, int i) %7B%0A            this.color = color;%0A            this.i = i;%0A        %7D%0A%0A        @Override%0A        public boolean equals(Object o) %7B%0A            if (this == o) return true;%0A            if (o == null %7C%7C getClass() != o.getClass()) return false;%0A            TestClass testClass = (TestClass) o;%0A            return i == testClass.i &&%0A                    Objects.equals(color, testClass.color);%0A        %7D%0A    %7D%0A%7D%0A

Add tests for GsonTypeHandlerAdapter