1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.core.container.ri.client.versioning.test;
22
23 import java.io.StringReader;
24 import junit.framework.Assert;
25 import junit.framework.TestCase;
26 import org.jdtaus.core.container.ri.client.versioning.ParseException;
27 import org.jdtaus.core.container.ri.client.versioning.Token;
28 import org.jdtaus.core.container.ri.client.versioning.VersionParser;
29
30
31
32
33
34
35
36 public class VersionParserTest extends TestCase
37 {
38
39 public void testParseable() throws Exception
40 {
41 this.assertValidVersion( "1" );
42 this.assertValidVersion( "1.1" );
43 this.assertValidVersion( "SNAPSHOT" );
44 this.assertValidVersion( "RELEASE" );
45 this.assertValidVersion( "LATEST" );
46 this.assertValidVersion( "4aug2007r7-dev" );
47 this.assertValidVersion( "1.0-alpha-10-stable-1" );
48 }
49
50 public void testUnparseable() throws Exception
51 {
52 this.assertInvalidVersion( "." );
53 }
54
55 protected void assertValidVersion( final String version ) throws Exception
56 {
57 final VersionParser parser =
58 new VersionParser( new StringReader( version ) );
59
60 final Token[] tokens = parser.parse();
61 final StringBuffer buf = new StringBuffer().append( "Parses '" +
62 version + "' to" );
63
64 for ( int i = 0; i < tokens.length; i++ )
65 {
66 buf.append( "\n\t" ).append( "token[" ).append( i ).append( "]=" ).
67 append( tokens[i].image );
68
69 }
70
71 System.out.println( buf.toString() );
72 }
73
74 protected void assertInvalidVersion( final String version )
75 {
76 try
77 {
78 final VersionParser parser =
79 new VersionParser( new StringReader( version ) );
80
81 parser.parse();
82 fail( "Could parse '" + version + "'." );
83 }
84 catch ( ParseException e )
85 {
86 Assert.assertNotNull( e.getMessage() );
87 System.out.println( e.toString() );
88 }
89 }
90
91 }