4141public class DefaultApacheHttpClientConnectionManagerFactoryTests {
4242
4343 @ Test
44- public void newConnectionManager () throws Exception {
44+ public void newConnectionManager () {
4545 HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory ()
4646 .newConnectionManager (false , 2 , 6 );
4747 then (((PoolingHttpClientConnectionManager ) connectionManager )
4848 .getDefaultMaxPerRoute ()).isEqualTo (6 );
4949 then (((PoolingHttpClientConnectionManager ) connectionManager ).getMaxTotal ())
5050 .isEqualTo (2 );
51- Object pool = getField (((PoolingHttpClientConnectionManager ) connectionManager ),
52- "pool" );
51+ Object pool = getField ((connectionManager ), "pool" );
5352 then ((Long ) getField (pool , "timeToLive" )).isEqualTo (new Long (-1 ));
54- TimeUnit timeUnit = getField (pool , "tunit " );
53+ TimeUnit timeUnit = getField (pool , "timeUnit " );
5554 then (timeUnit ).isEqualTo (TimeUnit .MILLISECONDS );
5655 }
5756
5857 @ Test
59- public void newConnectionManagerWithTTL () throws Exception {
58+ public void newConnectionManagerWithTTL () {
6059 HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory ()
6160 .newConnectionManager (false , 2 , 6 , 56L , TimeUnit .DAYS , null );
6261 then (((PoolingHttpClientConnectionManager ) connectionManager )
6362 .getDefaultMaxPerRoute ()).isEqualTo (6 );
6463 then (((PoolingHttpClientConnectionManager ) connectionManager ).getMaxTotal ())
6564 .isEqualTo (2 );
66- Object pool = getField (((PoolingHttpClientConnectionManager ) connectionManager ),
67- "pool" );
65+ Object pool = getField ((connectionManager ), "pool" );
6866 then ((Long ) getField (pool , "timeToLive" )).isEqualTo (new Long (56 ));
69- TimeUnit timeUnit = getField (pool , "tunit " );
67+ TimeUnit timeUnit = getField (pool , "timeUnit " );
7068 then (timeUnit ).isEqualTo (TimeUnit .DAYS );
7169 }
7270
7371 @ Test
74- public void newConnectionManagerWithSSL () throws Exception {
72+ public void newConnectionManagerWithSSL () {
7573 HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory ()
7674 .newConnectionManager (false , 2 , 6 );
7775
@@ -82,7 +80,7 @@ public void newConnectionManagerWithSSL() throws Exception {
8280 }
8381
8482 @ Test
85- public void newConnectionManagerWithDisabledSSLValidation () throws Exception {
83+ public void newConnectionManagerWithDisabledSSLValidation () {
8684 HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory ()
8785 .newConnectionManager (true , 2 , 6 );
8886
@@ -112,6 +110,10 @@ private X509TrustManager getX509TrustManager(
112110 @ SuppressWarnings ("unchecked" )
113111 protected <T > T getField (Object target , String name ) {
114112 Field field = ReflectionUtils .findField (target .getClass (), name );
113+ if (field == null ) {
114+ throw new IllegalArgumentException (
115+ "Can not find field " + name + " in " + target .getClass ());
116+ }
115117 ReflectionUtils .makeAccessible (field );
116118 Object value = ReflectionUtils .getField (field , target );
117119 return (T ) value ;
0 commit comments