Adding tests also for 3.0 version of the API
authorJaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:59:30 +0200
changeset 18277b3c0f1e4c3
parent 181 81d72f69fa42
child 183 e9f4bdb6a3f4
Adding tests also for 3.0 version of the API
samples/visitor/21-clientprovider/build.xml
samples/visitor/21-clientprovider/nbproject/project.xml
samples/visitor/21-clientprovider/src-test3.0/org/apidesign/test/visitor/PrintRealTest.java
     1.1 --- a/samples/visitor/21-clientprovider/build.xml	Sat Jun 14 09:59:27 2008 +0200
     1.2 +++ b/samples/visitor/21-clientprovider/build.xml	Sat Jun 14 09:59:30 2008 +0200
     1.3 @@ -21,18 +21,14 @@
     1.4              <param name="cp" value="build/api1.0/classes:${junit.jar}"/>
     1.5          </antcall>
     1.6  
     1.7 -        <echo level="info" message="Next compilation will fails, as adding methods into interface is not binary compatible"/>
     1.8 -        <antcall target="-build-one">
     1.9 -            <param name="version" value="test"/>
    1.10 -            <param name="out" value="will-not-compile"/>
    1.11 -            <param name="cp" value="build/api2.0/classes:${junit.jar}"/>
    1.12 -            <param name="failonerror" value="false"/>
    1.13 -        </antcall>
    1.14 -
    1.15          <antcall target="-build-one">
    1.16              <param name="version" value="test2.0"/>
    1.17              <param name="cp" value="build/api2.0/classes:build/test/classes:${junit.jar}"/>
    1.18          </antcall>
    1.19 +        <antcall target="-build-one">
    1.20 +            <param name="version" value="test3.0"/>
    1.21 +            <param name="cp" value="build/api3.0/classes:build/test/classes:build/test2.0/classes:${junit.jar}"/>
    1.22 +        </antcall>
    1.23      </target>
    1.24      
    1.25      <target name="test" depends="build">
    1.26 @@ -50,6 +46,12 @@
    1.27              <param name="extra.cp" value="build/test/classes"/>
    1.28              <param name="version" value="api2.0"/>
    1.29          </antcall>
    1.30 +        <echo level="info" message="Using old Number with new visitors"/>
    1.31 +        <antcall target="-run-one">
    1.32 +            <param name="test" value="test3.0"/>
    1.33 +            <param name="extra.cp" value="build/test/classes:build/test2.0/classes:"/>
    1.34 +            <param name="version" value="api3.0"/>
    1.35 +        </antcall>
    1.36      </target>
    1.37      
    1.38      <!-- support methods -->
     2.1 --- a/samples/visitor/21-clientprovider/nbproject/project.xml	Sat Jun 14 09:59:27 2008 +0200
     2.2 +++ b/samples/visitor/21-clientprovider/nbproject/project.xml	Sat Jun 14 09:59:30 2008 +0200
     2.3 @@ -40,6 +40,12 @@
     2.4                      <location>src-test2.0</location>
     2.5                      <encoding>UTF-8</encoding>
     2.6                  </source-folder>
     2.7 +                <source-folder>
     2.8 +                    <label>test-3.0</label>
     2.9 +                    <type>java</type>
    2.10 +                    <location>src-test3.0</location>
    2.11 +                    <encoding>UTF-8</encoding>
    2.12 +                </source-folder>
    2.13              </folders>
    2.14              <ide-actions>
    2.15                  <action name="build">
    2.16 @@ -66,20 +72,24 @@
    2.17                          <location>src-api1.0</location>
    2.18                      </source-folder>
    2.19                      <source-folder style="packages">
    2.20 +                        <label>Usage of the API</label>
    2.21 +                        <location>src-test</location>
    2.22 +                    </source-folder>
    2.23 +                    <source-folder style="packages">
    2.24                          <label>API Version 2.0</label>
    2.25                          <location>src-api2.0</location>
    2.26                      </source-folder>
    2.27                      <source-folder style="packages">
    2.28 +                        <label>Usage of 2.0 structures with 1.0 visitor</label>
    2.29 +                        <location>src-test2.0</location>
    2.30 +                    </source-folder>
    2.31 +                    <source-folder style="packages">
    2.32                          <label>API Version 3.0</label>
    2.33                          <location>src-api3.0</location>
    2.34                      </source-folder>
    2.35                      <source-folder style="packages">
    2.36 -                        <label>Usage of the API</label>
    2.37 -                        <location>src-test</location>
    2.38 -                    </source-folder>
    2.39 -                    <source-folder style="packages">
    2.40 -                        <label>Usage of new structures with old visitor</label>
    2.41 -                        <location>src-test2.0</location>
    2.42 +                        <label>Usage of 3.0 visitor</label>
    2.43 +                        <location>src-test3.0</location>
    2.44                      </source-folder>
    2.45                      <source-file>
    2.46                          <location>build.xml</location>
    2.47 @@ -116,6 +126,11 @@
    2.48                  <classpath mode="compile">src-api2.0:src-test:../../libs/dist/junit-4.4.jar</classpath>
    2.49                  <source-level>1.5</source-level>
    2.50              </compilation-unit>
    2.51 +            <compilation-unit>
    2.52 +                <package-root>src-test3.0</package-root>
    2.53 +                <classpath mode="compile">src-api3.0:src-test:src-test2.0:../../libs/dist/junit-4.4.jar</classpath>
    2.54 +                <source-level>1.5</source-level>
    2.55 +            </compilation-unit>
    2.56          </java-data>
    2.57      </configuration>
    2.58  </project>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/samples/visitor/21-clientprovider/src-test3.0/org/apidesign/test/visitor/PrintRealTest.java	Sat Jun 14 09:59:30 2008 +0200
     3.3 @@ -0,0 +1,83 @@
     3.4 +package org.apidesign.test.visitor;
     3.5 +
     3.6 +import org.apidesign.test.visitor.PrintTest.PrintVisitor;
     3.7 +import static junit.framework.Assert.*;
     3.8 +import org.apidesign.visitor.Language.Expression;
     3.9 +import org.apidesign.visitor.Language.Minus;
    3.10 +import org.apidesign.visitor.Language.Number;
    3.11 +import org.apidesign.visitor.Language.Plus;
    3.12 +import org.apidesign.visitor.Language.Real;
    3.13 +import org.apidesign.visitor.Language.Visitor;
    3.14 +import org.junit.Test;
    3.15 +
    3.16 +public class PrintRealTest {
    3.17 +    @Test public void printOneMinusTwo() {
    3.18 +        Real one = newReal(1);
    3.19 +        Real two = newReal(2);
    3.20 +        Expression plus = PrintOfMinusStructureTest.newMinus(one, two);
    3.21 +        
    3.22 +        PrintVisitor print = new PrintVisitor();
    3.23 +        plus.visit(print.dispatch);
    3.24 +        
    3.25 +        assertEquals("1.0 - 2.0", print.sb.toString());
    3.26 +    }
    3.27 +    
    3.28 +    @Test public void visitorReadyForVersion3_0() {
    3.29 +        class PrintVisitor3_0 implements Visitor.Version3_0 {
    3.30 +            StringBuffer sb = new StringBuffer();
    3.31 +            Visitor dispatch = Visitor.create(this);
    3.32 +
    3.33 +            public boolean visitUnknown(Expression exp) {
    3.34 +                sb.append("unknown");
    3.35 +                return true;
    3.36 +            }
    3.37 +
    3.38 +            public void visitPlus(Plus s) {
    3.39 +                s.getFirst().visit(dispatch);
    3.40 +                sb.append(" + ");
    3.41 +                s.getSecond().visit(dispatch);
    3.42 +            }
    3.43 +
    3.44 +            public void visitMinus(Minus m) {
    3.45 +                m.getFirst().visit(dispatch);
    3.46 +                sb.append(" - ");
    3.47 +                m.getSecond().visit(dispatch);
    3.48 +            }
    3.49 +
    3.50 +            public void visitReal(Real r) {
    3.51 +                sb.append(r.getValue());
    3.52 +            }
    3.53 +        }
    3.54 +        
    3.55 +        Number one = PrintTest.newNumber(1);
    3.56 +        Number two = PrintTest.newNumber(2);
    3.57 +        Expression plus = PrintOfMinusStructureTest.newMinus(one, two);
    3.58 +        
    3.59 +        PrintVisitor3_0 print = new PrintVisitor3_0();
    3.60 +        plus.visit(print.dispatch);
    3.61 +        
    3.62 +        assertEquals("1.0 - 2.0", print.sb.toString());
    3.63 +
    3.64 +        Real five = newReal(5);
    3.65 +        Real three = newReal(3);
    3.66 +        Expression realPlus = PrintOfMinusStructureTest.newMinus(five, three);
    3.67 +        
    3.68 +        PrintVisitor3_0 printReal = new PrintVisitor3_0();
    3.69 +        realPlus.visit(printReal.dispatch);
    3.70 +        
    3.71 +        assertEquals("5.0 - 3.0", printReal.sb.toString());
    3.72 +        
    3.73 +    }
    3.74 +    
    3.75 +    public static Real newReal(final double value) {
    3.76 +        return new Real() {
    3.77 +            public double getValue() {
    3.78 +                return value;
    3.79 +            }
    3.80 +
    3.81 +            public void visit(Visitor v) {
    3.82 +                v.dispatchReal(this);
    3.83 +            }
    3.84 +        };
    3.85 +    }
    3.86 +}