package org.springframework.cloud.commons.httpclient;

import java.lang.reflect.Field;
import java.util.concurrent.TimeUnit;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.junit.Test;
import org.springframework.util.ReflectionUtils;

import static org.junit.Assert.*;

/**
 * @author Ryan Baxter
 */
public class DefaultApacheHttpClientConnectionManagerFactoryTests {
	@Test
	public void newConnectionManager() throws Exception {
		HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
				.newConnectionManager(false, 2, 6);
		assertEquals(6, ((PoolingHttpClientConnectionManager) connectionManager)
				.getDefaultMaxPerRoute());
		assertEquals(2,
				((PoolingHttpClientConnectionManager) connectionManager).getMaxTotal());
		Object pool = getField(((PoolingHttpClientConnectionManager) connectionManager),
				"pool");
		assertEquals(-1l, getField(pool, "timeToLive"));
		TimeUnit timeUnit = getField(pool, "tunit");
		assertEquals(TimeUnit.MILLISECONDS, timeUnit);
	}

	@Test
	public void newConnectionManagerWithTTL() throws Exception {
		HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
				.newConnectionManager(false, 2, 6, 56l, TimeUnit.DAYS, null);
		assertEquals(6, ((PoolingHttpClientConnectionManager) connectionManager)
				.getDefaultMaxPerRoute());
		assertEquals(2,
				((PoolingHttpClientConnectionManager) connectionManager).getMaxTotal());
		Object pool = getField(((PoolingHttpClientConnectionManager) connectionManager),
				"pool");
		assertEquals(56l, getField(pool, "timeToLive"));
		TimeUnit timeUnit = getField(pool, "tunit");
		assertEquals(TimeUnit.DAYS, timeUnit);
	}

	protected <T> T getField(Object target, String name) {
		Field field = ReflectionUtils.findField(target.getClass(), name);
		ReflectionUtils.makeAccessible(field);
		Object value = ReflectionUtils.getField(field, target);
		return (T) value;
	}
}
@@ -973,11 +973,20 @@
 als(
+new Long(
 -1
-l
+)
 , ge
@@ -1665,19 +1665,28 @@
 tEquals(
+new Long(
 56
-l
+)
 , getFie
@@ -1802,16 +1802,48 @@
 t);%0A%09%7D%0A%0A
+%09@SuppressWarnings(%22unchecked%22)%0A
 %09protect

Fix test