TagDaoHelper { public void assertDisplayNameDoesNotExistForTag(String tagCode, String displayName) { TagEntity tagEntity = tagDao.getTagByTagTypeAndDisplayName(tagCode, displayName); if (tagEntity != null) { throw new AlreadyExistsException(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", displayName, tagEntity.getTagType().getCode(), tagEntity.getTagCode())); } }  void assertDisplayNameDoesNotExistForTag(String tagCode, String displayName); List<TagEntity> getTagChildrenEntities(TagEntity parentTagEntity); TagEntity getTagEntity(TagKey tagKey); void validateParentTagEntity(TagEntity tagEntity, TagEntity parentTagEntity); void validateParentTagType(String tagTypeCode, String parentTagTypeCode);  }
@Test public void testAssertDisplayNameDoesNotExistForTag() { TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(TAG_TYPE_CODE); TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(TAG_CODE); tagEntity.setDisplayName(TAG_DISPLAY_NAME); when(tagDao.getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME)).thenReturn(tagEntity); try { tagDaoHelper.assertDisplayNameDoesNotExistForTag(TAG_CODE, TAG_DISPLAY_NAME); fail("Expected to throw an exception."); } catch (AlreadyExistsException alreadyExistsException) { assertThat("Exception message is not correct.", alreadyExistsException.getMessage(), is(equalTo(String .format("Display name \"%s\" already exists for a tag with tag type \"%s\" and tag code \"%s\".", TAG_DISPLAY_NAME, tagEntity.getTagType().getCode(), tagEntity.getTagCode())))); } verify(tagDao).getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME); verifyNoMoreInteractions(configurationHelper, tagDao); }
@Test public void testAssertDisplayNameDoesNotExistForTagWithNullTagEntity() { when(tagDao.getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME)).thenReturn(null); try { tagDaoHelper.assertDisplayNameDoesNotExistForTag(TAG_CODE, TAG_DISPLAY_NAME); } catch (AlreadyExistsException alreadyExistsException) { fail("Should not have caught an exception."); } verify(tagDao).getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME); verifyNoMoreInteractions(configurationHelper, tagDao); }