Skip to content

Commit

Permalink
Minor code cleanup in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 17, 2013
1 parent cd405d9 commit 871d010
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 48 deletions.
Expand Up @@ -70,32 +70,7 @@

public class HierarchyRdfContextTest {

// for mocks see bottom of this class

@Before
public void setUp() throws RepositoryException {
initMocks(this);
when(mockNode.getName()).thenReturn("mockNode");
when(mockNode.getSession()).thenReturn(mockSession);
when(mockGraphSubjects.getContext()).thenReturn(testPage);
when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockParentNode.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockNodeType.getName()).thenReturn("not:root");
when(mockNode.getMixinNodeTypes()).thenReturn(new NodeType[] {});
when(mockNode.getPath()).thenReturn(MOCK_NODE_PATH);
when(mockParentNode.getPath()).thenReturn(MOCK_PARENT_NODE_PATH);
when(mockNode.getParent()).thenReturn(mockParentNode);
when(mockNode.getNodes()).thenReturn(mockNodes);
when(mockParentNode.hasProperties()).thenReturn(false);
when(mockNode.hasProperties()).thenReturn(false);
when(mockGraphSubjects.getGraphSubject(mockNode)).thenReturn(
testSubject);
when(mockGraphSubjects.getGraphSubject(mockParentNode)).thenReturn(
testParentSubject);
when(mockGraphSubjects.getGraphSubject(mockChildNode)).thenReturn(
testChildSubject);
when(mockNodeType.isNodeType("mode:system")).thenReturn(false);
}
// for mocks and setup gear see after tests

@Test
public void testParentTriples() throws RepositoryException, IOException {
Expand All @@ -121,8 +96,8 @@ public void shouldIncludeChildNodeInformation() throws RepositoryException,
when(mockNode.getNodes()).thenReturn(
nodeIterator(mockChildNode, mockChildNode2, mockChildNode3,
mockChildNode4, mockChildNode5));
// we exhaust the original mock so that the preceding node iterator is
// returned instead
// we exhaust the original mock from setUp() so that the preceding
// iterator is returned instead
mockNode.getNodes();

final Model actual = getResults();
Expand Down Expand Up @@ -197,6 +172,31 @@ public void testForLDPTriples() throws RepositoryException, IOException {
results.contains(testSubject, MEMBERSHIP_PREDICATE, HAS_CHILD));
}

@Before
public void setUp() throws RepositoryException {
initMocks(this);
when(mockNode.getName()).thenReturn("mockNode");
when(mockNode.getSession()).thenReturn(mockSession);
when(mockGraphSubjects.getContext()).thenReturn(testPage);
when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockParentNode.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockNodeType.getName()).thenReturn("not:root");
when(mockNode.getMixinNodeTypes()).thenReturn(new NodeType[] {});
when(mockNode.getPath()).thenReturn(MOCK_NODE_PATH);
when(mockParentNode.getPath()).thenReturn(MOCK_PARENT_NODE_PATH);
when(mockNode.getParent()).thenReturn(mockParentNode);
when(mockNode.getNodes()).thenReturn(mockNodes);
when(mockParentNode.hasProperties()).thenReturn(false);
when(mockNode.hasProperties()).thenReturn(false);
when(mockGraphSubjects.getGraphSubject(mockNode)).thenReturn(
testSubject);
when(mockGraphSubjects.getGraphSubject(mockParentNode)).thenReturn(
testParentSubject);
when(mockGraphSubjects.getGraphSubject(mockChildNode)).thenReturn(
testChildSubject);
when(mockNodeType.isNodeType("mode:system")).thenReturn(false);
}

private void nodeIsContainer() {
when(mockNodeType.getChildNodeDefinitions()).thenReturn(
new NodeDefinition[] {mock(NodeDefinition.class)});
Expand Down
Expand Up @@ -35,26 +35,7 @@

public class NamespaceContextTest {

@Mock
private NamespaceRegistry mockNamespaceRegistry;

@Mock
private Session mockSession;

@Mock
private Workspace mockWorkspace;

private final static String testUri = "http://example.com";

private final static String prefix = "jcr";

@Before
public void setUp() throws RepositoryException {
initMocks(this);
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
when(mockWorkspace.getNamespaceRegistry()).thenReturn(
mockNamespaceRegistry);
}
// for mocks and setup gear see after tests

@Test(expected = NullPointerException.class)
public void testBadNamespaceRegistry() throws RepositoryException {
Expand All @@ -72,6 +53,27 @@ public void testConstructor() throws RepositoryException {
assertTrue(any(new NamespaceContext(mockSession), hasTestUriAsObject));
}

@Before
public void setUp() throws RepositoryException {
initMocks(this);
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
when(mockWorkspace.getNamespaceRegistry()).thenReturn(
mockNamespaceRegistry);
}

@Mock
private NamespaceRegistry mockNamespaceRegistry;

@Mock
private Session mockSession;

@Mock
private Workspace mockWorkspace;

private final static String testUri = "http://example.com";

private final static String prefix = "jcr";

private static Predicate<Triple> hasTestUriAsObject =
new Predicate<Triple>() {

Expand Down

0 comments on commit 871d010

Please sign in to comment.