Skip to content

Commit

Permalink
Add tests for detectOptional and detectWithOptional to unit test suite.
Browse files Browse the repository at this point in the history
Signed-off-by: Donald Raab <Donald.Raab@gs.com>
  • Loading branch information
Donald Raab authored and Donald Raab committed Jan 9, 2017
1 parent 36f9d17 commit afbfbf6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ public void detect()
Assert.assertNull(this.newWith(1, 2, 3, 4, 5).detect(Integer.valueOf(6)::equals));
}

@Test
public void detectOptional()
{
Assert.assertEquals(Integer.valueOf(3), this.newWith(1, 2, 3, 4, 5).detectOptional(Integer.valueOf(3)::equals).get());
Assert.assertNotNull(this.newWith(1, 2, 3, 4, 5).detectOptional(Integer.valueOf(6)::equals));
Verify.assertThrows(NoSuchElementException.class, () -> this.newWith(1, 2, 3, 4, 5).detectOptional(Integer.valueOf(6)::equals).get());
}

@Test(expected = NoSuchElementException.class)
public void min_empty_throws()
{
Expand Down Expand Up @@ -645,6 +653,14 @@ public void detectWith()
Assert.assertNull(this.newWith(1, 2, 3, 4, 5).detectWith(Object::equals, 6));
}

@Test
public void detectWithOptional()
{
Assert.assertEquals(Integer.valueOf(3), this.newWith(1, 2, 3, 4, 5).detectWithOptional(Object::equals, 3).get());
Assert.assertNotNull(this.newWith(1, 2, 3, 4, 5).detectWithOptional(Object::equals, 6));
Verify.assertThrows(NoSuchElementException.class, () -> this.newWith(1, 2, 3, 4, 5).detectWithOptional(Object::equals, 6).get());
}

@Test
public void detectIfNone()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;

import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.bag.ImmutableBag;
Expand Down Expand Up @@ -399,6 +400,15 @@ public void detect()
Assert.assertNull(this.newBag().detect(ignored -> false));
}

@Override
@Test
public void detectOptional()
{
Assert.assertEquals("1", this.newBag().detectOptional("1"::equals).get());
Assert.assertNotNull(this.newBag().detectOptional("2"::equals));
Verify.assertThrows(NoSuchElementException.class, () -> this.newBag().detectOptional("2"::equals).get());
}

@Override
@Test
public void detectWith()
Expand All @@ -408,6 +418,15 @@ public void detectWith()
Assert.assertEquals(VAL, this.newBag().detectWith(Object::equals, "1"));
}

@Override
@Test
public void detectWithOptional()
{
Assert.assertEquals("1", this.newBag().detectWithOptional(Object::equals, "1").get());
Assert.assertNotNull(this.newBag().detectWithOptional(Object::equals, "2"));
Verify.assertThrows(NoSuchElementException.class, () -> this.newBag().detectWithOptional(Object::equals, "2").get());
}

@Override
@Test
public void detectWithIfNone()
Expand Down

0 comments on commit afbfbf6

Please sign in to comment.