### Question:
SwitchOperationsService implements ILinkOperationsServiceCarrier { public Switch patchSwitch(SwitchId switchId, SwitchPatch data) throws SwitchNotFoundException { return transactionManager.doInTransaction(() -> { Switch foundSwitch = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); Optional.ofNullable(data.getPop()).ifPresent(pop -> foundSwitch.setPop(!"".equals(pop) ? pop : null)); Optional.ofNullable(data.getLocation()).ifPresent(location -> { Optional.ofNullable(location.getLatitude()).ifPresent(foundSwitch::setLatitude); Optional.ofNullable(location.getLongitude()).ifPresent(foundSwitch::setLongitude); Optional.ofNullable(location.getStreet()).ifPresent(foundSwitch::setStreet); Optional.ofNullable(location.getCity()).ifPresent(foundSwitch::setCity); Optional.ofNullable(location.getCountry()).ifPresent(foundSwitch::setCountry); }); switchRepository.detach(foundSwitch); return foundSwitch; }); } SwitchOperationsService(RepositoryFactory repositoryFactory,
                                   TransactionManager transactionManager,
                                   SwitchOperationsServiceCarrier carrier); GetSwitchResponse getSwitch(SwitchId switchId); List<GetSwitchResponse> getAllSwitches(); Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance); boolean deleteSwitch(SwitchId switchId, boolean force); void checkSwitchIsDeactivated(SwitchId switchId); void checkSwitchHasNoFlows(SwitchId switchId); void checkSwitchHasNoFlowSegments(SwitchId switchId); void checkSwitchHasNoIsls(SwitchId switchId); SwitchPropertiesDto getSwitchProperties(SwitchId switchId); SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto); PortProperties getPortProperties(SwitchId switchId, int port); Collection<SwitchConnectedDevice> getSwitchConnectedDevices(
            SwitchId switchId); List<IslEndpoint> getSwitchIslEndpoints(SwitchId switchId); Switch patchSwitch(SwitchId switchId, SwitchPatch data);  }### Answer:
@Test public void shouldPatchSwitch() throws SwitchNotFoundException { Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build(); switchRepository.add(sw); SwitchPatch switchPatch = new SwitchPatch("pop", new SwitchLocation(48.860611, 2.337633, "street", "city", "country")); switchOperationsService.patchSwitch(TEST_SWITCH_ID, switchPatch); Switch updatedSwitch = switchRepository.findById(TEST_SWITCH_ID).get(); assertEquals(switchPatch.getPop(), updatedSwitch.getPop()); assertEquals(switchPatch.getLocation().getLatitude(), updatedSwitch.getLatitude()); assertEquals(switchPatch.getLocation().getLongitude(), updatedSwitch.getLongitude()); assertEquals(switchPatch.getLocation().getStreet(), updatedSwitch.getStreet()); assertEquals(switchPatch.getLocation().getCity(), updatedSwitch.getCity()); assertEquals(switchPatch.getLocation().getCountry(), updatedSwitch.getCountry()); }
@Test public void shouldSetNullPopWhenPopIsEmptyString() throws SwitchNotFoundException { Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build(); switchRepository.add(sw); SwitchPatch switchPatch = new SwitchPatch("", null); switchOperationsService.patchSwitch(TEST_SWITCH_ID, switchPatch); Switch updatedSwitch = switchRepository.findById(TEST_SWITCH_ID).get(); assertNull(updatedSwitch.getPop()); }