/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SE_Test.java

http://github.com/ocpsoft/prettytime · Java · 206 lines · 160 code · 28 blank · 18 comment · 0 complexity · 33756a117a2c59dad24fa583da1cb766 MD5 · raw file

  1. /*
  2. * Copyright 2012 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.ocpsoft.prettytime;
  17. import static org.junit.Assert.assertEquals;
  18. import java.text.SimpleDateFormat;
  19. import java.util.Date;
  20. import java.util.Locale;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.ocpsoft.prettytime.PrettyTime;
  24. public class PrettyTimeI18n_SE_Test {
  25. private Locale locale;
  26. private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
  27. @Before
  28. public void setUp() throws Exception
  29. {
  30. locale = new Locale("se");
  31. }
  32. @Test
  33. public void testPrettyTime()
  34. {
  35. PrettyTime p = new PrettyTime(locale);
  36. assertEquals(p.format(new Date()), "om ett par ögonblick frĺn nu");
  37. }
  38. @Test
  39. public void testPrettyTimeCenturies()
  40. {
  41. PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale);
  42. assertEquals("för 3 ĺrhundraden sedan", p.format(new Date(0)));
  43. p = new PrettyTime(new Date(0), locale);
  44. assertEquals("om 3 ĺrhundraden frĺn och med nu", p.format(new Date(3155692597470L * 3L)));
  45. }
  46. @Test
  47. public void testCeilingInterval() throws Exception
  48. {
  49. Date then = format.parse("20/5/2009");
  50. Date ref = format.parse("17/6/2009");
  51. PrettyTime t = new PrettyTime(ref, locale);
  52. assertEquals("för 1 mĺnad sedan", t.format(then));
  53. }
  54. @Test
  55. public void testNullDate() throws Exception
  56. {
  57. PrettyTime t = new PrettyTime(locale);
  58. Date date = null;
  59. assertEquals("om ett par ögonblick frĺn nu", t.format(date));
  60. }
  61. @Test
  62. public void testRightNow() throws Exception
  63. {
  64. PrettyTime t = new PrettyTime(locale);
  65. assertEquals("om ett par ögonblick frĺn nu", t.format(new Date()));
  66. }
  67. @Test
  68. public void testRightNowVariance() throws Exception
  69. {
  70. PrettyTime t = new PrettyTime(new Date(0), locale);
  71. assertEquals("om ett par ögonblick frĺn nu", t.format(new Date(600)));
  72. }
  73. @Test
  74. public void testMinutesFromNow() throws Exception
  75. {
  76. PrettyTime t = new PrettyTime(new Date(0), locale);
  77. assertEquals("om 12 minuter frĺn och med nu", t.format(new Date(1000 * 60 * 12)));
  78. }
  79. @Test
  80. public void testHoursFromNow() throws Exception
  81. {
  82. PrettyTime t = new PrettyTime(new Date(0), locale);
  83. assertEquals("om 3 timmar frĺn och med nu", t.format(new Date(1000 * 60 * 60 * 3)));
  84. }
  85. @Test
  86. public void testDaysFromNow() throws Exception
  87. {
  88. PrettyTime t = new PrettyTime(new Date(0), locale);
  89. assertEquals("om 3 dagar frĺn och med nu", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
  90. }
  91. @Test
  92. public void testWeeksFromNow() throws Exception
  93. {
  94. PrettyTime t = new PrettyTime(new Date(0), locale);
  95. assertEquals("om 3 veckor frĺn och med nu", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
  96. }
  97. @Test
  98. public void testMonthsFromNow() throws Exception
  99. {
  100. PrettyTime t = new PrettyTime(new Date(0), locale);
  101. assertEquals("om 3 mĺnader frĺn och med nu", t.format(new Date(2629743830L * 3L)));
  102. }
  103. @Test
  104. public void testYearsFromNow() throws Exception
  105. {
  106. PrettyTime t = new PrettyTime(new Date(0), locale);
  107. assertEquals("om 3 ĺr frĺn och med nu", t.format(new Date(2629743830L * 12L * 3L)));
  108. }
  109. @Test
  110. public void testDecadesFromNow() throws Exception
  111. {
  112. PrettyTime t = new PrettyTime(new Date(0), locale);
  113. assertEquals("om 3 ĺrtionden frĺn och med nu", t.format(new Date(315569259747L * 3L)));
  114. }
  115. @Test
  116. public void testCenturiesFromNow() throws Exception
  117. {
  118. PrettyTime t = new PrettyTime(new Date(0), locale);
  119. assertEquals("om 3 ĺrhundraden frĺn och med nu", t.format(new Date(3155692597470L * 3L)));
  120. }
  121. /*
  122. * Past
  123. */
  124. @Test
  125. public void testMomentsAgo() throws Exception
  126. {
  127. PrettyTime t = new PrettyTime(new Date(6000), locale);
  128. assertEquals("för ett par ögonblick sedan", t.format(new Date(0)));
  129. }
  130. @Test
  131. public void testMinutesAgo() throws Exception
  132. {
  133. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale);
  134. assertEquals("för 12 minuter sedan", t.format(new Date(0)));
  135. }
  136. @Test
  137. public void testHoursAgo() throws Exception
  138. {
  139. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale);
  140. assertEquals("för 3 timmar sedan", t.format(new Date(0)));
  141. }
  142. @Test
  143. public void testDaysAgo() throws Exception
  144. {
  145. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale);
  146. assertEquals("för 3 dagar sedan", t.format(new Date(0)));
  147. }
  148. @Test
  149. public void testWeeksAgo() throws Exception
  150. {
  151. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale);
  152. assertEquals("för 3 veckor sedan", t.format(new Date(0)));
  153. }
  154. @Test
  155. public void testMonthsAgo() throws Exception
  156. {
  157. PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale);
  158. assertEquals("för 3 mĺnader sedan", t.format(new Date(0)));
  159. }
  160. @Test
  161. public void testYearsAgo() throws Exception
  162. {
  163. PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale);
  164. assertEquals("för 3 ĺr sedan", t.format(new Date(0)));
  165. }
  166. @Test
  167. public void testDecadesAgo() throws Exception
  168. {
  169. PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale);
  170. assertEquals("för 3 ĺrtionden sedan", t.format(new Date(0)));
  171. }
  172. @Test
  173. public void testCenturiesAgo() throws Exception
  174. {
  175. PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale);
  176. assertEquals("för 3 ĺrhundraden sedan", t.format(new Date(0)));
  177. }
  178. }