Test all branches of LanguageChangedEvent

This commit is contained in:
Oystein Kristoffer Tveit 2021-04-26 00:31:33 +02:00
parent 40d32a5d54
commit 075988f327
2 changed files with 27 additions and 4 deletions

View File

@ -17,18 +17,22 @@ public class LanguageChangedEvent extends Event {
public LanguageChangedEvent(String language) {
this.language = language;
switch (language) {
switch (language.toLowerCase()) {
case "Java":
case "java":
Model.setLanguage(new Java());
break;
case "Markdown":
case "markdown":
Model.setLanguage(new Markdown());
break;
default:
case "empty":
Model.setLanguage(new Empty());
break;
default:
throw new IllegalArgumentException("Could not recognize language: " + language);
}
}

View File

@ -1,9 +1,12 @@
package app.events;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import app.model.Model;
import app.model.languages.Empty;
import app.model.languages.Java;
import app.testing.EventTestTemplate;
@ -15,5 +18,21 @@ public class LanguageChangedEventTest extends EventTestTemplate {
new LanguageChangedEvent("Java");
this.mockModel.verify(() -> Model.setLanguage(new Java()));
}
@Test
@DisplayName("Change into every possible language")
private void checkPossibleLanguages() {
new LanguageChangedEvent("Java");
this.mockModel.verify(() -> Model.setLanguage(new Java()));
new LanguageChangedEvent("Markdown");
this.mockModel.verify(() -> Model.setLanguage(new Java()));
new LanguageChangedEvent("Empty");
this.mockModel.verify(() -> Model.setLanguage(new Empty()));
assertThrows(IllegalArgumentException.class, () -> new LanguageChangedEvent(""));
}
}