From e8e64d435ce77c51afc5e08a4e3471fa4302254f Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sun, 1 May 2022 10:49:29 +0200 Subject: [PATCH 1/2] added Method deleteTournament but not implemented yet in FileIO.java added Test Methods for deleteTournament. --- .../projekt2/turnierverwaltung/FileIO.java | 5 +++ .../turnierverwaltung/FileIOTest.java | 36 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java index d072da5..801b6e0 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FileIO.java @@ -110,4 +110,9 @@ public class FileIO { } } + + public void deleteTournament(File tournamentFile) throws IOException { + throw new UnsupportedOperationException("Method deleteTournament not implemented yet."); + } + } diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java index ad0b9e8..aeeddf4 100644 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java +++ b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java @@ -83,7 +83,10 @@ class FileIOTest { @Test void loadTournamentNotExisting(){ io = new FileIO(mainDir); - assertThrows(FileNotFoundException.class, () -> io.loadTournament(new File("Not-existing-File"))); + File file = new File("Not-existing-File"); + assertFalse(file.exists()); + assertThrows(FileNotFoundException.class, () -> io.loadTournament(file)); + assertFalse(file.exists()); } @Test @@ -124,4 +127,35 @@ class FileIOTest { assertThrows(IllegalArgumentException.class, () -> io.saveTournament(null)); } } + + @Nested + class Delete{ + @BeforeEach + void setup(){ + mainDir = RESOURCES_DIR + "FileIODelete"; + io = new FileIO(mainDir); + } + + @Test + void deleteTournament() throws IOException { + File file = new File(mainDir + "/saves/test1.txt"); + file.createNewFile(); + assertTrue(file.exists()); + io.deleteTournament(file); + assertFalse(file.exists()); + } + + @Test + void deleteTournamentNotExisting() throws IOException { + File file = new File("Not-existing-File"); + assertFalse(file.exists()); + assertThrows(FileNotFoundException.class, () -> io.deleteTournament(file)); + assertFalse(file.exists()); + } + + @Test + void deleteTournamentNull(){ + assertThrows(IllegalArgumentException.class, () -> io.deleteTournament(null)); + } + } } \ No newline at end of file From 672ad409ce754004fc31185923aa74d5f136750e Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sun, 1 May 2022 10:54:21 +0200 Subject: [PATCH 2/2] refactoring in FileIOTest.java --- .../java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java index aeeddf4..8abeecd 100644 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java +++ b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FileIOTest.java @@ -82,7 +82,6 @@ class FileIOTest { @Test void loadTournamentNotExisting(){ - io = new FileIO(mainDir); File file = new File("Not-existing-File"); assertFalse(file.exists()); assertThrows(FileNotFoundException.class, () -> io.loadTournament(file)); @@ -91,13 +90,11 @@ class FileIOTest { @Test void loadTournamentEmpty(){ - io = new FileIO(mainDir); assertThrows(IOException.class, () -> io.loadTournament(new File(mainDir + "/saves/empty.txt"))); } @Test void loadTournamentFileNull(){ - io = new FileIO(mainDir); assertThrows(IllegalArgumentException.class, () -> io.loadTournament(null)); } }