Test all branches of LanguageChangedEvent
This commit is contained in:
parent
40d32a5d54
commit
075988f327
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(""));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue