carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/ExpectException.java
equal
deleted
inserted
replaced
|
1 /** |
|
2 * |
|
3 */ |
|
4 package org.junit.internal.runners.statements; |
|
5 |
|
6 import org.junit.runners.model.Statement; |
|
7 |
|
8 |
|
9 public class ExpectException extends Statement { |
|
10 private Statement fNext; |
|
11 private final Class<? extends Throwable> fExpected; |
|
12 |
|
13 public ExpectException(Statement next, Class<? extends Throwable> expected) { |
|
14 fNext= next; |
|
15 fExpected= expected; |
|
16 } |
|
17 |
|
18 @Override |
|
19 public void evaluate() throws Exception { |
|
20 boolean complete = false; |
|
21 try { |
|
22 fNext.evaluate(); |
|
23 complete = true; |
|
24 } catch (Throwable e) { |
|
25 if (!fExpected.isAssignableFrom(e.getClass())) { |
|
26 String message= "Unexpected exception, expected<" |
|
27 + fExpected.getName() + "> but was<" |
|
28 + e.getClass().getName() + ">"; |
|
29 throw new Exception(message, e); |
|
30 } |
|
31 } |
|
32 if (complete) |
|
33 throw new AssertionError("Expected exception: " |
|
34 + fExpected.getName()); |
|
35 } |
|
36 } |