Skip to content

Commit

Permalink
Merge pull request #520 from ajkannan/check-null-load
Browse files Browse the repository at this point in the history
Check for null in Project.load()
  • Loading branch information
ajkannan committed Jan 4, 2016
2 parents 645f381 + 2e152a3 commit 0fa9b51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public Project(ResourceManager resourceManager, ProjectInfo projectInfo) {
/**
* Constructs a Project object that contains project information loaded from the server.
*
* @return Project object containing the project's metadata
* @return Project object containing the project's metadata or {@code null} if not found
* @throws ResourceManagerException upon failure
*/
public static Project load(ResourceManager resourceManager, String projectId) {
ProjectInfo projectInfo = resourceManager.get(projectId);
return new Project(resourceManager, projectInfo);
return projectInfo != null ? new Project(resourceManager, projectInfo) : null;
}

/**
Expand All @@ -67,7 +67,7 @@ public ResourceManager resourceManager() {
/**
* Returns a Project object with updated project information.
*
* @return Project object containing the project's updated metadata
* @return Project object containing the project's updated metadata or {@code null} if not found
* @throws ResourceManagerException upon failure
*/
public Project reload() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -78,6 +80,24 @@ public void testReload() {
assertEquals(newInfo, newProject.info());
}

@Test
public void testLoadNull() {
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(null);
replay(resourceManager);
assertNull(Project.load(resourceManager, PROJECT_INFO.projectId()));
}

@Test
public void testReloadDeletedProject() {
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(PROJECT_INFO);
expect(resourceManager.get(PROJECT_INFO.projectId())).andReturn(null);
replay(resourceManager);
Project loadedProject = Project.load(resourceManager, PROJECT_INFO.projectId());
assertNotNull(loadedProject);
Project reloadedProject = loadedProject.reload();
assertNull(reloadedProject);
}

@Test
public void testInfo() {
replay(resourceManager);
Expand Down

0 comments on commit 0fa9b51

Please sign in to comment.