131 lines
4.4 KiB
Java
131 lines
4.4 KiB
Java
import org.junit.jupiter.api.Assertions;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
* New class TextTest
|
|
* This class is here to test the different methods of the Text class.
|
|
* Author: Roman Schenk, Andrin Fassbind
|
|
* Date: 12.11.2021
|
|
*/
|
|
public class TextTest {
|
|
Text txt;
|
|
ArrayList<String> stringListe;
|
|
|
|
/**
|
|
* This method prepares local parameters by resets them for each test method
|
|
*/
|
|
@BeforeEach
|
|
void setup() {
|
|
stringListe = new ArrayList<>();
|
|
txt = new Text();
|
|
}
|
|
|
|
/**
|
|
* Test methode: indexNormalTest()
|
|
* <p>
|
|
* 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()
|
|
* <p>
|
|
* 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()
|
|
* <p>
|
|
* 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<String>(), txt.index());
|
|
}
|
|
|
|
/**
|
|
* Test method: indexWithAddedEmptyLine()
|
|
* <p>
|
|
* 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<String>(), txt.index());
|
|
}
|
|
|
|
|
|
/**
|
|
* Test Method for add and dummy methods
|
|
*/
|
|
@Test
|
|
void addTest() {
|
|
Assertions.assertEquals(0, txt.getText().size());
|
|
Assertions.assertFalse(txt.add(1, "test"));
|
|
Assertions.assertFalse(txt.dummy(1));
|
|
Assertions.assertEquals(0, txt.getText().size());
|
|
Assertions.assertTrue(txt.add("test1"));
|
|
Assertions.assertTrue(txt.add(1, "test2"));
|
|
Assertions.assertEquals("test2", txt.getText().get(0));
|
|
Assertions.assertEquals("test1", txt.getText().get(1));
|
|
Assertions.assertTrue(txt.dummy(2));
|
|
Assertions.assertTrue(txt.dummy());
|
|
Assertions.assertEquals(txt.getText().get(1), txt.getText().get(3));
|
|
Assertions.assertEquals(4, txt.getText().size());
|
|
}
|
|
|
|
/**
|
|
* Test Method del
|
|
*/
|
|
@Test
|
|
void del() {
|
|
Assertions.assertTrue(txt.add("Das ist der erste Beispiel Text."));
|
|
Assertions.assertTrue(txt.add("Das ist der zweite Beispiel Text."));
|
|
Assertions.assertTrue(txt.add("Das ist der dritte Beispiel Text."));
|
|
Assertions.assertTrue(txt.add("Das ist der vierte Beispiel Text."));
|
|
Assertions.assertFalse(txt.del(5));
|
|
Assertions.assertTrue(txt.del(2));
|
|
Assertions.assertTrue(txt.del());
|
|
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(0));
|
|
Assertions.assertEquals("Das ist der dritte Beispiel Text.", txt.getText().get(1));
|
|
}
|
|
|
|
/**
|
|
* Test Method for replace Method
|
|
*/
|
|
@Test
|
|
void replace() {
|
|
Assertions.assertTrue(txt.add("Das ist der erste Beispiel Text."));
|
|
Assertions.assertTrue(txt.add("Das ist der zweite Beispiel Text."));
|
|
Assertions.assertFalse(txt.replace(3, "alt", "neu"));
|
|
Assertions.assertTrue(txt.replace(1, "erste", "zweite"));
|
|
Assertions.assertTrue(txt.replace("zweite", "erste"));
|
|
Assertions.assertTrue(txt.add("Text Text hallo Text"));
|
|
Assertions.assertTrue(txt.replace("Text", "Test"));
|
|
Assertions.assertEquals("Das ist der zweite Beispiel Text.", txt.getText().get(0));
|
|
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1));
|
|
Assertions.assertEquals("Test Test hallo Test", txt.getText().get(2));
|
|
}
|
|
|
|
}
|