javaclass

Changeset

20:5cf60a47f251
2004-11-10 Paul Boddie raw files shortlog changelog graph Expanded the exception test. Added construction of values in the value test. Added a test of subclass initialisation.
tests/ExceptionTest.java (file) tests/Value.java (file) tests/ValueSubclass.java (file)
     1.1 --- a/tests/ExceptionTest.java	Tue Nov 09 20:05:58 2004 +0100
     1.2 +++ b/tests/ExceptionTest.java	Wed Nov 10 15:54:09 2004 +0100
     1.3 @@ -1,18 +1,51 @@
     1.4  public class ExceptionTest {
     1.5  
     1.6 -    public int testCatch() {
     1.7 -        try {
     1.8 +    public int testThrow(int x) throws java.lang.Exception {
     1.9 +        if (x == 0) {
    1.10              throw new MyException();
    1.11 +        } else if (x == 1) {
    1.12 +            throw new MyOtherException();
    1.13 +        } else {
    1.14 +            return 1;
    1.15 +        }
    1.16 +    }
    1.17 +
    1.18 +    public int testCatch(int x) {
    1.19 +        try {
    1.20 +            if (x == 0) {
    1.21 +                throw new MyException();
    1.22 +            } else if (x == 1) {
    1.23 +                throw new MyOtherException();
    1.24 +            } else {
    1.25 +                x = 1;
    1.26 +            }
    1.27          } catch (MyException exc) {
    1.28 -            return 1;
    1.29 +            x = 3;
    1.30 +        } catch (MyOtherException exc) {
    1.31 +            x = 2;
    1.32 +        }
    1.33 +        return x;
    1.34 +    }
    1.35 +
    1.36 +    public int testIncomingCatch(int x) {
    1.37 +        try {
    1.38 +            return testThrow(x);
    1.39 +        } catch (MyException exc) {
    1.40 +            return 3;
    1.41 +        } catch (MyOtherException exc) {
    1.42 +            return 2;
    1.43 +        } catch (java.lang.Exception exc) {
    1.44 +            return -1; // Should be unreachable, really.
    1.45          }
    1.46      }
    1.47  
    1.48      public int testFinally(int x) throws java.lang.Exception {
    1.49          try {
    1.50              if (x == 0) {
    1.51 +                x = 3;
    1.52                  throw new MyException();
    1.53              } else if (x == 1) {
    1.54 +                x = 2;
    1.55                  throw new MyOtherException();
    1.56              }
    1.57          } finally {
     2.1 --- a/tests/Value.java	Tue Nov 09 20:05:58 2004 +0100
     2.2 +++ b/tests/Value.java	Wed Nov 10 15:54:09 2004 +0100
     2.3 @@ -30,6 +30,10 @@
     2.4      public int add(int value) {
     2.5          return this.value + value;
     2.6      }
     2.7 +
     2.8 +    public Value newValue() {
     2.9 +        return new Value(this.getValue());
    2.10 +    }
    2.11  }
    2.12  
    2.13  // vim: tabstop=4 expandtab shiftwidth=4
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tests/ValueSubclass.java	Wed Nov 10 15:54:09 2004 +0100
     3.3 @@ -0,0 +1,6 @@
     3.4 +public class ValueSubclass extends Value {
     3.5 +
     3.6 +    public ValueSubclass(int x) {
     3.7 +        super(x);
     3.8 +    }
     3.9 +}