TagDaoHelper { public TagEntity getTagEntity(TagKey tagKey) throws ObjectNotFoundException { TagEntity tagEntity = tagDao.getTagByKey(tagKey); if (tagEntity == null) { throw new ObjectNotFoundException( String.format("Tag with code \"%s\" doesn't exist for tag type \"%s\".", tagKey.getTagCode(), tagKey.getTagTypeCode())); } return tagEntity; }  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 testGetTagEntity() { 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); TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE); when(tagDao.getTagByKey(tagKey)).thenReturn(tagEntity); TagEntity result = tagDaoHelper.getTagEntity(tagKey); assertThat("Result not equal to tag entity.", result, is(equalTo(tagEntity))); verify(tagDao).getTagByKey(tagKey); verifyNoMoreInteractions(configurationHelper, tagDao); }
@Test public void testGetTagEntityWithNullTagEntity() { TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE); when(tagDao.getTagByKey(tagKey)).thenReturn(null); try { tagDaoHelper.getTagEntity(tagKey); fail("Expected to throw an exception."); } catch (ObjectNotFoundException objectNotFoundException) { assertThat("Exception message is not correct.", objectNotFoundException.getMessage(), is(equalTo(String.format("Tag with code \"%s\" doesn't exist for tag type \"%s\".", tagKey.getTagCode(), tagKey.getTagTypeCode())))); } verify(tagDao).getTagByKey(tagKey); verifyNoMoreInteractions(configurationHelper, tagDao); }