### Question:
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager,
                                 FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message);  }### Answer:
@Test public void handleNothingRulesToSync() { missingRules = emptyList(); service.handleSwitchSync(KEY, request, makeValidationResult()); verify(carrier).response(eq(KEY), any(InfoMessage.class)); verify(carrier).cancelTimeoutCallback(eq(KEY)); verifyNoMoreInteractions(commandBuilder); verifyNoMoreInteractions(carrier); }
@Test public void handleCommandBuilderMissingRulesException() { String errorMessage = "test error"; when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())) .thenThrow(new IllegalArgumentException(errorMessage)); service.handleSwitchSync(KEY, request, makeValidationResult()); verify(commandBuilder).buildCommandsToSyncMissingRules(eq(SWITCH_ID), eq(missingRules)); ArgumentCaptor<ErrorMessage> errorCaptor = ArgumentCaptor.forClass(ErrorMessage.class); verify(carrier).cancelTimeoutCallback(eq(KEY)); verify(carrier).response(eq(KEY), errorCaptor.capture()); assertEquals(errorMessage, errorCaptor.getValue().getData().getErrorMessage()); verifyNoMoreInteractions(commandBuilder); verifyNoMoreInteractions(carrier); }
@Test public void handleNothingToSyncWithExcess() { request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).removeExcess(true).build(); missingRules = emptyList(); service.handleSwitchSync(KEY, request, makeValidationResult()); verify(carrier).cancelTimeoutCallback(eq(KEY)); verify(carrier).response(eq(KEY), any(InfoMessage.class)); verifyNoMoreInteractions(commandBuilder); verifyNoMoreInteractions(carrier); }