### Question:
HubMinimumFirmwareVersionResolver implements MinimumFirmwareVersionResolver<Hub> { @Override public Version resolveMinimumVersion(Hub hub) { String minHubVersion = null; Population population = null; String populationName = null; String model = null; if (hub != null && hub.getPlace() != null) { populationName = placeDao.getPopulationById(hub.getPlace()); } if(StringUtils.isNotBlank(populationName)) { population = populationDao.findByName(populationName); } if (population == null) { population = populationDao.getDefaultPopulation(); } model = hub.getModel(); if (model == null) return null; switch (model) { case "IH300": case "IH304": minHubVersion = population.getMinHubV3Version(); break; case "IH200": minHubVersion = population.getMinHubV2Version(); break; default: return null; } return Version.fromRepresentation(minHubVersion); } @Inject  HubMinimumFirmwareVersionResolver(PlaceDAO placeDao, PopulationDAO populationDao); @Override Version resolveMinimumVersion(Hub hub);  }### Answer:
@Test public void testNoPlaceReturnsDefault() { replay(mockPlaceDao); expect(mockPopulationDao.getDefaultPopulation()).andReturn(defaultPopulation); replay(mockPopulationDao); Hub hub = new Hub(); hub.setModel("IH200"); assertEquals(Version.fromRepresentation(defaultPopulation.getMinHubV2Version()), resolver.resolveMinimumVersion(hub)); }
@Test public void testPlaceWithNoPopulationReturnsDefault() { replay(mockPlaceDao); expect(mockPopulationDao.getDefaultPopulation()).andReturn(defaultPopulation); replay(mockPopulationDao); Hub hub = new Hub(); hub.setModel("IH200"); assertEquals(Version.fromRepresentation(defaultPopulation.getMinHubV2Version()), resolver.resolveMinimumVersion(hub)); }
@Test public void testPlaceWithPopulationReturnsVersion2() { UUID placeId = UUID.randomUUID(); Hub hub = new Hub(); hub.setPlace(placeId); hub.setModel("IH200"); Place place = new Place(); place.setPopulation(alphaPopulation.getName()); expect(mockPlaceDao.getPopulationById(placeId)).andReturn(alphaPopulation.getName()); replay(mockPlaceDao); expect(mockPopulationDao.findByName(alphaPopulation.getName())).andReturn(alphaPopulation); replay(mockPopulationDao); assertEquals(Version.fromRepresentation(alphaPopulation.getMinHubV2Version()), resolver.resolveMinimumVersion(hub)); }
@Test public void testPlaceWithPopulationReturnsVersion3() { UUID placeId = UUID.randomUUID(); Hub hub = new Hub(); hub.setPlace(placeId); hub.setModel("IH300"); Place place = new Place(); place.setPopulation(alphaPopulation.getName()); expect(mockPlaceDao.getPopulationById(placeId)).andReturn(place.getPopulation()); replay(mockPlaceDao); expect(mockPopulationDao.findByName(alphaPopulation.getName())).andReturn(alphaPopulation); replay(mockPopulationDao); assertEquals(Version.fromRepresentation(alphaPopulation.getMinHubV3Version()), resolver.resolveMinimumVersion(hub)); }
@Test public void testBadHubModel() { replay(mockPlaceDao); expect(mockPopulationDao.getDefaultPopulation()).andReturn(defaultPopulation); replay(mockPopulationDao); Hub hub = new Hub(); assertNull(resolver.resolveMinimumVersion(hub)); }