Package com.eclipsesource.tabris.test.util.internal

Source Code of com.eclipsesource.tabris.test.util.internal.RemoteObjectHelper

package com.eclipsesource.tabris.test.util.internal;
/*******************************************************************************
* Copyright (c) 2012 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    EclipseSource - initial API and implementation
******************************************************************************/


import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import java.util.Random;

import org.eclipse.rap.rwt.internal.remote.ConnectionImpl;
import org.eclipse.rap.rwt.remote.OperationHandler;
import org.eclipse.rap.rwt.remote.RemoteObject;
import org.eclipse.rap.rwt.testfixture.Fixture;

import com.eclipsesource.tabris.test.util.TestRemoteObject;


@SuppressWarnings("restriction")
public class RemoteObjectHelper {

  private static final Random random = new Random();

  public static RemoteObject mockRemoteObject() {
    RemoteObject serviceObject = createRemoteObject();
    RemoteObject remoteObject = createRemoteObject();
    ConnectionImpl connection = mock( ConnectionImpl.class );
    when( connection.createRemoteObject( anyString() ) ).thenReturn( remoteObject );
    when( connection.createServiceObject( anyString() ) ).thenReturn( serviceObject );
    Fixture.fakeConnection( connection );
    return remoteObject;
  }

  private static RemoteObject createRemoteObject() {
    String id = "w" + random.nextInt();
    RemoteObject remoteObject = spy( new TestRemoteObject( id ) );
    remoteObject.setHandler( mock( OperationHandler.class ) );
    return remoteObject;
  }

  private RemoteObjectHelper() {
    // prevent instantiation
  }
}
TOP

Related Classes of com.eclipsesource.tabris.test.util.internal.RemoteObjectHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.