Skip to content

Commit

Permalink
[WIP] Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksclarke committed Jul 7, 2024
1 parent be2d3dd commit 8ab11bb
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Point previous() {
throw new NoSuchElementException();
}

return myPoints[myIndex--];
return myPoints[--myIndex];
}

@Override
Expand Down Expand Up @@ -176,6 +176,6 @@ public String toString() {
stream().forEach(point -> builder.append(point.toString()).append(", "));
length = builder.length();

return builder.delete(length - 2, length - 1).append(']').toString();
return builder.delete(length - 2, length).append(']').toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public LineString previous() {
throw new NoSuchElementException();
}

return myLineStrings[myIndex--];
return myLineStrings[--myIndex];
}

@Override
Expand Down Expand Up @@ -147,13 +147,13 @@ public Stream<LineString> stream() {
* @return A 3D array representation of a <code>MultiLineString</code>
*/
public double[][][] toArray() {
final int total = stream().mapToInt(LineString::length).sum();
final double[][][] matrix = new double[size()][total][2];
final int countTotal = stream().mapToInt(LineString::length).sum() / size();
final double[][][] matrix = new double[size()][countTotal][2];

for (int index = 0; index < size(); index++) {
final LineString lineString = get(index);

for (int count = 0; count < total; count++) {
for (int count = 0; count < countTotal; count++) {
matrix[index][count][0] = lineString.getX(count);
matrix[index][count][1] = lineString.getY(count);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Point previous() {
throw new NoSuchElementException();
}

return myPoints[myIndex--];
return myPoints[--myIndex];
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

package info.freelibrary.iiif.presentation.v3.exts.geo;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;

import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonGetter;
Expand All @@ -10,13 +12,14 @@
import info.freelibrary.util.Logger;
import info.freelibrary.util.LoggerFactory;

import info.freelibrary.iiif.presentation.v3.ids.UriUtils;
import info.freelibrary.iiif.presentation.v3.utils.JsonKeys;
import info.freelibrary.iiif.presentation.v3.utils.MessageCodes;

/**
* A spatially bounded thing.
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonInclude(NON_EMPTY)
public class NavPlaceFeature {

/** The NavPlaceFeature's logger. */
Expand Down Expand Up @@ -47,7 +50,7 @@ public NavPlaceFeature() {
* @param aID A feature ID
*/
public NavPlaceFeature(final String aID) {
myID = aID;
myID = UriUtils.checkID(aID, true);
}

/**
Expand Down Expand Up @@ -76,8 +79,8 @@ public Geometry getGeometry() {
* @return The navPlace feature ID
*/
@JsonGetter(JsonKeys.ID)
public String getID() {
return myID;
public Optional<String> getID() {
return Optional.ofNullable(myID);
}

/**
Expand Down Expand Up @@ -160,7 +163,7 @@ public NavPlaceFeature setProperties(final Properties aProperties) {
@JsonSetter(JsonKeys.TYPE)
private void setType(final String aType) {
if (!JsonKeys.FEATURE.equals(aType)) {
throw new IllegalArgumentException(LOGGER.getMessage("{} is not a valid navPlace type", aType));
throw new IllegalArgumentException(LOGGER.getMessage(MessageCodes.JPA_146, aType));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import info.freelibrary.util.warnings.PMD;

import info.freelibrary.iiif.presentation.v3.properties.Property;
import info.freelibrary.iiif.presentation.v3.utils.json.PropertiesDeserializer;
import info.freelibrary.iiif.presentation.v3.utils.json.PropertiesSerializer;
import info.freelibrary.util.warnings.PMD;

/**
* A wrapper for I18n properties.
Expand Down Expand Up @@ -87,7 +88,11 @@ public boolean containsAll(final Collection<Property> aCollection) {

@Override
public boolean equals(final Object aObject) {
return aObject instanceof Properties && myProperties.equals(aObject);
if (aObject instanceof final Properties properties) {
return myProperties.equals(properties.myProperties);
}

return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/iiif_presentation_messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<entry key="JPA-144">The supplementWith() method cannot be usd if the canvas doesn't have a minter set </entry>
<entry key="JPA-145">Internationalizations must be submitted in an array that alternates between language codes and
string values</entry>
<entry key="JPA-146"></entry>
<entry key="JPA-146">{} is not a valid navPlace type</entry>
<entry key="JPA-147"></entry>
<entry key="JPA-148"></entry>
</properties>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package info.freelibrary.iiif.presentation.v3.annotations;

import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.getRandom;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import info.freelibrary.iiif.presentation.v3.Annotation;
import info.freelibrary.iiif.presentation.v3.Canvas;
import info.freelibrary.iiif.presentation.v3.CanvasResource;
import info.freelibrary.iiif.presentation.v3.Manifest;
Expand Down Expand Up @@ -128,9 +130,11 @@ public final void testSetMotivationMotivation() {
/**
* Test method for {@link BookmarkingAnnotation#setMotivation(Motivation)}.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public final void testSetMotivationMotivationBad() {
assertTrue(new AssessingAnnotation(myMinter).setMotivation(Motivation.fromLabel(Purpose.BOOKMARKING)).getID()
.startsWith(ID_PATTERN));
final Annotation<WebAnnotation> anno = new AssessingAnnotation(myMinter);
final Motivation motivation = Motivation.fromLabel(Purpose.BOOKMARKING);

assertThrows(IllegalArgumentException.class, () -> anno.setMotivation(motivation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package info.freelibrary.iiif.presentation.v3.annotations;

import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.getRandom;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import info.freelibrary.iiif.presentation.v3.Annotation;
import info.freelibrary.iiif.presentation.v3.Canvas;
import info.freelibrary.iiif.presentation.v3.CanvasResource;
import info.freelibrary.iiif.presentation.v3.Manifest;
Expand Down Expand Up @@ -130,9 +132,11 @@ public final void testSetMotivationMotivation() {
/**
* Test method for {@link BookmarkingAnnotation#setMotivation(Motivation)}.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public final void testSetMotivationMotivationBad() {
assertTrue(new BookmarkingAnnotation(myMinter).setMotivation(Motivation.fromLabel(Purpose.ASSESSING)).getID()
.startsWith(ID_PATTERN));
final Annotation<WebAnnotation> anno = new BookmarkingAnnotation(myMinter);
final Motivation motivation = Motivation.fromLabel(Purpose.ASSESSING);

assertThrows(IllegalArgumentException.class, () -> anno.setMotivation(motivation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package info.freelibrary.iiif.presentation.v3.annotations;

import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.getRandom;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import info.freelibrary.iiif.presentation.v3.Annotation;
import info.freelibrary.iiif.presentation.v3.Canvas;
import info.freelibrary.iiif.presentation.v3.CanvasResource;
import info.freelibrary.iiif.presentation.v3.Manifest;
Expand Down Expand Up @@ -130,9 +132,11 @@ public final void testSetMotivationMotivation() {
/**
* Test method for {@link ClassifyingAnnotation#setMotivation(Motivation)}.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public final void testSetMotivationMotivationBad() {
assertTrue(new ClassifyingAnnotation(myMinter).setMotivation(Motivation.fromLabel(Purpose.ASSESSING)).getID()
.startsWith(ID_PATTERN));
final Annotation<WebAnnotation> anno = new ClassifyingAnnotation(myMinter);
final Motivation motivation = Motivation.fromLabel(Purpose.ASSESSING);

assertThrows(IllegalArgumentException.class, () -> anno.setMotivation(motivation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package info.freelibrary.iiif.presentation.v3.annotations;

import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.getRandom;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import info.freelibrary.iiif.presentation.v3.Annotation;
import info.freelibrary.iiif.presentation.v3.Canvas;
import info.freelibrary.iiif.presentation.v3.CanvasResource;
import info.freelibrary.iiif.presentation.v3.Manifest;
Expand Down Expand Up @@ -128,9 +130,11 @@ public final void testSetMotivationMotivation() {
/**
* Test method for {@link CommentingAnnotation#setMotivation(Motivation)}.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public final void testSetMotivationMotivationBad() {
assertTrue(new CommentingAnnotation(myMinter).setMotivation(Motivation.fromLabel(Purpose.ASSESSING)).getID()
.startsWith(ID_PATTERN));
final Annotation<WebAnnotation> anno = new CommentingAnnotation(myMinter);
final Motivation motivation = Motivation.fromLabel(Purpose.ASSESSING);

assertThrows(IllegalArgumentException.class, () -> anno.setMotivation(motivation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package info.freelibrary.iiif.presentation.v3.annotations;

import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.getRandom;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import info.freelibrary.iiif.presentation.v3.Annotation;
import info.freelibrary.iiif.presentation.v3.Canvas;
import info.freelibrary.iiif.presentation.v3.CanvasResource;
import info.freelibrary.iiif.presentation.v3.Manifest;
Expand Down Expand Up @@ -128,9 +130,11 @@ public final void testSetMotivationMotivation() {
/**
* Test method for {@link DescribingAnnotation#setMotivation(Motivation)}.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public final void testSetMotivationMotivationBad() {
assertTrue(new DescribingAnnotation(myMinter).setMotivation(Motivation.fromLabel(Purpose.ASSESSING)).getID()
.startsWith(ID_PATTERN));
final Annotation<WebAnnotation> anno = new DescribingAnnotation(myMinter);
final Motivation motivation = Motivation.fromLabel(Purpose.ASSESSING);

assertThrows(IllegalArgumentException.class, () -> anno.setMotivation(motivation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package info.freelibrary.iiif.presentation.v3.annotations;

import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.getRandom;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import info.freelibrary.iiif.presentation.v3.Annotation;
import info.freelibrary.iiif.presentation.v3.Canvas;
import info.freelibrary.iiif.presentation.v3.CanvasResource;
import info.freelibrary.iiif.presentation.v3.Manifest;
Expand Down Expand Up @@ -128,9 +130,11 @@ public final void testSetMotivationMotivation() {
/**
* Test method for {@link EditingAnnotation#setMotivation(Motivation)}.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public final void testSetMotivationMotivationBad() {
assertTrue(new EditingAnnotation(myMinter).setMotivation(Motivation.fromLabel(Purpose.ASSESSING)).getID()
.startsWith(ID_PATTERN));
final Annotation<WebAnnotation> anno = new EditingAnnotation(myMinter);
final Motivation motivation = Motivation.fromLabel(Purpose.ASSESSING);

assertThrows(IllegalArgumentException.class, () -> anno.setMotivation(motivation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package info.freelibrary.iiif.presentation.v3.annotations;

import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.getRandom;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import info.freelibrary.iiif.presentation.v3.Annotation;
import info.freelibrary.iiif.presentation.v3.Canvas;
import info.freelibrary.iiif.presentation.v3.CanvasResource;
import info.freelibrary.iiif.presentation.v3.Manifest;
Expand Down Expand Up @@ -130,9 +132,11 @@ public final void testSetMotivationMotivation() {
/**
* Test method for {@link HighlightingAnnotation#setMotivation(Motivation)}.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public final void testSetMotivationMotivationBad() {
assertTrue(new HighlightingAnnotation(myMinter).setMotivation(Motivation.fromLabel(Purpose.ASSESSING)).getID()
.startsWith(ID_PATTERN));
final Annotation<WebAnnotation> anno = new HighlightingAnnotation(myMinter);
final Motivation motivation = Motivation.fromLabel(Purpose.ASSESSING);

assertThrows(IllegalArgumentException.class, () -> anno.setMotivation(motivation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package info.freelibrary.iiif.presentation.v3.annotations;

import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.getRandom;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import info.freelibrary.iiif.presentation.v3.Annotation;
import info.freelibrary.iiif.presentation.v3.Canvas;
import info.freelibrary.iiif.presentation.v3.CanvasResource;
import info.freelibrary.iiif.presentation.v3.Manifest;
Expand Down Expand Up @@ -130,9 +132,11 @@ public final void testSetMotivationMotivation() {
/**
* Test method for {@link IdentifyingAnnotation#setMotivation(Motivation)}.
*/
@Test(expected = IllegalArgumentException.class)
@Test
public final void testSetMotivationMotivationBad() {
assertTrue(new IdentifyingAnnotation(myMinter).setMotivation(Motivation.fromLabel(Purpose.ASSESSING)).getID()
.startsWith(ID_PATTERN));
final Annotation<WebAnnotation> anno = new IdentifyingAnnotation(myMinter);
final Motivation motivation = Motivation.fromLabel(Purpose.ASSESSING);

assertThrows(IllegalArgumentException.class, () -> anno.setMotivation(motivation));
}
}
Loading

0 comments on commit 8ab11bb

Please sign in to comment.