/** * 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 testBigHtml() throws Exception { // given String expectedFormattedValue = String.format(htmlSyntax.getBigFormat(), testValue); // when Piece piece = HtmlPiece.put(testKey, testValue).big(); // then assertThat(piece.getValue()).isEqualTo(expectedFormattedValue); }
@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 public void testPut() throws Exception { // given // data in setUp() method // when Piece piece = HtmlPiece.put(testKey, testValue); // then assertThat(piece.getKey()).isEqualTo(testKey); assertThat(piece.getValue()).isEqualTo(testValue); }
@Test public void testItalicHtml() throws Exception { // given String expectedFormattedValue = String.format(htmlSyntax.getItalicFormat(), testValue); // when Piece piece = HtmlPiece.put(testKey, testValue).italic(); // then assertThat(piece.getValue()).isEqualTo(expectedFormattedValue); }
@Test public void testSubHtml() throws Exception { // given String expectedFormattedValue = String.format(htmlSyntax.getSubFormat(), testValue); // when Piece piece = HtmlPiece.put(testKey, testValue).sub(); // then assertThat(piece.getValue()).isEqualTo(expectedFormattedValue); }
@Test public void testBoldHtml() throws Exception { // given String expectedFormattedValue = String.format(htmlSyntax.getBoldFormat(), testValue); // when Piece piece = HtmlPiece.put(testKey, testValue).bold(); // then assertThat(piece.getValue()).isEqualTo(expectedFormattedValue); }
@Test public void testSupHtml() throws Exception { // given String expectedFormattedValue = String.format(htmlSyntax.getSupFormat(), testValue); // when Piece piece = HtmlPiece.put(testKey, testValue).sup(); // then assertThat(piece.getValue()).isEqualTo(expectedFormattedValue); }
@Test public void testUnderlineHtml() throws Exception { // given String expectedFormattedValue = String.format(htmlSyntax.getUnderlineFormat(), testValue); // when Piece piece = HtmlPiece.put(testKey, testValue).underline(); // then assertThat(piece.getValue()).isEqualTo(expectedFormattedValue); }
@Test public void testSmallHtml() throws Exception { // given String expectedFormattedValue = String.format(htmlSyntax.getSmallFormat(), testValue); // when Piece piece = HtmlPiece.put(testKey, testValue).small(); // then assertThat(piece.getValue()).isEqualTo(expectedFormattedValue); }
assertThat(piece.getValue()).isEqualTo(expectedFormattedValue);