@Test public void testAssertDisplayNameDoesNotExistForTagWithNullTagEntity() { // Setup when clauses when(tagDao.getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME)).thenReturn(null); // Call method under test try { tagDaoHelper.assertDisplayNameDoesNotExistForTag(TAG_CODE, TAG_DISPLAY_NAME); } catch (AlreadyExistsException alreadyExistsException) { // Confirm the exception does not occur fail("Should not have caught an exception."); } // Setup verify clauses verify(tagDao).getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME); verifyNoMoreInteractions(configurationHelper, tagDao); }
tagDaoHelper.assertDisplayNameDoesNotExistForTag(tagKey.getTagTypeCode(), tagUpdateRequest.getDisplayName());
tagDaoHelper.assertDisplayNameDoesNotExistForTag(tagKey.getTagTypeCode(), tagUpdateRequest.getDisplayName());
tagDaoHelper.assertDisplayNameDoesNotExistForTag(request.getTagKey().getTagTypeCode(), request.getDisplayName()); TagEntity parentTagEntity = null; if (request.getParentTagKey() != null)
tagDaoHelper.assertDisplayNameDoesNotExistForTag(request.getTagKey().getTagTypeCode(), request.getDisplayName()); TagEntity parentTagEntity = null; if (request.getParentTagKey() != null)
@Test public void testAssertDisplayNameDoesNotExistForTag() { // Create a tag type entity TagTypeEntity tagTypeEntity = new TagTypeEntity(); tagTypeEntity.setCode(TAG_TYPE_CODE); // Create a tag entity TagEntity tagEntity = new TagEntity(); tagEntity.setTagType(tagTypeEntity); tagEntity.setTagCode(TAG_CODE); tagEntity.setDisplayName(TAG_DISPLAY_NAME); // Setup when clauses when(tagDao.getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME)).thenReturn(tagEntity); // Call method under test try { tagDaoHelper.assertDisplayNameDoesNotExistForTag(TAG_CODE, TAG_DISPLAY_NAME); fail("Expected to throw an exception."); } catch (AlreadyExistsException alreadyExistsException) { // Confirm the exception message is correct 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())))); } // Setup verify clauses verify(tagDao).getTagByTagTypeAndDisplayName(TAG_CODE, TAG_DISPLAY_NAME); verifyNoMoreInteractions(configurationHelper, tagDao); }