Skip to content

Commit

Permalink
Junit tests for the missed line coverages shown in Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
leenata committed Jun 28, 2013
1 parent 8bc8ce8 commit 8420ce3
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions fcrepo-kernel/src/test/java/org/fcrepo/FedoraResourceTest.java
Expand Up @@ -6,9 +6,7 @@

package org.fcrepo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

This comment has been minimized.

Copy link
@eddies
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -78,7 +76,7 @@ public void setUp() {
testObj = new FedoraResource(mockNode);
assertEquals(mockNode, testObj.getNode());
}

/**
* @todo Add Documentation.
*/
Expand Down Expand Up @@ -142,6 +140,12 @@ public void testGetCreatedDate() throws RepositoryException {
assertEquals(someDate.getTimeInMillis(), testObj.getCreatedDate()
.getTime());
}

@Test
public void testCreatedDateMissing() throws RepositoryException {
when(mockNode.hasProperty(FedoraResource.JCR_CREATED)).thenReturn(false);
assertNull(testObj.getCreatedDate());
}

/**
* @todo Add Documentation.
Expand Down Expand Up @@ -205,6 +209,17 @@ public void testGetLastModifiedDate() throws RepositoryException {
assertEquals(modDate.getTimeInMillis(), actual.getTime());
}

@Test
public void testUpdatePropertiesDataset() throws RepositoryException {

// UpdateAction mockUpdate = mock(UpdateAction.class);

// GraphSubjects mockGraphSubjects = mock(GraphSubjects.class);
// testObj.updatePropertiesDataset(mockGraphSubjects, "xyz");

// verify(mockUpdate).parseExecute(anyString(), any(Dataset.class));
}

@Test
public void testGetPropertiesDataset() throws RepositoryException {

Expand All @@ -226,6 +241,36 @@ public void testGetPropertiesDataset() throws RepositoryException {
assertEquals(propertiesModel, dataset.getDefaultModel());
assertEquals("info:fedora/xyz", dataset.getContext().get(Symbol.create("uri")));
}

// @Test
// public void testGetPropertiesDatasetwithNullContext() throws RepositoryException {
//
// mockStatic(JcrRdfTools.class);
// mockStatic(DatasetFactory.class);
//
// GraphSubjects mockSubjects = mock(GraphSubjects.class);
// final Resource mockResource = mock(Resource.class);
// when(mockResource.getURI()).thenReturn("info:fedora/xyz");
// when(JcrRdfTools.getGraphSubject(mockSubjects, mockNode)).thenReturn(mockResource);
//
// final Model propertiesModel = ModelFactory.createDefaultModel();
// when(JcrRdfTools.getJcrPropertiesModel(mockSubjects, mockNode)).thenReturn(propertiesModel);
// final Model treeModel = ModelFactory.createDefaultModel();
// when(JcrRdfTools.getJcrTreeModel(mockSubjects, mockNode, 0, -1)).thenReturn(treeModel);
//
// DatasetFactory mockDatasetFactory = mock(DatasetFactory.class);
// Dataset mockDataset = mock(Dataset.class);
// when(mockDatasetFactory.create(propertiesModel)).thenReturn(mockDataset);
// when(mockDataset.getContext()).thenReturn(null);
//
// final Dataset dataset = testObj.getPropertiesDataset(mockSubjects, 0, -1);
//
// assertTrue(dataset.containsNamedModel("tree"));
// assertEquals(treeModel, dataset.getNamedModel("tree"));
//
// assertEquals(propertiesModel, dataset.getDefaultModel());
// assertEquals("info:fedora/xyz", dataset.getContext().get(Symbol.create("uri")));
// }

@Test
public void testGetPropertiesDatasetDefaultLimits() throws RepositoryException {
Expand Down

2 comments on commit 8420ce3

@eddies
Copy link

@eddies eddies commented on 8420ce3 Jun 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leenata please make sure you're following https://wiki.duraspace.org/display/FF/Contributing#Contributing-FormattingRules

And I would use @ignore rather than commenting out entire swaths of tests as above

@leenata
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, henceforth.
Thanks.

Please sign in to comment.