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
47 @Test
48 public void testGetTextWithOnlyKeyParameter()
49 {
50 assertingResolver.getText("hello world");
51 }
52
53 @Test
54 public void testGetTextWithMessageParameterWithZeroArgument()
55 {
56 Message message = new DefaultMessage("fun");
57 assertingResolver.getText(message);
58 }
59
60 @Test(expected = NullPointerException.class)
61 public void testGetTextWithLocaleRequiresNonNullLocale()
62 {
63 assertingResolver.getText(null, "hello world");
64 }
65
66 @Test
67 public void testGetTextWithLocaleAndKey()
68 {
69 assertingResolver.getText(Locale.ENGLISH, "hello world");
70 }
71 }