|
30 | 30 | // |
31 | 31 | package com.rabbitmq.client.test; |
32 | 32 |
|
33 | | -import java.io.IOException; |
34 | | - |
35 | 33 | import junit.framework.TestCase; |
36 | 34 | import junit.framework.TestSuite; |
37 | 35 |
|
38 | 36 | import com.rabbitmq.utility.ValueOrException; |
| 37 | +import com.rabbitmq.utility.SensibleClone; |
39 | 38 |
|
40 | 39 |
|
41 | 40 | public class ValueOrExceptionTest extends TestCase { |
| 41 | + public static class InsufficientMagicException extends Exception |
| 42 | + implements SensibleClone<InsufficientMagicException> { |
| 43 | + public InsufficientMagicException(String message) { |
| 44 | + super(message); |
| 45 | + } |
| 46 | + |
| 47 | + public InsufficientMagicException sensibleClone() { |
| 48 | + return new InsufficientMagicException(getMessage()); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + |
42 | 53 | public static TestSuite suite() |
43 | 54 | { |
44 | 55 | TestSuite suite = new TestSuite("valueOrEx"); |
45 | 56 | suite.addTestSuite(ValueOrExceptionTest.class); |
46 | 57 | return suite; |
47 | 58 | } |
48 | 59 |
|
49 | | - public void testStoresValue() throws IOException { |
| 60 | + public void testStoresValue() throws InsufficientMagicException { |
50 | 61 | Integer value = new Integer(3); |
51 | | - ValueOrException<Integer, IOException> valueOrEx = ValueOrException.<Integer, IOException>makeValue(value); |
52 | 62 |
|
| 63 | + ValueOrException<Integer, InsufficientMagicException> valueOrEx = |
| 64 | + ValueOrException.<Integer, InsufficientMagicException>makeValue(value); |
| 65 | + |
53 | 66 | Integer returnedValue = valueOrEx.getValue(); |
54 | 67 | assertTrue(returnedValue == value); |
55 | 68 | } |
56 | 69 |
|
57 | | - public void testStoresException() { |
58 | | - IOException exception = new IOException("dummy message"); |
59 | | - ValueOrException<Integer, IOException> valueOrEx = ValueOrException.<Integer, IOException>makeException(exception); |
| 70 | + public void testClonesException() { |
| 71 | + InsufficientMagicException exception = |
| 72 | + new InsufficientMagicException("dummy message"); |
| 73 | + ValueOrException<Integer, InsufficientMagicException> valueOrEx |
| 74 | + = ValueOrException.makeException(exception); |
60 | 75 |
|
61 | 76 | try { |
62 | 77 | valueOrEx.getValue(); |
63 | 78 | fail("Expected exception"); |
64 | | - } catch(IOException returnedException) { |
65 | | - assertTrue(returnedException == exception); |
| 79 | + } catch(InsufficientMagicException returnedException) { |
| 80 | + assertTrue(returnedException != exception); |
| 81 | + assertEquals(returnedException.getMessage(), exception.getMessage()); |
| 82 | + boolean inGetValue = false; |
| 83 | + for(StackTraceElement elt : returnedException.getStackTrace()) |
| 84 | + inGetValue |= "getValue".equals(elt.getMethodName()); |
| 85 | + assertTrue(inGetValue); |
66 | 86 | } |
67 | 87 | } |
68 | 88 | } |
0 commit comments