JsonApiResource extends JsonApiResourceIdentifier implements JsonLinks, JsonApiData { @Override public boolean hasRelationshipTo(JsonApiIdentifiable related) { return relationships.entrySet().stream() .anyMatch(r -> r.getValue().containsEntity(related)); } JsonApiResource(JsonApiIdentifiable entity, URI uri); @JsonIgnoreProperties(value = {"id", "type"}) @JsonProperty("attributes") Object getEntity(); @JsonInclude(JsonInclude.Include.NON_EMPTY) Map<String, JsonApiRelationship> getRelationships(); @Override Map<String, URI> getLinks(); @Override void addLink(String name, URI ref); @Override URI getURI(); @Override boolean hasRelationshipTo(JsonApiIdentifiable related); @Override void setResourceCollectionURI(URI collectionURI); @Override JsonApiResource asSingleResource(); @Override JsonApiResourceCollection asResourceCollection(); @Override URI getRelationshipUri(JsonApiIdentifiable related); @Override JsonApiResource addRelationship(String name, JsonApiIdentifiable related, URI location); @Override JsonApiResource addRelationship(String name, Collection<? extends JsonApiIdentifiable> relatedCollection, URI location); @Override JsonApiResource restrictTo(String attribute); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testHasRelationshipTo() { JsonApiResource result = new JsonApiResource(dummyObj, uri); result.addRelationship("dummy02", dummy02, uri); result.addRelationship("anotherDummyClass", anotherDummyClass, uri); Assert.assertTrue(result.hasRelationshipTo(dummy02)); Assert.assertTrue(result.hasRelationshipTo(anotherDummyClass)); Assert.assertFalse(result.hasRelationshipTo(dummy03)); }