From 91bba8878c01c913696d5b12cc6e5b45f7e93300 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 26 Apr 2021 21:15:36 +0200 Subject: [PATCH] Update tests --- .../app/controllers/EditorControllerTest.java | 1 - .../java/app/service/DialogBoxesTest.java | 6 ---- .../java/app/service/FileOperationsTest.java | 29 +++++++++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/test/java/app/controllers/EditorControllerTest.java b/src/test/java/app/controllers/EditorControllerTest.java index b959d72..500538f 100644 --- a/src/test/java/app/controllers/EditorControllerTest.java +++ b/src/test/java/app/controllers/EditorControllerTest.java @@ -20,7 +20,6 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/src/test/java/app/service/DialogBoxesTest.java b/src/test/java/app/service/DialogBoxesTest.java index b71d394..1f434ad 100644 --- a/src/test/java/app/service/DialogBoxesTest.java +++ b/src/test/java/app/service/DialogBoxesTest.java @@ -2,10 +2,4 @@ package app.service; public class DialogBoxesTest { - - - - - - } diff --git a/src/test/java/app/service/FileOperationsTest.java b/src/test/java/app/service/FileOperationsTest.java index 8bbe2a4..51a77dc 100644 --- a/src/test/java/app/service/FileOperationsTest.java +++ b/src/test/java/app/service/FileOperationsTest.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; @@ -22,36 +21,56 @@ import com.google.common.io.Files; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.MockedStatic; +import org.mockito.junit.jupiter.MockitoExtension; import app.model.Model; +import javafx.scene.control.Alert; +import javafx.stage.DirectoryChooser; +import javafx.stage.FileChooser; import javafx.stage.Stage; +@ExtendWith(MockitoExtension.class) public class FileOperationsTest { @TempDir File tmp; + @Mock + FileChooser fc = mock(FileChooser.class); + + @Mock + DirectoryChooser dc = mock(DirectoryChooser.class); + + @Mock + Alert error = mock(Alert.class); + + @InjectMocks + MockedStatic db = mockStatic(DialogBoxes.class); + @Test @DisplayName("Test openFileWithDialog") public void testOpenFileWithDialog() { - try (MockedStatic mocked = mockStatic(DialogBoxes.class)) { + // try (MockedStatic mocked = mockStatic(DialogBoxes.class)) { Stage stage = mock(Stage.class); - mocked.when(() -> DialogBoxes.showopenFileWithDialog(any())) + db.when(() -> DialogBoxes.showopenFileWithDialog(any())) .thenReturn(null); assertThrows(FileNotFoundException.class, () -> FileOperations.openFileWithDialog(stage)); File file = mock(File.class); - mocked.when(() -> DialogBoxes.showopenFileWithDialog(any())) + db.when(() -> DialogBoxes.showopenFileWithDialog(any())) .thenReturn(file); try { assertEquals(file, FileOperations.openFileWithDialog(stage)); } catch (FileNotFoundException e) { fail("Chosen file was null when it was expected to be mock file"); } - } + // } }