|
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 implements SensibleClone<InsufficientMagicException> { |
| 42 | + public InsufficientMagicException(String message) { |
| 43 | + super(message); |
| 44 | + } |
| 45 | + |
| 46 | + public InsufficientMagicException sensibleClone() { |
| 47 | + return new InsufficientMagicException(getMessage()); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + |
42 | 52 | public static TestSuite suite() |
43 | 53 | { |
44 | 54 | TestSuite suite = new TestSuite("valueOrEx"); |
45 | 55 | suite.addTestSuite(ValueOrExceptionTest.class); |
46 | 56 | return suite; |
47 | 57 | } |
48 | 58 |
|
49 | | - public void testStoresValue() throws IOException { |
| 59 | + public void testStoresValue() throws InsufficientMagicException { |
50 | 60 | Integer value = new Integer(3); |
51 | | - ValueOrException<Integer, IOException> valueOrEx = ValueOrException.<Integer, IOException>makeValue(value); |
| 61 | + ValueOrException<Integer, InsufficientMagicException> valueOrEx = ValueOrException.<Integer, InsufficientMagicException>makeValue(value); |
52 | 62 |
|
53 | 63 | Integer returnedValue = valueOrEx.getValue(); |
54 | 64 | assertTrue(returnedValue == value); |
55 | 65 | } |
56 | 66 |
|
57 | | - public void testStoresException() { |
58 | | - IOException exception = new IOException("dummy message"); |
59 | | - ValueOrException<Integer, IOException> valueOrEx = ValueOrException.<Integer, IOException>makeException(exception); |
| 67 | + public void testClonesException() { |
| 68 | + InsufficientMagicException exception = new InsufficientMagicException("dummy message"); |
| 69 | + ValueOrException<Integer, InsufficientMagicException> valueOrEx = ValueOrException.<Integer, InsufficientMagicException>makeException(exception); |
60 | 70 |
|
61 | 71 | try { |
62 | 72 | valueOrEx.getValue(); |
63 | 73 | fail("Expected exception"); |
64 | | - } catch(IOException returnedException) { |
65 | | - assertTrue(returnedException == exception); |
| 74 | + } catch(InsufficientMagicException returnedException) { |
| 75 | + assertTrue(returnedException != exception); |
| 76 | + assertEquals(returnedException.getMessage(), exception.getMessage()); |
| 77 | + boolean inGetValue = false; |
| 78 | + for(StackTraceElement elt : returnedException.getStackTrace()) |
| 79 | + inGetValue |= "getValue".equals(elt.getMethodName()); |
| 80 | + assertTrue(inGetValue); |
66 | 81 | } |
67 | 82 | } |
68 | 83 | } |
0 commit comments