2 * Sone - L10nFilterTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.freenet;
20 import static freenet.l10n.BaseL10n.LANGUAGE.ENGLISH;
21 import static freenet.l10n.BaseL10n.LANGUAGE.GERMAN;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.is;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
27 import java.util.Collections;
30 import net.pterodactylus.sone.web.WebInterface;
32 import freenet.l10n.BaseL10n;
33 import freenet.l10n.BaseL10n.LANGUAGE;
35 import com.google.common.collect.ImmutableMap;
36 import org.junit.Before;
37 import org.junit.Test;
40 * Unit test for {@link L10nFilter}.
42 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
44 public class L10nFilterTest {
46 private final BaseL10n l10n = mock(BaseL10n.class);
47 private final WebInterface webInterface = mock(WebInterface.class);
48 private final L10nFilter l10nFilter = new L10nFilter(webInterface);
52 when(webInterface.getL10n()).thenReturn(l10n);
53 when(l10n.getString("SingleString")).thenReturn("Translated Value");
54 when(l10n.getString("MultiString")).thenReturn("{0,number}, {1}");
58 public void formatStringWithoutParameters() {
59 String translatedValue = l10nFilter.format(null, "SingleString", Collections.<String, Object>emptyMap());
60 assertThat(translatedValue, is("Translated Value"));
64 public void formatStringWithParametersInEnglish() {
66 Map<String, Object> parameters = ImmutableMap.<String, Object>of("0", 17.123, "1", "Value C");
67 String translatedValue = l10nFilter.format(null, "MultiString", parameters);
68 assertThat(translatedValue, is("17.123, Value C"));
72 public void formatStringWithParametersInGerman() {
74 Map<String, Object> parameters = ImmutableMap.<String, Object>of("0", 17.123, "1", "Value C");
75 String translatedValue = l10nFilter.format(null, "MultiString", parameters);
76 assertThat(translatedValue, is("17,123, Value C"));
79 private void setLanguage(LANGUAGE language) {
80 when(l10n.getSelectedLanguage()).thenReturn(language);