Skip to content

Commit

Permalink
Minor code cleanup. Upgraded to JSON-LD 0.11.1 (test dependency).
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Jan 11, 2018
1 parent 5f937a5 commit bfd1dd3
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<junit.version>4.12</junit.version>
<org.mockito.version>1.10.19</org.mockito.version>
<com.github.jsonld-java.version>0.8.3</com.github.jsonld-java.version>
<com.github.jsonld-java.version>0.11.1</com.github.jsonld-java.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,14 @@ public static boolean hasPropertiesField(Class<?> cls) {
* @throws IllegalArgumentException When the specified class does not have a {@link Properties} field
*/
public static Field getPropertiesField(Class<?> cls) {
// TODO Rewrite this to return optional?
final List<Field> fields = getSerializableFields(cls);
final Optional<Field> propsField = fields.stream().filter(BeanAnnotationProcessor::isPropertiesField).findAny();
if (propsField.isPresent()) {
return propsField.get();
}
throw new IllegalArgumentException(cls + " does not have a @Properties field.");
return propsField.orElseThrow(() -> new IllegalArgumentException(cls + " does not have a @Properties field."));
}

/**
* Extracts types field from the specified class or any of its ancestors.
*
* <p>
* This method assumes there is at most one types field in the class hierarchy.
*
* @param cls The class to scan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public boolean equals(Object o) {

TransformationRuleIdentifier<?, ?> that = (TransformationRuleIdentifier<?, ?>) o;

if (!sourceType.equals(that.sourceType)) return false;
return targetType.equals(that.targetType);
return sourceType.equals(that.sourceType) && targetType.equals(that.targetType);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ public boolean equals(Object o) {

LiteralNode<?> that = (LiteralNode<?>) o;

if (getName() != null && !getName().equals(that.getName()) || getName() == null && that.getName() != null) {
return false;
}
return value.equals(that.value);
return (getName() == null || getName().equals(that.getName())) &&
(getName() != null || that.getName() == null) && value.equals(that.value);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ public void getAttributeIdentifierThrowsIllegalArgumentWhenFieldIsNotJsonLdSeria
}

@Test
public void getInstanceIdentifierExtractsIdFieldValue() throws Exception {
public void getInstanceIdentifierExtractsIdFieldValue() {
final Organization org = Generator.generateOrganization();
assertEquals(org.getUri(), BeanAnnotationProcessor.getInstanceIdentifier(org));
}

@Test
public void getInstanceIdentifierExtractsIdFieldFromAncestorClass() throws Exception {
public void getInstanceIdentifierExtractsIdFieldFromAncestorClass() {
final Employee e = Generator.generateEmployee();
assertEquals(e.getUri(), BeanAnnotationProcessor.getInstanceIdentifier(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void closeObjectDoesNothingForRootObject() throws Exception {
}

@Test
public void addValueAddsValuesToCurrentlyOpenCollection() throws Exception {
public void addValueAddsValuesToCurrentlyOpenCollection() {
final List<Integer> items = new ArrayList<>();
for (int i = 0; i < Generator.randomCount(10); i++) {
items.add(Generator.randomCount(Integer.MAX_VALUE));
Expand All @@ -132,7 +132,7 @@ public void addValueAddsValuesToCurrentlyOpenCollection() throws Exception {
}

@Test
public void openObjectByPropertyCreatesObjectOfCorrectType() throws Exception {
public void openObjectByPropertyCreatesObjectOfCorrectType() {
deserializer.openObject(Employee.class);
deserializer.openObject(Vocabulary.IS_MEMBER_OF);
assertTrue(deserializer.getCurrentRoot() instanceof Organization);
Expand All @@ -149,7 +149,7 @@ public void openObjectByPropertySetsNewInstanceAsFieldValueAndReplacesCurrentCon
}

@Test
public void addValueSetsPropertyValue() throws Exception {
public void addValueSetsPropertyValue() {
deserializer.openObject(User.class);
final String firstName = "Catherine";
final String lastName = "Halsey";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void addItemInsertsValuesOfCorrectTypes() throws Exception {
}

@Test
public void addItemConvertsValuesToCorrectType() throws Exception {
public void addItemConvertsValuesToCorrectType() {
final Map<String, Set<String>> map = new HashMap<>();
final InstanceContext<Map> ctx = new PropertiesInstanceContext(map, Vocabulary.IS_ADMIN, personProperties);
ctx.addItem(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void closeInstancePopsOriginalCurrentFromStack() throws Exception {
}

@Test
public void openCollectionCreatesCollectionNode() throws Exception {
public void openCollectionCreatesCollectionNode() {
treeBuilder.openCollection(Collections.singleton(Generator.generateEmployee()));
final CompositeNode root = treeBuilder.getTreeRoot();
assertNotNull(root);
Expand Down Expand Up @@ -288,7 +288,7 @@ public void testAddCollectionItemAfterVisitKnownInstanceWasCalledInObject() thro
}

@Test
public void testBuildTreeWithRootCollection() throws Exception {
public void testBuildTreeWithRootCollection() {
final Set<User> users = Generator.generateUsers();
treeBuilder.openCollection(users);
for (User u : users) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void traverseTraversesObjectReferences() throws Exception {
}

@Test
public void traverseTraversesObjectPropertyCollection() throws Exception {
public void traverseTraversesObjectPropertyCollection() {
final Organization org = Generator.generateOrganization();
generateEmployees(org);
traverser.traverse(org);
Expand Down Expand Up @@ -126,7 +126,7 @@ public void traverseRecognizesAlreadyVisitedInstances() throws Exception {
}

@Test
public void traverseOnCollectionOpensCollectionAddsInstancesAndClosesCollection() throws Exception {
public void traverseOnCollectionOpensCollectionAddsInstancesAndClosesCollection() {
final Set<User> users = Generator.generateUsers();
traverser.traverse(users);

Expand Down

0 comments on commit bfd1dd3

Please sign in to comment.