CreateMappingFunction extends CliFunction<Object[]> { void createRegionMapping(JdbcConnectorService service, RegionMapping regionMapping) throws RegionMappingExistsException { service.createRegionMapping(regionMapping); } CreateMappingFunction(); @Override CliFunctionResult executeFunction(FunctionContext<Object[]> context);  }
@Test public void createRegionMappingReturnsRegionName() throws Exception { function.createRegionMapping(service, regionMapping); verify(service, times(1)).createRegionMapping(regionMapping); }
@Test public void createRegionMappingThrowsIfMappingExists() throws Exception { doAnswer((m) -> { throw new RegionMappingExistsException(); }).when(service) .createRegionMapping(eq(regionMapping)); Throwable throwable = catchThrowable(() -> function.createRegionMapping(service, regionMapping)); assertThat(throwable).isInstanceOf(RegionMappingExistsException.class); verify(service, times(1)).createRegionMapping(regionMapping); }
@Test public void executeReportsErrorIfRegionMappingExists() throws Exception { doThrow(RegionMappingExistsException.class).when(service) .createRegionMapping(eq(regionMapping)); function.execute(context); ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class); verify(resultSender, times(1)).lastResult(argument.capture()); assertThat(argument.getValue().getStatusMessage()) .contains(RegionMappingExistsException.class.getName()); }