76 lines
2.5 KiB
Java
76 lines
2.5 KiB
Java
import org.junit.jupiter.api.Assertions;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import java.util.ArrayList;
|
|
|
|
|
|
public class TextTest {
|
|
Text txt;
|
|
|
|
@BeforeEach
|
|
void setup() {
|
|
txt = new Text();
|
|
}
|
|
|
|
/**
|
|
* Test Method for add and dummy methods
|
|
*/
|
|
@Test
|
|
void addTest() {
|
|
Assertions.assertEquals(0, txt.getText().size());
|
|
Assertions.assertEquals(false, txt.add(1, "test"));
|
|
Assertions.assertEquals(false, txt.dummy(1));
|
|
Assertions.assertEquals(0, txt.getText().size());
|
|
Assertions.assertEquals(true, txt.add("test1"));
|
|
Assertions.assertEquals(true, txt.add(1, "test2"));
|
|
Assertions.assertEquals("test2", txt.getText().get(0));
|
|
Assertions.assertEquals("test1", txt.getText().get(1));
|
|
Assertions.assertEquals(true, txt.dummy(2));
|
|
Assertions.assertEquals(true, txt.dummy());
|
|
Assertions.assertEquals(true, txt.getText().get(1).equals(txt.getText().get(3)));
|
|
Assertions.assertEquals(4, txt.getText().size());
|
|
}
|
|
|
|
@Test
|
|
void replace() {
|
|
Assertions.assertEquals(true, txt.add("Das ist der erste Beispiel Text."));
|
|
Assertions.assertEquals(true, txt.add("Das ist der zweite Beispiel Text."));
|
|
Assertions.assertEquals(false, txt.replace(3, "alt", "neu"));
|
|
Assertions.assertEquals(true, txt.replace(1, "erste", "zweite"));
|
|
Assertions.assertEquals(true, txt.replace("zweite", "erste"));
|
|
Assertions.assertEquals("Das ist der zweite Beispiel Text.", txt.getText().get(0));
|
|
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1));
|
|
}
|
|
|
|
/**
|
|
* Test methode for Index method
|
|
*/
|
|
@Test
|
|
void indexTest() {
|
|
ArrayList<String> stringListe;
|
|
|
|
//Positiv Testcase One, Three and Four Negativ Testcase Two
|
|
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));
|
|
//End of Test
|
|
|
|
setup();
|
|
|
|
//Positiv Testcase Two
|
|
txt.add("Word word Word Test");
|
|
stringListe = txt.index();
|
|
Assertions.assertEquals("Word 1",stringListe.get(0));
|
|
//End of Test
|
|
|
|
setup();
|
|
|
|
//Negativ Testcase One
|
|
stringListe = txt.index();
|
|
Assertions.assertEquals(0,stringListe.size());
|
|
}
|
|
}
|