Skip to content

Commit

Permalink
Add more ContextList tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksclarke committed Sep 4, 2024
1 parent 2f75222 commit 991e70f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ public URI set(final int aIndex, final URI aURI) {
if (PRESENTATION_CONTEXT_URI.equals(aURI)) {
if (aIndex != 0) {
throw new IndexOutOfBoundsException(LOGGER.getMessage(MessageCodes.JPA_149));
} // else, just ignore -- this should be the current index of the default context
} else if (aIndex != 0) {
}

return aURI;
}
if (aIndex != 0) {
return super.set(aIndex, aURI);
}

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

package info.freelibrary.iiif.presentation.v3;

import static info.freelibrary.iiif.presentation.v3.ContextList.PRESENTATION_CONTEXT_URI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
Expand All @@ -15,6 +16,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -337,6 +339,18 @@ public final void testRemoveIfPredicateOfQsuperURI() {
assertTrue(contexts.contains(kept));
}

/**
* Test method for {@link ContextList#removeIf(Predicate)}.
*/
@Test
public final void testRemoveIfPredicateOfQsuperUriNoDefault() {
final ContextList contexts = new ContextList(myContexts);

contexts.removeIf(uri -> !uri.equals(PRESENTATION_CONTEXT_URI));
assertEquals(1, contexts.size());
assertTrue(contexts.contains(PRESENTATION_CONTEXT_URI));
}

/**
* Test method for {@link ContextList#remove(int)}.
*/
Expand Down Expand Up @@ -365,6 +379,14 @@ public final void testRemoveLast() {
assertFalse(contexts.contains(uri));
}

/**
* Test method for {@link ContextList#removeLast()}.
*/
@Test(expected = NoSuchElementException.class)
public final void testRemoveLastWhenEmpty() {
new ContextList().removeLast();
}

/**
* Test method for {@link ContextList#remove(Object)}.
*/
Expand Down Expand Up @@ -427,6 +449,30 @@ public final void testSetIntURI() {
assertEquals(uri, contexts.get(1));
}

/**
* Test method for {@link ContextList#set(int, URI)}.
*/
@Test(expected = IndexOutOfBoundsException.class)
public final void testSetIntURIException() {
new ContextList(myContexts).set(1, PRESENTATION_CONTEXT_URI);
}

/**
* Test method for {@link ContextList#set(int, URI)}.
*/
@Test(expected = IndexOutOfBoundsException.class)
public final void testSetIntURIException2() {
new ContextList(myContexts).set(0, URI.create(getURL()));
}

/**
* Test method for {@link ContextList#set(int, URI)}.
*/
@Test
public final void testSetIntUriStatusQuo() {
new ContextList(myContexts).set(0, PRESENTATION_CONTEXT_URI);
}

/**
* Test method for {@link ContextList#sort(Comparator)}.
*/
Expand Down

0 comments on commit 991e70f

Please sign in to comment.