ServiceUtil { public static Service rewriteConnectionsForTesting(Service service) throws CoreException { Service rewritten = service; if (rewritten instanceof ConnectedService) { ConnectedService connectedService = (ConnectedService) rewritten; connectedService.setConnection(cloneForTesting(connectedService.getConnection())); } if (rewritten instanceof ServiceCollection) { rewriteConnectionsForTesting((ServiceCollection) rewritten); } if (rewritten instanceof ServiceWrapper) { rewriteConnectionsForTesting((ServiceWrapper) rewritten); } return rewritten; }  static Service[] discardNulls(Service... services); static Service rewriteConnectionsForTesting(Service service);  }
@Test public void testRewriteForTesting_NoConnection() throws Exception { NullService nullService = new NullService(); JdbcServiceList jdbcService = new JdbcServiceList(); StatelessServiceWrapper stateless = new StatelessServiceWrapper(new StandaloneProducer()); assertTrue(nullService == rewriteConnectionsForTesting(nullService)); assertTrue(jdbcService == rewriteConnectionsForTesting(jdbcService)); assertTrue(stateless == rewriteConnectionsForTesting(stateless)); ServiceList nestedList = new ServiceList(); ServiceList list = new ServiceList(); list.add(nestedList); assertTrue(list == rewriteConnectionsForTesting(list)); }
@Test public void testRewriteForTesting_Connection() throws Exception { NullConnection conn = new NullConnection(); StandaloneProducer service = new StandaloneProducer(conn, new NullMessageProducer()); StandaloneProducer rewritten = ((StandaloneProducer) rewriteConnectionsForTesting(service)); assertNotSame(conn, rewritten.getConnection()); }
@Test public void testRewriteForTesting_RetriesConnection() throws Exception { MockAllowsRetriesConnection conn = new MockAllowsRetriesConnection(55); StandaloneProducer service = new StandaloneProducer(conn, new NullMessageProducer()); StandaloneProducer rewritten = ((StandaloneProducer) rewriteConnectionsForTesting(service)); assertNotSame(conn, rewritten.getConnection()); assertNotSame(55, ((AllowsRetriesConnection) rewritten.getConnection()).getConnectionAttempts()); }