/** * Returns CharSequence formatted with custom formatter implementation * * @param formatter implementation * @return formatted CharSequence */ public CharSequence format(Formatter formatter) { CharSequence input = format(); return formatter.format(String.valueOf(input)); }
@Test(expected = IllegalArgumentException.class) public void testPutShouldThrowAnExceptionWhenKeyIsAnEmptyString() { // given String testKey = ""; String testValue = "test value"; String testInputString = "Sample text {" + testKey + "} rest of the sentence."; // when Kirai.from(testInputString).put(testKey, testValue).format(); // then throw an exception }
@Test(expected = IllegalArgumentException.class) public void testPutShouldThrowAnExceptionWhenKeyIsNull() { // given String testKey = null; String testValue = "test value"; String testInputString = "Sample text {" + testKey + "} rest of the sentence."; // when Kirai.from(testInputString).put(testKey, testValue).format(); // then throw an exception }
@Test public void testFormatterShouldFormatInput() { // given // formatter below is created for test purposes and it can do anything Formatter upperCaseTestFormatter = new Formatter() { @Override public CharSequence format(String input) { return input.toString().toUpperCase(); } }; String input = "value"; String expectedOutput = "VALUE"; // when CharSequence output = Kirai.from(input).format(upperCaseTestFormatter); // then assertThat(output).isEqualTo(expectedOutput); } }
@Test(expected = IllegalArgumentException.class) public void testPutShouldThrowAnExceptionWhenValueIsAnEmptyString() { String testKey = "testKey"; String testValue = ""; String testInputString = "Sample text {" + testKey + "} rest of the sentence."; // when Kirai.from(testInputString).put(testKey, testValue).format(); // then throw an exception }
@Test(expected = IllegalArgumentException.class) public void testPutShouldThrowAnExceptionWhenValueIsNull() { String testKey = "testKey"; String testValue = null; String testInputString = "Sample text {" + testKey + "} rest of the sentence."; // when Kirai.from(testInputString).put(testKey, testValue).format(); // then throw an exception }
@Test public void testPutShouldAddKeyAndValue() { // given String testKey = "test_tag_present"; String testValue = "test value"; String testInputString = "Sample text {" + testKey + "} rest of the sentence."; String expectedOutPutString = "Sample text " + testValue + " rest of the sentence."; // when CharSequence generatedCharSequence = Kirai.from(testInputString).put(testKey, testValue).format(); // then assertThat(generatedCharSequence).isEqualTo(expectedOutPutString); }
@Test public void testPutShouldAddPiece() { // given String testKey = "test_tag_present"; String testValue = "test value"; String testInputString = "Sample text {" + testKey + "} rest of the sentence."; String expectedOutPutString = "Sample text " + testValue + " rest of the sentence."; // when CharSequence generatedCharSequence = Kirai.from(testInputString) .put(HtmlPiece.put(testKey, testValue)) .format(); // then assertThat(generatedCharSequence).isEqualTo(expectedOutPutString); }