EventTests

This commit is contained in:
Oystein 2021-04-23 11:29:09 +02:00
parent 92fa16891c
commit 2e397fd971
7 changed files with 85 additions and 5 deletions

View File

@ -103,7 +103,7 @@ public class MenubarController implements Initializable, Controller {
try { try {
File dir = FileOperations.openFolderWithDialog(stage); File dir = FileOperations.openFolderWithDialog(stage);
this.eventBus.post(new OpenProjectEvent(dir.toPath())); this.eventBus.post(new OpenProjectEvent(Optional.of(dir.toPath())));
} catch (FileNotFoundException e) {} } catch (FileNotFoundException e) {}
} }

View File

@ -10,21 +10,21 @@ import app.model.Model;
*/ */
public class OpenProjectEvent extends Event { public class OpenProjectEvent extends Event {
private Path path; private Optional<Path> path;
/** /**
* Event signalizing that a folder is supposed to be opened in the filetree. * Event signalizing that a folder is supposed to be opened in the filetree.
* @param path The path of the folder to be opened * @param path The path of the folder to be opened
*/ */
public OpenProjectEvent(Path path) { public OpenProjectEvent(Optional<Path> path) {
this.path = path; this.path = path;
Model.setProjectPath(Optional.of(path)); Model.setProjectPath(path);
} }
/** /**
* @return The path of the folder to be opened * @return The path of the folder to be opened
*/ */
public Path getPath() { public Optional<Path> getPath() {
return this.path; return this.path;
} }
} }

View File

@ -0,0 +1,19 @@
package app.events;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import app.model.Model;
import app.model.languages.Java;
import app.testing.EventTestTemplate;
public class LanguageChangedEventTest extends EventTestTemplate {
@Test
@DisplayName("Check that model gets changed on constructor")
private void checkModel() {
new LanguageChangedEvent("Java");
this.mockModel.verify(() -> Model.setLanguage(new Java()));
}
}

View File

@ -0,0 +1,20 @@
package app.events;
import java.util.Optional;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import app.model.Model;
import app.testing.EventTestTemplate;
public class OpenFileEventTest extends EventTestTemplate {
@Test
@DisplayName("Check that model gets changed on constructor")
private void checkModel() {
new OpenFileEvent(Optional.empty());
this.mockModel.verify(() -> Model.setActiveFilePath(Optional.empty()));
}
}

View File

@ -0,0 +1,21 @@
package app.events;
import java.util.Optional;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import app.model.Model;
import app.testing.EventTestTemplate;
public class OpenProjectEventTest extends EventTestTemplate {
@Test
@DisplayName("Check that model gets changed on constructor")
private void checkModel() {
new OpenProjectEvent(Optional.empty());
this.mockModel.verify(() -> Model.setProjectPath(Optional.empty()));
}
}

View File

@ -0,0 +1,18 @@
package app.events;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import app.model.Model;
import app.testing.EventTestTemplate;
public class ThemeChangedEventTest extends EventTestTemplate {
@Test
@DisplayName("Check that model gets changed on constructor")
private void checkModel() {
new ThemeChangedEvent("Monokai");
this.mockModel.verify(() -> Model.setTheme("Monokai"));
}
}

View File

@ -1,3 +1,5 @@
@ECHO OFF @ECHO OFF
call mvn package -Dmaven.test.skip=true
java -jar --enable-preview target/banana-editor-1.0.0.jar java -jar --enable-preview target/banana-editor-1.0.0.jar