@Test public void loadProjectList_callback_registers_project_to_ProjectManager_and_dispatch_it_on_event_bus() throws Exception { // Setup final ProjectList projectList = new ProjectList(); projectList.addProject(new Project("pId1", "pName", "pParentId")); projectList.addProject(new Project("pId2", "pName", "pParentId")); when(_mockRequestController.sendRequest(getApiVersion(), "projects", ProjectList.class)) .thenReturn(Futures.immediateFuture(projectList)); // Exercise final ListenableFuture<Void> ackFuture = _apiController.loadProjectList(); // Verify assertThat(_projectManager.getProjects().size(), is(2)); assertThat(_projectManager.getProjects().get(0).getId(), is("pId1")); assertThat(_projectManager.getProjects().get(1).getId(), is("pId2")); assertThat(_dispatchedObjects, hasItem(_projectManager)); assertThat(ackFuture.isDone(), is(true)); }
@Test public void loadBuildTypeList_callback_dispatches_parent_project_on_event_bus() throws Exception { // Setup final ProjectData project = new ProjectData("p1", "pname", Optional.<String>empty()); final ProjectData project2 = new ProjectData("p2", "pname", Optional.<String>empty()); _projectManager.registerProjects(ImmutableList.of(project, project2)); final BuildTypeList buildTypelist = new BuildTypeList(); buildTypelist.addBuildType(new BuildType("bt1", "btName", "pname", "p2")); when(_mockRequestController.sendRequest(getApiVersion(), "buildTypes", BuildTypeList.class)) .thenReturn(Futures.immediateFuture(buildTypelist)); // Exercise _apiController.loadBuildTypeList(); // Verify assertThat(_dispatchedObjects, not(hasItem(project))); assertThat(_dispatchedObjects, hasItem(project2)); }