KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > test > snip > NiceTimeTest


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25
26 package org.snipsnap.test.snip;
27
28 import org.snipsnap.snip.Modified;
29
30 import java.sql.Timestamp JavaDoc;
31
32 import junit.framework.Test;
33 import junit.framework.TestSuite;
34
35 public class NiceTimeTest extends SnipTestSupport {
36   private final static long ONE_SECOND = 1000;
37   private final static long ONE_MINUTE = 60 * ONE_SECOND;
38   private final static long ONE_HOUR = 60 * ONE_MINUTE;
39   private final static long ONE_DAY = 24 * ONE_HOUR;
40   private final static long ONE_YEAR = 365 * ONE_DAY;
41
42   private final static long NOW = ONE_YEAR;
43
44   public NiceTimeTest(String JavaDoc name) {
45     super(name);
46   }
47   protected void setUp() throws Exception JavaDoc {
48     super.setUp();
49   }
50
51   public static Test suite() {
52     return new TestSuite(ImageTest.class);
53   }
54
55   public void testNiceSeconds() {
56     assertEquals("just a blink of an eye", Modified.getNiceTime(NOW, NOW - ONE_SECOND));
57   }
58
59   public void testNiceMinutes() {
60     assertEquals("one minute", Modified.getNiceTime(NOW, NOW - (ONE_MINUTE + 30 * ONE_SECOND)));
61     assertEquals("5 minutes", Modified.getNiceTime(NOW, NOW - (5 * ONE_MINUTE)));
62   }
63
64   public void testNiceHours() {
65     assertEquals("one hour", Modified.getNiceTime(NOW, NOW - ONE_HOUR));
66     assertEquals("one hour and one minute", Modified.getNiceTime(NOW, NOW - (ONE_HOUR + ONE_MINUTE)));
67     assertEquals("one hour and 5 minutes", Modified.getNiceTime(NOW, NOW - (ONE_HOUR + 5 * ONE_MINUTE)));
68   }
69
70   public void testNiceDays() {
71     assertEquals("one day", Modified.getNiceTime(NOW, NOW - ONE_DAY));
72     assertEquals("5 days", Modified.getNiceTime(NOW, NOW - 5 * ONE_DAY));
73   }
74
75   public void testNiceYears() {
76     assertEquals("one year", Modified.getNiceTime(NOW, NOW - ONE_YEAR));
77     assertEquals("2 years", Modified.getNiceTime(NOW, NOW - 2 * ONE_YEAR));
78     assertEquals("one year and one day", Modified.getNiceTime(NOW, NOW - (ONE_YEAR + ONE_DAY)));
79     assertEquals("5 years and 4 days", Modified.getNiceTime(NOW, NOW - (5 * ONE_YEAR + 4 * ONE_DAY)));
80   }
81
82 }
83
84
Popular Tags