### Question:
StopPlaceHandler { @Request(value = StopPlaceRequest.NAME, service = true) public void handleStopPlace( Optional<VoiceContext> context, @Named(StopPlaceRequest.ATTR_ASSISTANT) String assistant ) { long startTime = System.nanoTime(); try { if(!context.isPresent()) { VoiceServiceMetrics.timeHandlerSuccess(StopPlaceRequest.NAME, startTime); return; } voiceDao.removeAssistant(context.get().getPlaceId(), assistant); proactiveCredsDAO.remove(context.get().getPlaceId(), assistant); context.get().removeAssistant(assistant); if(!context.get().hasAssistants()) { registry.remove(context.get().getPlaceId()); } VoiceServiceMetrics.timeHandlerSuccess(StopPlaceRequest.NAME, startTime); } catch(RuntimeException e) { VoiceServiceMetrics.timeHandlerFailure(StopPlaceRequest.NAME, startTime); throw e; } } StopPlaceHandler(VoiceDAO voiceDao, ProactiveCredsDAO proactiveCredsDAO, VoiceContextExecutorRegistry registry); @Request(value = StopPlaceRequest.NAME, service = true) void handleStopPlace(
      Optional<VoiceContext> context,
      @Named(StopPlaceRequest.ATTR_ASSISTANT) String assistant
   );  }### Answer:
@Test public void testStopDoesntFlushCache() { mockVoiceDao.removeAssistant(placeId, VoiceService.StartPlaceRequest.ASSISTANT_ALEXA); EasyMock.expectLastCall(); mockProactiveCredsDao.remove(placeId, VoiceService.StartPlaceRequest.ASSISTANT_ALEXA); EasyMock.expectLastCall(); replay(); handler.handleStopPlace(Optional.of(context), VoiceService.StartPlaceRequest.ASSISTANT_ALEXA); assertTrue(context.getAssistants().noneMatch(VoiceService.StartPlaceRequest.ASSISTANT_ALEXA::equals)); assertTrue(context.getAssistants().anyMatch(VoiceService.StartPlaceRequest.ASSISTANT_GOOGLE::equals)); verify(); }
@Test public void testStopLastFlushesCache() { context.removeAssistant(VoiceService.StartPlaceRequest.ASSISTANT_ALEXA); mockVoiceDao.removeAssistant(placeId, VoiceService.StartPlaceRequest.ASSISTANT_GOOGLE); EasyMock.expectLastCall(); mockProactiveCredsDao.remove(placeId, VoiceService.StartPlaceRequest.ASSISTANT_GOOGLE); EasyMock.expectLastCall(); mockContextRegistry.remove(placeId); EasyMock.expectLastCall(); replay(); handler.handleStopPlace(Optional.of(context), VoiceService.StartPlaceRequest.ASSISTANT_GOOGLE); assertEquals(0, context.getAssistants().count()); verify(); }