Extract logic from classes
This commit is contained in:
@@ -37,6 +37,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import app.testing.FxTestTemplate;
|
||||
import app.model.Model;
|
||||
import app.model.ProgrammingLanguage;
|
||||
import app.service.FileOperations;
|
||||
import app.service.LanguageOperations;
|
||||
import app.events.CopyEvent;
|
||||
import app.events.CutEvent;
|
||||
@@ -88,16 +89,14 @@ public class EditorControllerTest extends FxTestTemplate {
|
||||
String resourcePath = "/testfile.txt";
|
||||
String filePath = getClass().getResource(resourcePath).getPath();
|
||||
File file = new File(filePath);
|
||||
List<String> content =
|
||||
Files.readAllLines(file.toPath())
|
||||
.stream()
|
||||
.map(s -> s + "\n")
|
||||
.collect(Collectors.toList());
|
||||
|
||||
eventBus.post(new FileSelectedEvent(filePath));
|
||||
verify(editor, times(content.size())).appendText(captor.capture());
|
||||
eventBus.post(new FileSelectedEvent(file.toPath()));
|
||||
try (MockedStatic<FileOperations> mocked = mockStatic(FileOperations.class)) {
|
||||
mocked.when(() -> FileOperations.readFile(any()))
|
||||
.thenReturn("");
|
||||
|
||||
assertEquals(content, captor.getAllValues());
|
||||
mocked.verify(() -> FileOperations.readFile(file.toPath()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +104,7 @@ public class EditorControllerTest extends FxTestTemplate {
|
||||
public void testFileSelectedEventWithUnrealFile() throws IOException {
|
||||
|
||||
String brokenFilePath = "/doesNotExist.txt";
|
||||
eventBus.post(new FileSelectedEvent(brokenFilePath));
|
||||
eventBus.post(new FileSelectedEvent(new File(brokenFilePath).toPath()));
|
||||
|
||||
verify(editor, never()).clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user