-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package core.model; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.MissingResourceException; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
|
||
class TranslationFacilityTest { | ||
|
||
@Test | ||
void getTranslator() { | ||
// given | ||
TranslationFacility.setTranslator(null); | ||
|
||
// when | ||
final var translator = TranslationFacility.getTranslator(); | ||
|
||
// then | ||
assertThat(translator.getLanguage()).isEqualTo(Translator.LANGUAGE_NO_TRANSLATION); | ||
} | ||
|
||
@Test | ||
void setLanguage_with_German() { | ||
// given | ||
TranslationFacility.setLanguage("German"); | ||
|
||
// when | ||
final var translator = TranslationFacility.getTranslator(); | ||
|
||
// then | ||
assertThat(translator.getLanguage()).isEqualTo("German"); | ||
} | ||
|
||
@Test | ||
void setLanguage_unknown_throws_exception() { | ||
// when-then | ||
assertThatThrownBy(() -> TranslationFacility.setLanguage("foobar")).isInstanceOf(MissingResourceException.class); | ||
} | ||
|
||
@Test | ||
void setTranslator() { | ||
// when | ||
TranslationFacility.setTranslator(null); | ||
|
||
// then | ||
assertThat(TranslationFacility.getTranslator()).isNotNull(); | ||
assertThat(TranslationFacility.getTranslator().getLanguage()).isEqualTo(Translator.LANGUAGE_NO_TRANSLATION); | ||
} | ||
|
||
@Test | ||
void tr_with_initial_translator_results_in_no_translation() { | ||
// given | ||
TranslationFacility.setTranslator(null); | ||
|
||
// when | ||
final var translation = TranslationFacility.tr("ls.button.save"); | ||
|
||
// then | ||
assertThat(translation).isEqualTo("!ls.button.save!"); | ||
} | ||
|
||
@Test | ||
void trWithVariables() { | ||
// given | ||
TranslationFacility.setLanguage("English"); | ||
|
||
// when | ||
final var translation = TranslationFacility.tr("ls.teamanalyzer.bot_since", "EVER"); | ||
|
||
// then | ||
assertThat(translation).isEqualTo("since EVER"); | ||
} | ||
} |