Extract logic from classes

This commit is contained in:
2021-04-20 09:28:45 +00:00
parent 7d40b2608d
commit 77ddb56d69
14 changed files with 416 additions and 249 deletions

View File

@@ -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();
}