|
1 | 1 | package quickfix; |
2 | 2 |
|
3 | 3 | import static org.junit.Assert.*; |
| 4 | +import static org.mockito.Mockito.doReturn; |
| 5 | +import static org.mockito.Mockito.mock; |
| 6 | +import static org.mockito.Mockito.verify; |
| 7 | +import static org.mockito.Mockito.verifyNoMoreInteractions; |
4 | 8 | import static quickfix.FixVersions.*; |
5 | 9 | import static quickfix.field.ApplVerID.*; |
6 | 10 |
|
|
9 | 13 | import org.junit.runner.RunWith; |
10 | 14 | import org.junit.runners.Parameterized; |
11 | 15 | import quickfix.field.*; |
| 16 | +import quickfix.fix44.MessageFactory; |
12 | 17 | import quickfix.test.util.ExpectedTestFailure; |
13 | 18 |
|
14 | 19 | /** |
@@ -81,6 +86,24 @@ protected void execute() throws Throwable { |
81 | 86 | factory.create(BEGINSTRING_FIX40, MsgType.MARKET_DATA_SNAPSHOT_FULL_REFRESH, NoMDEntries.FIELD)); |
82 | 87 | } |
83 | 88 |
|
| 89 | + @Test |
| 90 | + public void testContextClassLoaderFactory() throws ClassNotFoundException { |
| 91 | + ClassLoader customLoader = mock(ClassLoader.class); |
| 92 | + doReturn(MessageFactory.class).when(customLoader).loadClass("foo.DefaultMessageFactory"); |
| 93 | + |
| 94 | + ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); |
| 95 | + Thread.currentThread().setContextClassLoader(customLoader); |
| 96 | + |
| 97 | + try { |
| 98 | + factory.addFactory(BEGINSTRING_FIX44, "foo.DefaultMessageFactory"); |
| 99 | + } finally { |
| 100 | + Thread.currentThread().setContextClassLoader(previousClassLoader); |
| 101 | + } |
| 102 | + |
| 103 | + verify(customLoader).loadClass("foo.DefaultMessageFactory"); |
| 104 | + verifyNoMoreInteractions(customLoader); |
| 105 | + } |
| 106 | + |
84 | 107 | private static void assertMessage(Class<?> expectedMessageClass, String expectedMessageType, Message message) throws Exception { |
85 | 108 | assertEquals(expectedMessageClass, message.getClass()); |
86 | 109 | assertEquals(expectedMessageType, message.getHeader().getString(MsgType.FIELD)); |
|
0 commit comments