### Question:
LabelService implements ILabelService { @Override public LabelDto addLabelGroup(LabelDto labelRequest) { try { BeanPropertyBindingResult validationResult = this.validateAddLabelGroup(labelRequest); if (validationResult.hasErrors()) { throw new ValidationConflictException(validationResult); } String code = labelRequest.getKey(); ApsProperties languages = new ApsProperties(); languages.putAll(labelRequest.getTitles()); this.getI18nManager().addLabelGroup(code, languages); return labelRequest; } catch (ApsSystemException t) { logger.error("error in add label group with code {}", labelRequest.getKey(), t); throw new RestServerError("error in add label group", t); } }  void setI18nManager(II18nManager i18nManager); void setLangManager(ILangManager langManager); @SuppressWarnings({"rawtypes", "unchecked"}) @Override PagedMetadata<LabelDto> getLabelGroups(final RestListRequest restRequest); @Override LabelDto getLabelGroup(String code); @Override LabelDto updateLabelGroup(LabelDto labelRequest); @Override LabelDto addLabelGroup(LabelDto labelRequest); @Override void removeLabelGroup(String code);  }### Answer:
@Test(expected = RestServerError.class) public void testAddLabelGroupError() throws ApsSystemException { when(langManager.getDefaultLang()).thenReturn(lang); when(langManager.getAssignableLangs()).thenReturn(singletonList(lang)); when(langManager.getLangs()).thenReturn(singletonList(lang)); doThrow(ApsSystemException.class).when(i18nManager).addLabelGroup(anyString(), any(ApsProperties.class)); final LabelDto label = new LabelDto("lab", singletonMap("EN", "some_value")); labelService.addLabelGroup(label); }
@Test(expected = ValidationConflictException.class) public void testAddLabelGroupNotAssignableLang() throws ApsSystemException { when(langManager.getDefaultLang()).thenReturn(lang); when(langManager.getAssignableLangs()).thenReturn(Collections.emptyList()); when(langManager.getLangs()).thenReturn(singletonList(lang)); final LabelDto label = new LabelDto("lab", singletonMap("EN", "some_value")); labelService.addLabelGroup(label); }
@Test public void testAddLabelGroup() throws ApsSystemException { when(langManager.getDefaultLang()).thenReturn(lang); when(langManager.getAssignableLangs()).thenReturn(singletonList(lang)); when(langManager.getLangs()).thenReturn(singletonList(lang)); final LabelDto label = new LabelDto("lab", singletonMap("EN", "some_value")); final LabelDto labelResult = labelService.addLabelGroup(label); ArgumentCaptor<ApsProperties> captor = ArgumentCaptor.forClass(ApsProperties.class); verify(i18nManager, times(1)).addLabelGroup(eq("lab"), captor.capture()); final ApsProperties value = captor.getValue(); assertThat(value.getProperty("EN")).isEqualTo("some_value"); assertThat(labelResult.getKey()).isEqualTo("lab"); assertThat(labelResult.getTitles()).hasSize(1); assertThat(labelResult.getTitles()).containsOnly(entry("EN", "some_value")); }