### Question:
ApplicationNameUtil { public String decorateName(String name, String userName) { if (name.endsWith("-cb")) { name += "-" + userName; } if (!name.endsWith("-cb-" + userName)) { name = name + "-cb-" + userName; } return cutToMaxLength(name, userName); }  String decorateName(String name, String userName);  }### Answer:
@Test public void testDecorateNameWhenNameContainsPostfix() { ReflectionTestUtils.setField(underTest, "maxResourceNameLength", 30); String actual = underTest.decorateName("smtg-name-cb-username", "username"); Assertions.assertEquals("smtg-name-cb-username", actual); }
@Test public void testDecorateNameWhenNameContainsCbOnly() { ReflectionTestUtils.setField(underTest, "maxResourceNameLength", 30); String actual = underTest.decorateName("smtg-name-cb", "username"); Assertions.assertEquals("smtg-name-cb-username", actual); }
@Test public void testDecorateNameWhenNameDoesNotContainsPostfix() { ReflectionTestUtils.setField(underTest, "maxResourceNameLength", 30); String actual = underTest.decorateName("smtg-name", "username"); Assertions.assertEquals("smtg-name-cb-username", actual); }
@Test public void testDecorateNameWhenNameIsTooLong() { ReflectionTestUtils.setField(underTest, "maxResourceNameLength", 15); String actual = underTest.decorateName("smtg-name-smtg-name-smtg-name-smtg-name-smtg-name-smtg-name", "username"); Assertions.assertEquals("smt-cb-username", actual); }
@Test public void testDecorateNameWhenNameIsEqualsChars() { ReflectionTestUtils.setField(underTest, "maxResourceNameLength", 21); String actual = underTest.decorateName("smtg-name-cb-username", "username"); Assertions.assertEquals("smtg-name-cb-username", actual); }