01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wiki;
04:
05: import junit.framework.TestCase;
06: import java.util.regex.Matcher;
07: import java.util.*;
08:
09: public class VersionInfoTest extends TestCase {
10: public void testRegex() throws Exception {
11: Matcher match = VersionInfo.COMPEX_NAME_PATTERN
12: .matcher("01234567890123");
13: assertTrue(match.find());
14: assertEquals("01234567890123", match.group(2));
15:
16: match = VersionInfo.COMPEX_NAME_PATTERN
17: .matcher("Joe-01234567890123");
18: assertTrue(match.find());
19: assertEquals("Joe", match.group(1));
20: assertEquals("01234567890123", match.group(2));
21: }
22:
23: public void testGetVersionNumber() throws Exception {
24: assertEquals("01234567890123", VersionInfo
25: .getVersionNumber("01234567890123"));
26: assertEquals("01234567890123", VersionInfo
27: .getVersionNumber("Joe-01234567890123"));
28: assertEquals("09876543210987", VersionInfo
29: .getVersionNumber("Joe-09876543210987"));
30: }
31:
32: public void testSortVersions() throws Exception {
33: List list = new LinkedList();
34: VersionInfo toms = new VersionInfo("Tom-45678901234567");
35: VersionInfo anons = new VersionInfo("56789012345678");
36: VersionInfo jerrys = new VersionInfo("Jerry-01234567890123");
37: VersionInfo joes = new VersionInfo("Joe-43210987654321");
38: list.add(toms);
39: list.add(anons);
40: list.add(jerrys);
41: list.add(joes);
42:
43: Collections.sort(list);
44:
45: assertEquals(jerrys, list.get(0));
46: assertEquals(joes, list.get(1));
47: assertEquals(toms, list.get(2));
48: assertEquals(anons, list.get(3));
49: }
50:
51: public void testParts() throws Exception {
52: VersionInfo version = new VersionInfo("joe-20030101010101");
53: assertEquals("joe", version.getAuthor());
54: assertEquals("joe-20030101010101", version.getName());
55: }
56:
57: public void testGetCreationTime() throws Exception {
58: VersionInfo version = new VersionInfo("joe-20030101010101");
59: Date date = version.getCreationTime();
60: assertEquals("20030101010101", VersionInfo
61: .makeVersionTimeFormat().format(date));
62: }
63:
64: public void testGetAuthor() throws Exception {
65: checkAuthor("01234567890123", "");
66: checkAuthor("123-01234567890123", "");
67: checkAuthor("-123-01234567890123", "");
68: checkAuthor("user-01234567890123", "user");
69: checkAuthor("user-123-01234567890123", "user");
70: checkAuthor("abc123-123-01234567890123", "abc123");
71: checkAuthor("abc123efg-123-01234567890123", "abc123efg");
72: checkAuthor("joe <joe@blo.com>-123-01234567890123",
73: "joe <joe@blo.com>");
74: }
75:
76: private void checkAuthor(String versionName, String author)
77: throws Exception {
78: VersionInfo version = new VersionInfo(versionName);
79: assertEquals(author, version.getAuthor());
80: }
81:
82: }
|