* Initiates a new instance of the class TextLogic. * Contains command instructions for the class Text. * Defined the different cases and appointed to specific commands. @@ -106,7 +108,6 @@ public class TextLogic { textOutput.errorInvalidCommand(); break; } - } while (!"EXIT".equals(command[0])); } @@ -120,9 +121,17 @@ public class TextLogic { return str.matches("\\d+"); } - private void checkIfSuccess(boolean method) { - if (method) { - textOutput.userInfoOutput("Command was successfull"); + /** + * Method for checking if a command has been executed successfully. + * If it is success it would output a message, which tells the user that is was successfully executed. + * If it failed during execution it would output a message, + * which tells the user that the execution of command has failed + * + * @param result is the result of the executed command + */ + private void checkIfSuccess(boolean result) { + if (result) { + textOutput.userInfoOutput("Command was successful!"); } else { textOutput.errorInvalidParagraph(); } diff --git a/src/TextOutput.java b/src/TextOutput.java index 9b21b07..95fc4c8 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -1,7 +1,8 @@ import java.util.ArrayList; /** - * New class TextOutput + * @Class TextOutput + *
* This class puts out the finished text and formats the text if wanted.
* Author: Leonardo Brandenberger
* Date: 12.11.2021
@@ -20,7 +21,7 @@ public class TextOutput {
if (text.size() == 0) {
errorMissingText();
} else if (formatRaw) {
- printFormated(text);
+ printFormatted(text);
} else {
toFormat(text);
}
@@ -31,7 +32,7 @@ public class TextOutput {
*
* @param text the ArrayList which is used for the output
*/
- private void printFormated(ArrayList
+ * This test method checks, if the index method lists the words with all lines, in which they appear
+ * It should return "Word 1, 2" and "Test 1, 2, 3"
+ */
+ @Test
+ void indexNormalTest() {
+ txt.add("Word word Test");
+ txt.add("Word word etc. !!test zweite... Zeile");
+ txt.add("Lorem ipsum lorem ipsum TEST");
+ stringListe = txt.index();
+ Assertions.assertEquals("Word 1, 2", stringListe.get(0));
+ Assertions.assertEquals("Test 1, 2, 3", stringListe.get(1));
+ }
+
+ /**
+ * Test method: indexMultipleWordsTest()
+ *
+ * This method tests if the method get the first word, which appears multiple times
+ * Index() should return
+ */
+ @Test
+ void indexMultipleWordsTest() {
+ txt.add("Word Word Word Test");
+ Assertions.assertEquals("Word 1", txt.index().get(0));
+ }
+
+ /**
+ * Test method: indexEmptyTest()
+ *
+ * Tests the method index(), when there are no text saved or available
+ * It should return an empty Array with the type String
+ */
+ @Test
+ void indexEmptyTest() {
+ Assertions.assertEquals(new ArrayList
+ * Test Method to check if the method index() is working with empty Strings
+ * It should return an empty ArrayList with the type String
+ */
+ @Test
+ void indexWithAddedEmptyLine() {
+ txt.add("");
+ Assertions.assertEquals(new ArrayList