Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Sternberg2016-01-27 12:35:20 -0500
committerRalf Sternberg2016-01-27 12:35:20 -0500
commitbfa68fa6709d2aa89a24e00ce8b3e11c5b509efc (patch)
tree8021b6bc47158c4e8ef5b356191312e9ecab1148
parent33a6ef229a598522d7aaad55d14acb67b7d9a719 (diff)
downloadorg.eclipse.rap.incubator.dropdown-bfa68fa6709d2aa89a24e00ce8b3e11c5b509efc.tar.gz
org.eclipse.rap.incubator.dropdown-bfa68fa6709d2aa89a24e00ce8b3e11c5b509efc.tar.xz
org.eclipse.rap.incubator.dropdown-bfa68fa6709d2aa89a24e00ce8b3e11c5b509efc.zip
Replace spy with mock in tests
Spying ConnectionImpl fails with Java 8 with some dubious InvocationTargetException. Instead of spying the existing connection object, create a mock and make sure that it returns another mocked RemoteObject for the DropDown widget that is created internally. Change-Id: I26fe1030451ce05ab3ab35525cbaebc6a9e2b3b8
-rw-r--r--tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java b/tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java
index ea06b97..41b2347 100644
--- a/tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java
+++ b/tests/org.eclipse.rap.addons.autosuggest.test/src/org/eclipse/rap/addons/autosuggest/AutoSuggest_Test.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2015 EclipseSource and others.
+ * Copyright (c) 2013, 2016 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,19 +18,18 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.concurrent.atomic.AtomicReference;
-import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.internal.lifecycle.WidgetDataUtil;
import org.eclipse.rap.rwt.remote.Connection;
import org.eclipse.rap.rwt.remote.OperationHandler;
@@ -500,8 +499,17 @@ public class AutoSuggest_Test {
private void mockRemoteObject() {
remoteObject = mock( RemoteObject.class );
when( remoteObject.getId() ).thenReturn( "foo" );
- connection = spy( RWT.getUISession().getConnection() );
- when( connection.createRemoteObject( REMOTE_TYPE ) ).thenReturn( remoteObject );
+ connection = mock( Connection.class );
+ doAnswer( new Answer<Object>() {
+ @Override
+ public Object answer( InvocationOnMock invocation ) throws Throwable {
+ String type = ( String )invocation.getArguments()[ 0 ];
+ if( type.equals( REMOTE_TYPE ) ) {
+ return remoteObject;
+ }
+ return mock( RemoteObject.class );
+ }
+ } ).when( connection ).createRemoteObject( anyString() );
context.replaceConnection( connection );
}

Back to the top