135 lines
4.3 KiB
Java
135 lines
4.3 KiB
Java
package de.joethei.hs.java2.tests;
|
|
|
|
import de.joethei.hs.java2.praktikum.praktikum3.TextFileFormatException;
|
|
import de.joethei.hs.java2.praktikum.praktikum3.Vorlesung;
|
|
import de.joethei.hs.java2.praktikum.praktikum3.Vorlesungsverzeichnis;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertNotEquals;
|
|
|
|
public class VorlesungsverzeichnisTest {
|
|
|
|
private Vorlesungsverzeichnis vorlesungsverzeichnis;
|
|
|
|
@Before
|
|
public void before() {
|
|
try {
|
|
vorlesungsverzeichnis = new Vorlesungsverzeichnis(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum3/vorlesungen.txt")).getFile());
|
|
} catch (IOException | TextFileFormatException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
@Test(expected = IOException.class)
|
|
public void constructorIOException() throws IOException, TextFileFormatException {
|
|
new Vorlesungsverzeichnis("HalloWelt");
|
|
}
|
|
|
|
@Test(expected = TextFileFormatException.class)
|
|
public void constructorTextFileFormatException() throws IOException, TextFileFormatException {
|
|
new Vorlesungsverzeichnis(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum3/vorlesungen-format.txt")).getFile());
|
|
}
|
|
|
|
@Test(expected = TextFileFormatException.class)
|
|
public void constructorNumberFormatException() throws IOException, TextFileFormatException {
|
|
new Vorlesungsverzeichnis(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum3/vorlesungen-number.txt")).getFile());
|
|
}
|
|
|
|
|
|
@Test
|
|
public void titles() {
|
|
List<String> titles = new ArrayList<>();
|
|
titles.add("Algorithmen und Datenstrukturen");
|
|
titles.add("Audio-/Videotechnik");
|
|
titles.add("Internet-Technologien");
|
|
titles.add("Java 2");
|
|
titles.add("Mathematik 2");
|
|
titles.add("Rechnerarchitekturen");
|
|
|
|
assertEquals(vorlesungsverzeichnis.titles(), titles);
|
|
|
|
titles.add("Hallo Welt");
|
|
assertNotEquals(vorlesungsverzeichnis.titles(), titles);
|
|
}
|
|
|
|
@Test
|
|
public void workaholics() {
|
|
Set<String> set = new HashSet<>();
|
|
set.add("von Coelln");
|
|
set.add("Rump");
|
|
assertEquals(vorlesungsverzeichnis.workaholics(), set);
|
|
}
|
|
|
|
@Test
|
|
public void groupToTitles() {
|
|
Map<String, List<String>> map = vorlesungsverzeichnis.groupToTitles();
|
|
|
|
List<String> mt2 = new ArrayList<>();
|
|
mt2.add("Audio-/Videotechnik");
|
|
mt2.add("Mathematik 2");
|
|
|
|
List<String> e2 = new ArrayList<>();
|
|
e2.add("Mathematik 2");
|
|
|
|
List<String> i2 = new ArrayList<>();
|
|
i2.add("Algorithmen und Datenstrukturen");
|
|
i2.add("Java 2");
|
|
|
|
List<String> i4 = new ArrayList<>();
|
|
i4.add("Internet-Technologien");
|
|
i4.add("Rechnerarchitekturen");
|
|
|
|
assertEquals(mt2, map.get("MT2"));
|
|
assertEquals(e2, map.get("E2"));
|
|
assertEquals(i2, map.get("I2"));
|
|
assertEquals(i4, map.get("I4"));
|
|
}
|
|
|
|
@Test
|
|
public void multipleTitles() {
|
|
Map<String, List<String>> map = vorlesungsverzeichnis.multipleTitles();
|
|
|
|
List<String> math = new ArrayList<>();
|
|
math.add("Rabe");
|
|
math.add("von Coelln");
|
|
|
|
Collections.sort(math);
|
|
assertEquals(map.get("Mathematik 2"), math);
|
|
}
|
|
|
|
@Test
|
|
public void descendingTitles() {
|
|
List<String> list = new ArrayList<>();
|
|
list.add("Java 2");
|
|
list.add("Algorithmen und Datenstrukturen");
|
|
list.add("Mathematik 2");
|
|
list.add("Mathematik 2");
|
|
list.add("Audio-/Videotechnik");
|
|
list.add("Rechnerarchitekturen");
|
|
list.add("Internet-Technologien");
|
|
|
|
assertEquals(list, vorlesungsverzeichnis.descendingTitles());
|
|
}
|
|
|
|
@Test
|
|
public void toStringTest() {
|
|
List<String> list = new ArrayList<>();
|
|
list.add("I2");
|
|
list.add("Java 2");
|
|
list.add("Rump");
|
|
list.add("10");
|
|
try {
|
|
Vorlesung vorlesung = new Vorlesung(list);
|
|
assertEquals(vorlesung.toString(), "I2:Java 2:Rump:10");
|
|
} catch (TextFileFormatException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
} |