1 package com.atlassian.sal.core.message;
2
3 import com.atlassian.sal.api.message.I18nResolver;
4 import com.atlassian.sal.api.message.Message;
5 import org.junit.Test;
6
7 import java.io.Serializable;
8 import java.util.Locale;
9 import java.util.Map;
10
11 import static org.junit.Assert.assertEquals;
12
13 public class TestAbstractI18nResolver {
14 private I18nResolver assertingResolver = new AbstractI18nResolver() {
15 @Override
16 public String resolveText(String key, Serializable[] arguments) {
17 assertEquals(0, arguments.length);
18 return "";
19 }
20
21 @Override
22 public String resolveText(Locale locale, String key, Serializable[] arguments) {
23 assertEquals(0, arguments.length);
24 return "";
25 }
26
27 public Map<String, String> getAllTranslationsForPrefix(String prefix) {
28 throw new UnsupportedOperationException();
29 }
30
31 public Map<String, String> getAllTranslationsForPrefix(String prefix, Locale locale) {
32 throw new UnsupportedOperationException();
33 }
34
35 public String getRawText(final String key) {
36 throw new UnsupportedOperationException();
37 }
38
39 public String getRawText(final Locale locale, final String key) {
40 throw new UnsupportedOperationException();
41 }
42 };
43
44 @Test
45 public void testGetTextWithOnlyKeyParameter() {
46 assertingResolver.getText("hello world");
47 }
48
49 @Test
50 public void testGetTextWithMessageParameterWithZeroArgument() {
51 Message message = new DefaultMessage("fun");
52 assertingResolver.getText(message);
53 }
54
55 @Test(expected = NullPointerException.class)
56 public void testGetTextWithLocaleRequiresNonNullLocale() {
57 assertingResolver.getText(null, "hello world");
58 }
59
60 @Test
61 public void testGetTextWithLocaleAndKey() {
62 assertingResolver.getText(Locale.ENGLISH, "hello world");
63 }
64 }