2021-11-05 11:35:09 +01:00
|
|
|
import org.junit.jupiter.api.Assertions;
|
2021-11-05 09:14:26 +01:00
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
2021-11-12 10:37:38 +01:00
|
|
|
|
2021-11-05 09:14:26 +01:00
|
|
|
import java.util.ArrayList;
|
2021-11-10 18:19:40 +01:00
|
|
|
|
2021-11-12 11:11:03 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2021-11-04 14:19:58 +01:00
|
|
|
public class TextTest {
|
2021-11-05 09:14:26 +01:00
|
|
|
Text txt;
|
2021-11-12 10:49:19 +01:00
|
|
|
ArrayList<String> stringListe;
|
2021-11-05 09:14:26 +01:00
|
|
|
|
2021-11-12 11:11:03 +01:00
|
|
|
/**
|
|
|
|
* This method is here as a preparation for the test.
|
|
|
|
*/
|
2021-11-05 09:14:26 +01:00
|
|
|
@BeforeEach
|
|
|
|
void setup() {
|
2021-11-12 10:53:40 +01:00
|
|
|
stringListe = new ArrayList<>();
|
2021-11-05 09:14:26 +01:00
|
|
|
txt = new Text();
|
|
|
|
}
|
|
|
|
|
2021-11-10 13:55:59 +01:00
|
|
|
/**
|
|
|
|
* Test Method for add and dummy methods
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void addTest() {
|
|
|
|
Assertions.assertEquals(0, txt.getText().size());
|
2021-11-11 14:05:46 +01:00
|
|
|
Assertions.assertFalse(txt.add(1, "test"));
|
|
|
|
Assertions.assertFalse(txt.dummy(1));
|
2021-11-10 13:55:59 +01:00
|
|
|
Assertions.assertEquals(0, txt.getText().size());
|
2021-11-11 14:05:46 +01:00
|
|
|
Assertions.assertTrue(txt.add("test1"));
|
|
|
|
Assertions.assertTrue(txt.add(1, "test2"));
|
2021-11-10 13:55:59 +01:00
|
|
|
Assertions.assertEquals("test2", txt.getText().get(0));
|
|
|
|
Assertions.assertEquals("test1", txt.getText().get(1));
|
2021-11-11 14:05:46 +01:00
|
|
|
Assertions.assertTrue(txt.dummy(2));
|
|
|
|
Assertions.assertTrue(txt.dummy());
|
|
|
|
Assertions.assertEquals(txt.getText().get(1), txt.getText().get(3));
|
2021-11-10 13:55:59 +01:00
|
|
|
Assertions.assertEquals(4, txt.getText().size());
|
|
|
|
}
|
|
|
|
|
2021-11-11 11:33:10 +01:00
|
|
|
/**
|
|
|
|
* Test Method del
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void del() {
|
2021-11-11 14:05:46 +01:00
|
|
|
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());
|
2021-11-11 11:33:10 +01:00
|
|
|
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(0));
|
|
|
|
Assertions.assertEquals("Das ist der dritte Beispiel Text.", txt.getText().get(1));
|
|
|
|
}
|
|
|
|
|
2021-11-11 09:44:23 +01:00
|
|
|
/**
|
|
|
|
* Test Method for replace Method
|
|
|
|
*/
|
2021-11-11 09:43:14 +01:00
|
|
|
@Test
|
|
|
|
void replace() {
|
2021-11-11 14:05:46 +01:00
|
|
|
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"));
|
2021-11-11 22:42:10 +01:00
|
|
|
Assertions.assertTrue(txt.add("Text Text hallo Text"));
|
|
|
|
Assertions.assertTrue(txt.replace("Text", "Test"));
|
2021-11-11 09:43:14 +01:00
|
|
|
Assertions.assertEquals("Das ist der zweite Beispiel Text.", txt.getText().get(0));
|
|
|
|
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1));
|
2021-11-11 22:42:10 +01:00
|
|
|
Assertions.assertEquals("Test Test hallo Test", txt.getText().get(2));
|
2021-11-11 09:43:14 +01:00
|
|
|
}
|
|
|
|
|
2021-11-10 18:19:40 +01:00
|
|
|
/**
|
|
|
|
* Test methode for Index method
|
2021-11-12 10:49:19 +01:00
|
|
|
* For TestCase Positiv Testcase One, Three and Four Negativ Testcase Two
|
2021-11-10 18:19:40 +01:00
|
|
|
*/
|
2021-11-05 09:14:26 +01:00
|
|
|
@Test
|
2021-11-12 10:49:19 +01:00
|
|
|
void indexTestOne() {
|
2021-11-10 18:19:40 +01:00
|
|
|
txt.add("Word word Test");
|
|
|
|
txt.add("Word word etc. !!test zweite... Zeile");
|
|
|
|
txt.add("Lorem ipsum lorem ipsum TEST");
|
|
|
|
stringListe = txt.index();
|
2021-11-12 10:37:38 +01:00
|
|
|
Assertions.assertEquals("Word 1, 2", stringListe.get(0));
|
|
|
|
Assertions.assertEquals("Test 1, 2, 3", stringListe.get(1));
|
2021-11-12 10:49:19 +01:00
|
|
|
}
|
2021-11-10 18:19:40 +01:00
|
|
|
|
2021-11-12 10:49:19 +01:00
|
|
|
/**
|
|
|
|
* Test methode for Index method
|
|
|
|
* For TestCase Positiv Testcase Two
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void indexTestTwo() {
|
2021-11-10 18:19:40 +01:00
|
|
|
txt.add("Word word Word Test");
|
|
|
|
stringListe = txt.index();
|
2021-11-12 10:37:38 +01:00
|
|
|
Assertions.assertEquals("Word 1", stringListe.get(0));
|
2021-11-12 10:49:19 +01:00
|
|
|
}
|
2021-11-10 18:19:40 +01:00
|
|
|
|
2021-11-12 10:49:19 +01:00
|
|
|
/**
|
|
|
|
* Test methode for Index method
|
|
|
|
* For TestCase Negativ Testcase One
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
void indexTestThree() {
|
2021-11-10 18:19:40 +01:00
|
|
|
stringListe = txt.index();
|
2021-11-12 10:37:38 +01:00
|
|
|
Assertions.assertEquals(0, stringListe.size());
|
2021-11-05 09:14:26 +01:00
|
|
|
}
|
2021-11-11 17:18:50 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
void testing() {
|
|
|
|
txt.add("");
|
|
|
|
txt.index();
|
|
|
|
}
|
2021-11-04 14:19:58 +01:00
|
|
|
}
|