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 import static org.junit.Assert.fail;
13
14 public class TestAbstractI18nResolver
15 {
16 private I18nResolver assertingResolver = new AbstractI18nResolver() {
17 @Override
18 public String resolveText(String key, Serializable[] arguments)
19 {
20 assertEquals(0, arguments.length);
21 return "";
22 }
23
24 @Override
25 public String resolveText(Locale locale, String key, Serializable[] arguments)
26 {
27 assertEquals(0, arguments.length);
28 return "";
29 }
30
31 public Map<String, String> getAllTranslationsForPrefix(String prefix)
32 {
33 throw new UnsupportedOperationException();
34 }
35
36 public Map<String, String> getAllTranslationsForPrefix(String prefix, Locale locale)
37 {
38 throw new UnsupportedOperationException();
39 }
40
41 public String getRawText(final String key)
42 {
43 throw new UnsupportedOperationException();
44 }
45
46 public String getRawText(final Locale locale, final String key)
47 {
48 throw new UnsupportedOperationException();
49 }
50 };
51
52 @Test
53 public void testGetTextWithOnlyKeyParameter()
54 {
55 assertingResolver.getText("hello world");
56 }
57
58 @Test
59 public void testGetTextWithMessageParameterWithZeroArgument()
60 {
61 Message message = new DefaultMessage("fun");
62 assertingResolver.getText(message);
63 }
64
65 @Test(expected = NullPointerException.class)
66 public void testGetTextWithLocaleRequiresNonNullLocale()
67 {
68 assertingResolver.getText(null, "hello world");
69 }
70
71 @Test
72 public void testGetTextWithLocaleAndKey()
73 {
74 assertingResolver.getText(Locale.ENGLISH, "hello world");
75 }
76 }