Skip to content

Commit

Permalink
Small tweaks to use Guava predicates instead of homebrew
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 22, 2013
1 parent 9977b4d commit d42d998
Showing 1 changed file with 15 additions and 18 deletions.
Expand Up @@ -16,12 +16,12 @@

package org.fcrepo.kernel.observer;

import static com.google.common.base.Predicates.alwaysFalse;
import static com.google.common.base.Predicates.alwaysTrue;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraDatastream;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraObject;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

Expand Down Expand Up @@ -52,9 +52,6 @@ public class DefaultFilterTest {
@Mock
private Repository mockRepo;

@Mock
private Predicate<Node> mockFuncTrue, mockFuncFalse;

@Mock
private Event mockEvent;

Expand All @@ -69,8 +66,6 @@ public class DefaultFilterTest {
@Before
public void setUp() throws Exception {
initMocks(this);
when(mockFuncTrue.apply(any(Node.class))).thenReturn(true);
when(mockFuncFalse.apply(any(Node.class))).thenReturn(false);
when(mockEvent.getPath()).thenReturn(testPath);
when(mockNode.isNode()).thenReturn(true);
testObj = new DefaultFilter();
Expand All @@ -92,8 +87,8 @@ public void shouldApplyToObject() throws Exception {
final Predicate<Node> holdDS = isFedoraDatastream;
final Predicate<Node> holdO = isFedoraObject;
try {
isFedoraDatastream = mockFuncFalse;
isFedoraObject = mockFuncTrue;
isFedoraDatastream = alwaysFalse();
isFedoraObject = alwaysTrue();
assertTrue(testObj.apply(mockEvent));
} finally {
isFedoraDatastream = holdDS;
Expand All @@ -107,8 +102,8 @@ public void shouldApplyToDatastream() throws Exception {
final Predicate<Node> holdDS = isFedoraDatastream;
final Predicate<Node> holdO = isFedoraObject;
try {
isFedoraDatastream = mockFuncTrue;
isFedoraObject = mockFuncFalse;
isFedoraDatastream = alwaysTrue();
isFedoraObject = alwaysFalse();
assertTrue(testObj.apply(mockEvent));
} finally {
isFedoraDatastream = holdDS;
Expand All @@ -118,8 +113,8 @@ public void shouldApplyToDatastream() throws Exception {

@Test
public void shouldNotApplyToNonExistentNodes() throws Exception {
doThrow(PathNotFoundException.class).when(mockSession)
.getItem(testPath);
when(mockSession.getItem(testPath)).thenThrow(
new PathNotFoundException("Expected."));
assertEquals(false, testObj.apply(mockEvent));
}

Expand All @@ -129,8 +124,8 @@ public void shouldNotApplyToNonFedoraNodes() throws Exception {
final Predicate<Node> holdDS = isFedoraDatastream;
final Predicate<Node> holdO = isFedoraObject;
try {
isFedoraDatastream = mockFuncFalse;
isFedoraObject = mockFuncFalse;
isFedoraDatastream = alwaysFalse();
isFedoraObject = alwaysFalse();
assertEquals(false, testObj.apply(mockEvent));
} finally {
isFedoraDatastream = holdDS;
Expand All @@ -141,7 +136,9 @@ public void shouldNotApplyToNonFedoraNodes() throws Exception {
@Test(expected = RuntimeException.class)
public void testBadItem() throws RepositoryException {
when(mockSession.getItem(testPath)).thenReturn(mockProperty);
doThrow(RepositoryException.class).when(mockProperty).getParent();
when(mockProperty.isNode()).thenReturn(false);
when(mockProperty.getParent()).thenThrow(
new RepositoryException("Expected."));
testObj.apply(mockEvent);
}

Expand All @@ -153,8 +150,8 @@ public void testProperty() throws RepositoryException {
final Predicate<Node> holdDS = isFedoraDatastream;
final Predicate<Node> holdO = isFedoraObject;
try {
isFedoraDatastream = mockFuncFalse;
isFedoraObject = mockFuncTrue;
isFedoraDatastream = alwaysFalse();
isFedoraObject = alwaysTrue();
assertEquals(true, testObj.apply(mockEvent));
} finally {
isFedoraDatastream = holdDS;
Expand Down

0 comments on commit d42d998

Please sign in to comment.