From 272080230a268ac4cd46a54f846093fa8fc62585 Mon Sep 17 00:00:00 2001 From: Martin Ledvinka Date: Sun, 19 Jul 2020 13:47:57 +0200 Subject: [PATCH] Minor code improvements. --- README.md | 3 +-- .../cvut/kbss/jsonld/common/BeanClassProcessor.java | 11 ++++++----- .../common/JsonLdPropertyAccessResolverTest.java | 2 +- .../deserialization/NodeReferenceContextTest.java | 2 +- .../serialization/PropertiesFieldSerializerTest.java | 4 ++-- .../jsonld/serialization/model/AbstractNodeTest.java | 2 +- .../traversal/ObjectGraphTraverserTest.java | 2 +- .../serialization/util/BufferedJsonGenerator.java | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ba92a83..71dab0a 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ Java Binding for JSON-LD (JB4JSON-LD) is a simple library for serialization of Java objects into JSON-LD and vice versa. -Note that this is the core, abstract implementation. For actual usage, a binding like -[https://github.com/kbss-cvut/jb4jsonld-jackson](https://github.com/kbss-cvut/jb4jsonld-jackson) +Note that this is the core, abstract implementation. For actual usage, a binding like [https://github.com/kbss-cvut/jb4jsonld-jackson](https://github.com/kbss-cvut/jb4jsonld-jackson) has to be used. More information can be found at [https://kbss.felk.cvut.cz/web/kbss/jb4json-ld](https://kbss.felk.cvut.cz/web/kbss/jb4json-ld). diff --git a/src/main/java/cz/cvut/kbss/jsonld/common/BeanClassProcessor.java b/src/main/java/cz/cvut/kbss/jsonld/common/BeanClassProcessor.java index 172f45a..60de90e 100644 --- a/src/main/java/cz/cvut/kbss/jsonld/common/BeanClassProcessor.java +++ b/src/main/java/cz/cvut/kbss/jsonld/common/BeanClassProcessor.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2020 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any * later version. - * + *

* This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more @@ -18,6 +18,7 @@ import cz.cvut.kbss.jsonld.exception.TargetTypeException; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.net.URI; @@ -77,8 +78,8 @@ public static void setFieldValue(Field field, Object instance, Object value) { */ public static T createInstance(Class cls) { try { - return cls.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return cls.getDeclaredConstructor().newInstance(); + } catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) { throw new BeanProcessingException("Class " + cls + " is missing a public no-arg constructor.", e); } } @@ -210,7 +211,7 @@ public static Class getMapGenericValueType(Field field) { final Type actualType = valueType.getActualTypeArguments()[0]; if (Class.class.isAssignableFrom(actualType.getClass())) { // For Map> - return Class.class.cast(actualType); + return (Class) actualType; } // For Map> return null; diff --git a/src/test/java/cz/cvut/kbss/jsonld/common/JsonLdPropertyAccessResolverTest.java b/src/test/java/cz/cvut/kbss/jsonld/common/JsonLdPropertyAccessResolverTest.java index 3ecc14b..dc77541 100644 --- a/src/test/java/cz/cvut/kbss/jsonld/common/JsonLdPropertyAccessResolverTest.java +++ b/src/test/java/cz/cvut/kbss/jsonld/common/JsonLdPropertyAccessResolverTest.java @@ -28,7 +28,7 @@ class JsonLdPropertyAccessResolverTest { - private JsonLdPropertyAccessResolver sut = new JsonLdPropertyAccessResolver(); + private final JsonLdPropertyAccessResolver sut = new JsonLdPropertyAccessResolver(); @ParameterizedTest @CsvSource({ diff --git a/src/test/java/cz/cvut/kbss/jsonld/deserialization/NodeReferenceContextTest.java b/src/test/java/cz/cvut/kbss/jsonld/deserialization/NodeReferenceContextTest.java index 11075af..ebc5285 100644 --- a/src/test/java/cz/cvut/kbss/jsonld/deserialization/NodeReferenceContextTest.java +++ b/src/test/java/cz/cvut/kbss/jsonld/deserialization/NodeReferenceContextTest.java @@ -39,7 +39,7 @@ class NodeReferenceContextTest { @BeforeEach void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @Test diff --git a/src/test/java/cz/cvut/kbss/jsonld/serialization/PropertiesFieldSerializerTest.java b/src/test/java/cz/cvut/kbss/jsonld/serialization/PropertiesFieldSerializerTest.java index 860ff83..08f0168 100644 --- a/src/test/java/cz/cvut/kbss/jsonld/serialization/PropertiesFieldSerializerTest.java +++ b/src/test/java/cz/cvut/kbss/jsonld/serialization/PropertiesFieldSerializerTest.java @@ -30,7 +30,7 @@ class PropertiesFieldSerializerTest { private Field field; - private FieldSerializer serializer = new PropertiesFieldSerializer(); + private final FieldSerializer serializer = new PropertiesFieldSerializer(); @BeforeEach void setUp() throws Exception { @@ -143,4 +143,4 @@ void serializeFieldSerializesTypedPropertiesToCorrectTargetTypes() { } } } -} \ No newline at end of file +} diff --git a/src/test/java/cz/cvut/kbss/jsonld/serialization/model/AbstractNodeTest.java b/src/test/java/cz/cvut/kbss/jsonld/serialization/model/AbstractNodeTest.java index 7f4a48d..180e5e2 100644 --- a/src/test/java/cz/cvut/kbss/jsonld/serialization/model/AbstractNodeTest.java +++ b/src/test/java/cz/cvut/kbss/jsonld/serialization/model/AbstractNodeTest.java @@ -24,6 +24,6 @@ public abstract class AbstractNodeTest { JsonGenerator serializerMock; public void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } } diff --git a/src/test/java/cz/cvut/kbss/jsonld/serialization/traversal/ObjectGraphTraverserTest.java b/src/test/java/cz/cvut/kbss/jsonld/serialization/traversal/ObjectGraphTraverserTest.java index 7f3235c..1937c77 100644 --- a/src/test/java/cz/cvut/kbss/jsonld/serialization/traversal/ObjectGraphTraverserTest.java +++ b/src/test/java/cz/cvut/kbss/jsonld/serialization/traversal/ObjectGraphTraverserTest.java @@ -49,7 +49,7 @@ class ObjectGraphTraverserTest { @BeforeEach void setUp() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); this.traverser = new ObjectGraphTraverser(); traverser.addVisitor(visitor); } diff --git a/src/test/java/cz/cvut/kbss/jsonld/serialization/util/BufferedJsonGenerator.java b/src/test/java/cz/cvut/kbss/jsonld/serialization/util/BufferedJsonGenerator.java index 98ee588..c46d1e3 100644 --- a/src/test/java/cz/cvut/kbss/jsonld/serialization/util/BufferedJsonGenerator.java +++ b/src/test/java/cz/cvut/kbss/jsonld/serialization/util/BufferedJsonGenerator.java @@ -20,7 +20,7 @@ public class BufferedJsonGenerator implements JsonGenerator { - private StringBuilder buffer = new StringBuilder(); + private final StringBuilder buffer = new StringBuilder(); private boolean firstElement = true; private boolean firstAttribute = true;