Merge remote-tracking branch 'origin/logging_and_docs' into testing

# Conflicts:
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LogConfiguration.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java
This commit is contained in:
Andrin Fassbind
2022-05-13 22:53:30 +02:00
21 changed files with 412 additions and 86 deletions
@@ -1,6 +1,6 @@
package ch.zhaw.projekt2.turnierverwaltung;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
@@ -12,10 +12,13 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.*;
/**
* FileIO Test Class
*/
class FileIOTest {
String RESOURCES_DIR = "./src/test/resources/ch/zhaw/projekt2/turnierverwaltung/";
@@ -23,6 +26,11 @@ class FileIOTest {
String saveDir;
FileIO io;
/**
* Method checks if a new directory is set up correctly and can be accessed.
*
* @throws IOException Exceptions should not be thrown
*/
@Test
void FileIONewDir() throws IOException {
mainDir = RESOURCES_DIR + "FileIONew";
@@ -50,14 +58,23 @@ class FileIOTest {
assertFalse(saveDirFile.exists());
}
/**
* Method tests the read behavior and if a file is read correctly
*/
@Nested
class Read{
/**
* Sets up a directory
*/
@BeforeEach
void init() {
mainDir = RESOURCES_DIR + "FileIORead";
io = new FileIO(mainDir);
}
/**
* Test if the list is displayed correctly when getting it via getList
*/
@Test
void getList() {
List<FileIO.TournamentFile> tournaments = io.getList();
@@ -65,6 +82,9 @@ class FileIOTest {
assertEquals("test1.txt", tournaments.get(1).getName());
}
/**
* Test behaviour when the list is empty
*/
@Test
void getListEmpty() {
mainDir = RESOURCES_DIR + "FileIOEmpty";
@@ -72,6 +92,12 @@ class FileIOTest {
assertEquals(0, io.getList().size());
}
/**
* Tests behavior when loading a tournament that exists.
*
* @throws IOException Exceptions should not be thrown
* @throws ClassNotFoundException Exceptions should not be thrown
*/
@Test
void loadTournament() throws IOException, ClassNotFoundException {
mainDir = RESOURCES_DIR + "FileIORead";
@@ -80,6 +106,9 @@ class FileIOTest {
assertEquals("test1", tournament.getName());
}
/**
* Test behavior when trying to load non-existent tournament
*/
@Test
void loadTournamentNotExisting(){
File file = new File("Not-existing-File");
@@ -88,11 +117,17 @@ class FileIOTest {
assertFalse(file.exists());
}
/**
* Tests behavior when trying to load an empty tournament.
*/
@Test
void loadTournamentEmpty(){
assertThrows(IOException.class, () -> io.loadTournament(new File(mainDir + "/saves/empty.txt")));
}
/**
* Tests behavior when the tournamentfile input is null
*/
@Test
void loadTournamentFileNull(){
assertThrows(IllegalArgumentException.class, () -> io.loadTournament(null));
@@ -107,6 +142,13 @@ class FileIOTest {
io = new FileIO(mainDir);
}
/**
* Saves the Saving mechanism and deletion
*
* @throws IOException Exceptions should not be thrown
* @throws InvalidNameException Exceptions should not be thrown
* @throws Tournament.InvalidTypeException Exceptions should not be thrown
*/
@Test
void saveTournament() throws IOException, InvalidNameException, Tournament.InvalidTypeException {
Tournament tournament = null;
@@ -118,6 +160,9 @@ class FileIOTest {
assertFalse(file.exists());
}
/**
* Tests behavior when a tournament is being saved that is only null
*/
@Test
void saveTournamentNull(){
assertThrows(IllegalArgumentException.class, () -> io.saveTournament(null));
@@ -132,6 +177,10 @@ class FileIOTest {
io = new FileIO(mainDir);
}
/**
* Test if tournament that does exist can be deleted
* @throws IOException Exceptions should not be thrown
*/
@Test
void deleteTournament() throws IOException {
File file = new File(mainDir + "/saves/test1.txt");
@@ -141,6 +190,11 @@ class FileIOTest {
assertFalse(file.exists());
}
/**
* Testing if tournament that does not exist can be deleted
*
* @throws IOException Exception should not be thrown only checking for FileNotFoundException
*/
@Test
void deleteTournamentNotExisting() throws IOException {
File file = new File("Not-existing-File");
@@ -149,6 +203,9 @@ class FileIOTest {
assertFalse(file.exists());
}
/**
* Tests if a tournament that is null can be deleted
*/
@Test
void deleteTournamentNull(){
assertThrows(IllegalArgumentException.class, () -> io.deleteTournament(null));