Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DFGMETA-69]: Nullpointer fix in Manifestation.toString() for real … #185

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Fixed

- Fixed Nullpointer in `Manifestation.toString()`
morpheus-87 marked this conversation as resolved.
Show resolved Hide resolved

## [9.3.2](https://github.com/dbmdz/metadata-service/releases/tag/9.3.2) - 2024-08-09

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,12 @@ public int hashCode() {
* @param relations a list of EntityRelations
* @return A texual representation of the list with subject uuid, predicate and object uuid
*/
private String dumpShortenedRelations(List<EntityRelation> relations) {
protected static String dumpShortenedRelations(List<EntityRelation> relations) {
return "["
+ (relations == null
? "null"
: relations.stream()
.filter(Objects::nonNull)
clorenz marked this conversation as resolved.
Show resolved Hide resolved
.map(EntityRelation::toShortenedString)
.collect(Collectors.joining(",")))
+ "]";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.digitalcollections.model.identifiable.entity.manifestation;

import static org.assertj.core.api.Assertions.assertThat;

import de.digitalcollections.model.identifiable.entity.agent.Person;
import de.digitalcollections.model.identifiable.entity.relation.EntityRelation;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("The Manifestation")
class ManifestationTest {

@DisplayName("only dumps uuids of relations in toString to avoid recursion")
@Test
public void testToString() {
Person author = Person.builder().uuid(UUID.randomUUID()).build();
Manifestation manifestation = Manifestation.builder().uuid(UUID.randomUUID()).build();
EntityRelation entityRelation =
EntityRelation.builder().subject(author).predicate("foo").object(manifestation).build();
manifestation.setRelations(List.of(entityRelation));

String actual = manifestation.toString();

String expected =
"Manifestation{composition='null', dimensions='null', expressionTypes=[], relations=[EntityRelation{subject="
+ author.getUuid()
+ ", predicate='foo', object="
+ manifestation.getUuid()
+ "}], language=null, manifestationType=null, manufacturingType=null, mediaTypes=[], otherLanguages=[], parents=[], publicationInfo=null, distributionInfo=null, productionInfo=null, scale='null', subjects=[], "
+ "titles=[], version='null', work=null, customAttributes=null, navDate=null, refId=0, notes=[], description=null, identifiableObjectType=MANIFESTATION, identifiers=[], label=null, localizedUrlAliases=null, previewImage=null, previewImageRenderingHints=null, tags=[], type=ENTITY, created=null, lastModified=null, uuid="
+ manifestation.getUuid()
+ "}";
assertThat(actual).isEqualTo(expected);
}

@DisplayName("can dump shortened Strings for weird manifestations")
@Test
public void shortenedStringsForWeirdManifestations() {
List<EntityRelation> relations = new ArrayList<>();
relations.add(null); // yes, that's an actual real-world example!
String actual = Manifestation.dumpShortenedRelations(relations);
assertThat(actual).isEqualTo("[]");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.digitalcollections.model.jackson.identifiable.entity.manifestation;

import static org.assertj.core.api.Assertions.assertThat;

import de.digitalcollections.model.RelationSpecification;
import de.digitalcollections.model.identifiable.Identifier;
import de.digitalcollections.model.identifiable.entity.agent.Person;
Expand Down Expand Up @@ -201,27 +199,4 @@ public void testSerializeDeserialize() throws Exception {
manifestation,
"serializedTestObjects/identifiable/entity/manifestation/Manifestation.json");
}

@DisplayName("only dumps uuids of relations in toString to avoid recursion")
@Test
public void testToString() {
Person author = Person.builder().uuid(UUID.randomUUID()).build();
Manifestation manifestation = Manifestation.builder().uuid(UUID.randomUUID()).build();
EntityRelation entityRelation =
EntityRelation.builder().subject(author).predicate("foo").object(manifestation).build();
manifestation.setRelations(List.of(entityRelation));

String actual = manifestation.toString();

String expected =
"Manifestation{composition='null', dimensions='null', expressionTypes=[], relations=[EntityRelation{subject="
+ author.getUuid()
+ ", predicate='foo', object="
+ manifestation.getUuid()
+ "}], language=null, manifestationType=null, manufacturingType=null, mediaTypes=[], otherLanguages=[], parents=[], publicationInfo=null, distributionInfo=null, productionInfo=null, scale='null', subjects=[], "
+ "titles=[], version='null', work=null, customAttributes=null, navDate=null, refId=0, notes=[], description=null, identifiableObjectType=MANIFESTATION, identifiers=[], label=null, localizedUrlAliases=null, previewImage=null, previewImageRenderingHints=null, tags=[], type=ENTITY, created=null, lastModified=null, uuid="
+ manifestation.getUuid()
+ "}";
assertThat(actual).isEqualTo(expected);
}
}
Loading