Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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