public void testForThrowable() throws Throwable { NullPointerException exception = new NullPointerException(); Answer<Object> answer = AnswerFactory.forThrowable(exception); try { answer.answer(null); fail("should have thrown exception"); } catch (NullPointerException expected) { assertSame(exception, expected); } }
public void testForOnSuccess_noCallbackProvided() throws Throwable { Answer<Object> answer = AnswerFactory.forOnSuccess(42); Object[] args = {14, "Hallo"}; try { answer.answer(args); fail("should have thrown exception"); } catch (IllegalArgumentException expected) { assertEquals( "No com.google.gwt.user.client.rpc.AsyncCallback object as last argument provided", expected.getMessage()); } }
public void testForOnSuccess() throws Throwable { @SuppressWarnings("unchecked") AsyncCallback<Object> callback = EasyMock.createMock(AsyncCallback.class); callback.onSuccess(42); EasyMock.replay(callback); Answer<Object> answer = AnswerFactory.forOnSuccess(42); Object[] args = {14, "Hallo", callback}; answer.answer(args); EasyMock.verify(callback); }
public void testForOnFailure() throws Throwable { Throwable throwable = new Exception(); @SuppressWarnings("unchecked") AsyncCallback<Object> callback = EasyMock.createMock(AsyncCallback.class); callback.onFailure(throwable); EasyMock.replay(callback); Answer<Object> answer = AnswerFactory.forOnFailure(throwable); Object[] args = {14, "Hallo", callback}; answer.answer(args); EasyMock.verify(callback); }
public void testForValue_object() throws Throwable { Object obj = new Object(); Answer<Object> answer = AnswerFactory.forValue(obj); assertSame(obj, answer.answer(null)); }
public void testForValue_primitive() throws Throwable { Answer<Object> answer = AnswerFactory.forValue(42); assertEquals(42, answer.answer(null)); }
public void testForValue_null() throws Throwable { Answer<Object> answer = AnswerFactory.forValue(null); assertNull(answer.answer(null)); }