/******************************************************************************* * Copyright (c) 2011, 2014 RĂ¼diger Herrmann 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * RĂ¼diger Herrmann - initial API and implementation * EclipseSource - ongoing development ******************************************************************************/ package org.eclipse.rap.rwt.internal.client; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.eclipse.rap.json.JsonObject; import org.eclipse.rap.rwt.client.service.UrlLauncher; import org.eclipse.rap.rwt.internal.remote.ConnectionImpl; import org.eclipse.rap.rwt.remote.RemoteObject; import org.eclipse.rap.rwt.testfixture.internal.Fixture; import org.eclipse.swt.widgets.Display; import org.junit.After; import org.junit.Before; import org.junit.Test; public class UrlLauncherImpl_Test { private static final String URL = "http://someurl.com/foo/bar"; @Before public void setUp() { Fixture.setUp(); new Display(); Fixture.fakeNewRequest(); } @After public void tearDown() { Fixture.tearDown(); } @Test public void testCreatesRemoteObjectWithCorrectId() { ConnectionImpl connection = fakeConnection( mock( RemoteObject.class ) ); UrlLauncher launcher = new UrlLauncherImpl(); launcher.openURL( URL ); verify( connection ).createServiceObject( eq( "rwt.client.UrlLauncher" ) ); } @Test public void testWritesCallOperation() { RemoteObject remoteObject = mock( RemoteObject.class ); fakeConnection( remoteObject ); UrlLauncher launcher = new UrlLauncherImpl(); launcher.openURL( URL ); verify( remoteObject ).call( eq( "openURL" ), eq( new JsonObject().add( "url", URL ) ) ); } private ConnectionImpl fakeConnection( RemoteObject remoteObject ) { ConnectionImpl connection = mock( ConnectionImpl.class ); when( connection.createServiceObject( anyString() ) ).thenReturn( remoteObject ); Fixture.fakeConnection( connection ); return connection; } }