### Question:
BuildingServiceImpl implements BuildingService { @Override public ConstructionSite constructBuilding(Planet planet, BuildingType type) throws BuildingException { Preconditions.checkNotNull(planet, "planet"); Preconditions.checkNotNull(type, "type"); return createConstructionSite(planet, type, 1); } @Inject  BuildingServiceImpl(UUIDFactory uuidFactory, BuildingDAO buildingDAO, RoundService roundService, ConstructionSiteDAO constructionSiteDAO, PlanetDAO planetDAO, EventService eventService, TechnologyDAO technologyDAO, BuildingMechanics buildingMechanics, TechnologyMechanics technologyMechanics); @Override Buildings findBuildingsOnPlanet(Planet planet); @Override List<ConstructionSite> findConstructionSitesOnPlanet(Planet planet); @Override void manifestBuilding(Planet planet, BuildingType type, int level); @Override ConstructionSite constructBuilding(Planet planet, BuildingType type); @Override ConstructionSite upgradeBuilding(Planet planet, BuildingType type); @Override ConstructionSite constructOrUpgradeBuilding(Planet planet, BuildingType type); @Override Resources calculateBuildCostWithoutBonuses(BuildingType type, int level); @Override void finishConstructionSites(); @Override long calculateBuildTime(BuildingType type, int level, Technologies technologies, Buildings buildings); @Override long calculateBuildTimeWithoutBonuses(BuildingType type, int level); @Override Resources calculateBuildCost(BuildingType type, int level, Technologies technologies);  }### Answer:
@Test public void testConstructBuilding() throws Exception { UUID id = UUID.randomUUID(); when(uuidFactory.create()).thenReturn(id); ConstructionSite expected = new ConstructionSite(id, BuildingType.CRYSTAL_MINE, 1, Data.Player1.Planet1.PLANET.getId(), Data.Player1.PLAYER.getId(), 1, 2, BUILD_COST_CRYSTAL_MINE_1); ConstructionSite actual = sut.constructBuilding(Data.Player1.Planet1.PLANET, BuildingType.CRYSTAL_MINE); verify(planetDAO).update(Data.Player1.Planet1.PLANET.withResources(new Resources(5, 10, 15))); verify(constructionSiteDAO).insert(expected); assertThat(expected, is(actual)); }
@Test(description = "Prerequisites not fulfilled") public void testConstructBuilding2() throws Exception { when(buildingMechanics.getPrerequisites(BuildingType.COMMAND_CENTER)).thenReturn(Prerequisites.buildings(new Prerequisites.Building(BuildingType.SHIPYARD, 10))); try { sut.constructBuilding(Data.Player1.Planet1.PLANET, BuildingType.COMMAND_CENTER); fail("Expected exception"); } catch (BuildingException e) { assertThat(e.getReason(), is(BuildingException.Reason.PREREQUISITES_NOT_FULFILLED)); } }
@Test(description = "Not enough build queues") public void testConstructBuilding3() throws Exception { when(constructionSiteDAO.findWithPlanetId(Data.Player1.Planet1.PLANET.getId())).thenReturn(Arrays.asList(Data.Player1.Planet1.CONSTRUCTION_SITE)); try { sut.constructBuilding(Data.Player1.Planet1.PLANET, BuildingType.COMMAND_CENTER); fail("Expected exception"); } catch (BuildingException e) { assertThat(e.getReason(), is(BuildingException.Reason.NOT_ENOUGH_BUILD_QUEUES)); } }