PageRenderTime 52ms CodeModel.GetById 16ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/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
Possible License(s): Apache-2.0
  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 */
 16package org.ocpsoft.prettytime;
 17import static org.junit.Assert.assertEquals;
 18
 19import java.text.SimpleDateFormat;
 20import java.util.Date;
 21import java.util.Locale;
 22
 23import org.junit.Before;
 24import org.junit.Test;
 25import org.ocpsoft.prettytime.PrettyTime;
 26
 27public class PrettyTimeI18n_SE_Test {
 28	private Locale locale;
 29    private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
 30
 31    @Before
 32    public void setUp() throws Exception
 33    {
 34        locale = new Locale("se");
 35    }
 36
 37    @Test
 38    public void testPrettyTime()
 39    {
 40        PrettyTime p = new PrettyTime(locale);
 41        assertEquals(p.format(new Date()), "om ett par ögonblick frĺn nu");
 42    }
 43
 44    @Test
 45    public void testPrettyTimeCenturies()
 46    {
 47        PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale);
 48        assertEquals("för 3 ĺrhundraden sedan", p.format(new Date(0)));
 49
 50        p = new PrettyTime(new Date(0), locale);
 51        assertEquals("om 3 ĺrhundraden frĺn och med nu", p.format(new Date(3155692597470L * 3L)));
 52    }
 53
 54    @Test
 55    public void testCeilingInterval() throws Exception
 56    {
 57        Date then = format.parse("20/5/2009");
 58        Date ref = format.parse("17/6/2009");
 59        PrettyTime t = new PrettyTime(ref, locale);
 60        assertEquals("för 1 mĺnad sedan", t.format(then));
 61    }
 62
 63    @Test
 64    public void testNullDate() throws Exception
 65    {
 66        PrettyTime t = new PrettyTime(locale);
 67        Date date = null;
 68        assertEquals("om ett par ögonblick frĺn nu", t.format(date));
 69    }
 70
 71    @Test
 72    public void testRightNow() throws Exception
 73    {
 74        PrettyTime t = new PrettyTime(locale);
 75        assertEquals("om ett par ögonblick frĺn nu", t.format(new Date()));
 76    }
 77
 78    @Test
 79    public void testRightNowVariance() throws Exception
 80    {
 81        PrettyTime t = new PrettyTime(new Date(0), locale);
 82        assertEquals("om ett par ögonblick frĺn nu", t.format(new Date(600)));
 83    }
 84
 85    @Test
 86    public void testMinutesFromNow() throws Exception
 87    {
 88        PrettyTime t = new PrettyTime(new Date(0), locale);
 89        assertEquals("om 12 minuter frĺn och med nu", t.format(new Date(1000 * 60 * 12)));
 90    }
 91
 92    @Test
 93    public void testHoursFromNow() throws Exception
 94    {
 95        PrettyTime t = new PrettyTime(new Date(0), locale);
 96        assertEquals("om 3 timmar frĺn och med nu", t.format(new Date(1000 * 60 * 60 * 3)));
 97    }
 98
 99    @Test
100    public void testDaysFromNow() throws Exception
101    {
102        PrettyTime t = new PrettyTime(new Date(0), locale);
103        assertEquals("om 3 dagar frĺn och med nu", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
104    }
105
106    @Test
107    public void testWeeksFromNow() throws Exception
108    {
109        PrettyTime t = new PrettyTime(new Date(0), locale);
110        assertEquals("om 3 veckor frĺn och med nu", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
111    }
112
113    @Test
114    public void testMonthsFromNow() throws Exception
115    {
116        PrettyTime t = new PrettyTime(new Date(0), locale);
117        assertEquals("om 3 mĺnader frĺn och med nu", t.format(new Date(2629743830L * 3L)));
118    }
119
120    @Test
121    public void testYearsFromNow() throws Exception
122    {
123        PrettyTime t = new PrettyTime(new Date(0), locale);
124        assertEquals("om 3 ĺr frĺn och med nu", t.format(new Date(2629743830L * 12L * 3L)));
125    }
126
127    @Test
128    public void testDecadesFromNow() throws Exception
129    {
130        PrettyTime t = new PrettyTime(new Date(0), locale);
131        assertEquals("om 3 ĺrtionden frĺn och med nu", t.format(new Date(315569259747L * 3L)));
132    }
133
134    @Test
135    public void testCenturiesFromNow() throws Exception
136    {
137        PrettyTime t = new PrettyTime(new Date(0), locale);
138        assertEquals("om 3 ĺrhundraden frĺn och med nu", t.format(new Date(3155692597470L * 3L)));
139    }
140
141    /*
142     * Past
143     */
144    @Test
145    public void testMomentsAgo() throws Exception
146    {
147        PrettyTime t = new PrettyTime(new Date(6000), locale);
148        assertEquals("för ett par ögonblick sedan", t.format(new Date(0)));
149    }
150
151    @Test
152    public void testMinutesAgo() throws Exception
153    {
154        PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale);
155        assertEquals("för 12 minuter sedan", t.format(new Date(0)));
156    }
157
158    @Test
159    public void testHoursAgo() throws Exception
160    {
161        PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale);
162        assertEquals("för 3 timmar sedan", t.format(new Date(0)));
163    }
164
165    @Test
166    public void testDaysAgo() throws Exception
167    {
168        PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale);
169        assertEquals("för 3 dagar sedan", t.format(new Date(0)));
170    }
171
172    @Test
173    public void testWeeksAgo() throws Exception
174    {
175        PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale);
176        assertEquals("för 3 veckor sedan", t.format(new Date(0)));
177    }
178
179    @Test
180    public void testMonthsAgo() throws Exception
181    {
182        PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale);
183        assertEquals("för 3 mĺnader sedan", t.format(new Date(0)));
184    }
185
186    @Test
187    public void testYearsAgo() throws Exception
188    {
189        PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale);
190        assertEquals("för 3 ĺr sedan", t.format(new Date(0)));
191    }
192
193    @Test
194    public void testDecadesAgo() throws Exception
195    {
196        PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale);
197        assertEquals("för 3 ĺrtionden sedan", t.format(new Date(0)));
198    }
199
200    @Test
201    public void testCenturiesAgo() throws Exception
202    {
203        PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale);
204        assertEquals("för 3 ĺrhundraden sedan", t.format(new Date(0)));
205    }
206}