List of usage examples for org.apache.commons.pool PoolableObjectFactory makeObject
Object makeObject() throws Exception;
From source file:gov.nih.nci.firebird.proxy.PoolingHandlerTest.java
@Test @SuppressWarnings("unchecked") public void testNormalInvocation() throws Exception { final ITestClient rootMock = makeBaseMockClient(); PoolableObjectFactory<Object> factory = mock(PoolableObjectFactory.class); when(factory.validateObject(any())).thenReturn(Boolean.TRUE); when(factory.makeObject()).thenAnswer(new Answer<ITestClient>() { @Override// w ww.j av a 2s. c om public ITestClient answer(InvocationOnMock invocation) throws Throwable { return new RelayClient(rootMock); } }); ITestClient proxy = newProxy(factory); assertEquals(1, proxy.doSomethingUseful("foo")); try { proxy.doSomethingBad(1); fail(); } catch (IllegalArgumentException e) { // expected } try { proxy.doSomethingWorse(false); fail(); } catch (UnsupportedOperationException e) { // expected } verify(rootMock).doSomethingUseful("foo"); verify(rootMock).doSomethingBad(1); verify(rootMock).doSomethingWorse(false); verifyNoMoreInteractions(rootMock); }
From source file:gov.nih.nci.firebird.proxy.PoolingHandlerTest.java
@SuppressWarnings("unchecked") private PoolableObjectFactory<Object> makeMockFactory() { PoolableObjectFactory<Object> factory = mock(PoolableObjectFactory.class); when(factory.validateObject(any())).thenReturn(Boolean.TRUE); try {//from ww w . java 2s.c om when(factory.makeObject()).thenAnswer(new Answer<ITestClient>() { @Override public ITestClient answer(InvocationOnMock invocation) throws Throwable { return makeBaseMockClient(); } }); } catch (Exception e) { //will never happen here. } return factory; }