/** * Returns formatted CharSequence without additional operations * * @return formatted CharSequence */ public CharSequence format() { if (pieces.isEmpty()) { return input; } String target; for (Piece piece : pieces) { target = BRACE_START + piece.getKey() + BRACE_END; input = input.replace(target, String.valueOf(piece.getValue())); } return input; }
@Test public void testColorHtml() throws Exception { // given String testColorHexValue = "#FF0000"; String colorFormat = htmlSyntax.getColorFormat(); String expectedFormattedValue = String.format(colorFormat, testColorHexValue, testValue); // when Piece piece = HtmlPiece.put(testKey, testValue).color(testColorHexValue); // then assertThat(piece.getValue()).isEqualTo(expectedFormattedValue); }
@Test(expected = IllegalArgumentException.class) public void testColorShouldThrowExceptionWhenHexIsEmptyForHtml() throws Exception { // given String emptyTestColorHexValue = ""; // when HtmlPiece.put(testKey, testValue).color(emptyTestColorHexValue); // then // throw an exception }
@Test(expected = IllegalArgumentException.class) public void testColorShouldThrowExceptionWhenHexDoesNotStartFromHashForHtml() throws Exception { // given String incorrectTestColorHexValue = "F#FFFFF"; // when HtmlPiece.put(testKey, testValue).color(incorrectTestColorHexValue); // then // throw an exception }
@Test(expected = IllegalArgumentException.class) public void testColorShouldThrowExceptionWhenHexIsNullForHtml() throws Exception { // given String nullTestColorHexValue = null; // when HtmlPiece.put(testKey, testValue).color(nullTestColorHexValue); // then // throw an exception }
@Test(expected = IllegalArgumentException.class) public void testColorShouldThrowExceptionWhenHexDoesNotContainSevenCharacters() throws Exception { // given String incorrectTestColorHexValue = "#FFFFFFF"; // when HtmlPiece.put(testKey, testValue).color(incorrectTestColorHexValue); // then // throw an exception }
@Test public void testColorHexShouldContainSevenCharactersForHtml() throws Exception { // given String correctTestColorHexValue = "#FFFFFF"; // when Piece piece = HtmlPiece.put(testKey, testValue).color(correctTestColorHexValue); // then // no exception occurs and object is created assertThat(piece).isNotNull(); }