### Question:
BuildingServiceImpl implements BuildingService { @Override public ConstructionSite constructOrUpgradeBuilding(Planet planet, BuildingType type) throws BuildingException { Preconditions.checkNotNull(planet, "planet"); Preconditions.checkNotNull(type, "type"); Buildings buildings = findBuildingsOnPlanet(planet); Optional<Building> existingBuilding = buildings.stream().filter(b -> b.getType().equals(type)).findFirst(); if (existingBuilding.isPresent()) { return upgradeBuilding(planet, type); } else { return constructBuilding(planet, type); } } @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(description = "Construct building") public void testConstructOrUpgradeBuilding() 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.constructOrUpgradeBuilding(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 = "Upgrade building") public void testConstructOrUpgradeBuilding2() throws Exception { UUID id = UUID.randomUUID(); when(uuidFactory.create()).thenReturn(id); ConstructionSite expected = new ConstructionSite(id, BuildingType.COMMAND_CENTER, 2, Data.Player1.Planet1.PLANET.getId(), Data.Player1.PLAYER.getId(), 1, 3, BUILD_COST_COMMAND_CENTER_2); ConstructionSite actual = sut.constructOrUpgradeBuilding(Data.Player1.Planet1.PLANET, BuildingType.COMMAND_CENTER); verify(planetDAO).update(Data.Player1.Planet1.PLANET.withResources(new Resources(0, 0, 0))); verify(constructionSiteDAO).insert(expected); assertThat(expected, is(actual)); }