Update tests
This commit is contained in:
parent
c53d5716c3
commit
91bba8878c
@ -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;
|
||||
|
@ -2,10 +2,4 @@ package app.service;
|
||||
|
||||
public class DialogBoxesTest {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<DialogBoxes> db = mockStatic(DialogBoxes.class);
|
||||
|
||||
@Test
|
||||
@DisplayName("Test openFileWithDialog")
|
||||
public void testOpenFileWithDialog() {
|
||||
try (MockedStatic<DialogBoxes> mocked = mockStatic(DialogBoxes.class)) {
|
||||
// try (MockedStatic<DialogBoxes> 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");
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user