Java Code Examples for org.easymock.EasyMock#createStrictControl()

The following examples show how to use org.easymock.EasyMock#createStrictControl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElectrumMultiWalletTest.java    From java-stratum with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    params = NetworkParameters.fromID(NetworkParameters.ID_UNITTESTNET);
    mapper = new ObjectMapper();

    DeterministicSeed seed = new DeterministicSeed("correct battery horse staple", null, "", 0);
    DeterministicKeyChain chain =
            DeterministicKeyChain.builder()
                    .seed(seed)
                    .build();
    KeyChainGroup group = new KeyChainGroup(params);
    group.addAndActivateHDChain(chain);
    wallet = new SmartWallet(params, group);
    wallet.setKeychainLookaheadSize(10);

    control = EasyMock.createStrictControl();
    client = control.createMock(StratumClient.class);
    expect(client.getConnectedAddresses()).andStubReturn(Lists.newArrayList(new InetSocketAddress(InetAddress.getLocalHost(), 0)));
    expect(client.getPeerVersion()).andStubReturn("1.0");
    store = control.createMock(HeadersStore.class);
    stratumChain = control.createMock(StratumChain.class);
    expect(stratumChain.getPeerHeight()).andStubReturn(100L);
    expect(store.get(340242)).andStubReturn(params.getGenesisBlock().cloneAsHeader());
    multiWallet = new ElectrumMultiWallet(wallet, BASE_DIRECTORY);
    multiWallet.start(client, stratumChain, store);
}
 
Example 2
Source File: TestWebappServiceLoader.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Before
public void init() {
    control = EasyMock.createStrictControl();
    parent = control.createMock(ClassLoader.class);
    cl = EasyMock.createMockBuilder(ClassLoader.class)
            .withConstructor(parent)
            .addMockedMethod("loadClass", String.class)
            .createMock(control);
    servletContext = control.createMock(ServletContext.class);
    EasyMock.expect(servletContext.getClassLoader()).andStubReturn(cl);
    context = new ExtendedTesterContext(servletContext, parent);
}
 
Example 3
Source File: FileTrackExporterTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  MockContentResolver mockContentResolver = new MockContentResolver();
  RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
      getContext(), getContext(), "test.");
  Context context = new MockContext(mockContentResolver, targetContext);
  MyTracksProvider myTracksProvider = new MyTracksProvider();
  myTracksProvider.attachInfo(context, null);
  mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, myTracksProvider);
  setContext(context);
  myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
  oldProviderUtilsFactory = TestingProviderUtilsFactory.installWithInstance(
      myTracksProviderUtils);

  mocksControl = EasyMock.createStrictControl();
  trackWriter = mocksControl.createMock(TrackWriter.class);

  Track track = new Track();
  track.setName(TRACK_NAME);
  track.setId(TRACK_ID);

  tracks = new Track[] {track};
  
  outputStream = new ByteArrayOutputStream();
  TrackExporterListener trackExporterListener = new TrackExporterListener() {
    
      @Override
    public void onProgressUpdate(int number, int max) {
      // Safe to ignore

    }
  };
  fileTrackExporter = new FileTrackExporter(
      myTracksProviderUtils, tracks, trackWriter, trackExporterListener);
}
 
Example 4
Source File: LockCleanerServiceTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Before
public void setupMocks() {
    relaxedCtrl = EasyMock.createControl();
    tx = relaxedCtrl.createMock(StoreTransaction.class);

    ctrl = EasyMock.createStrictControl();
    store = ctrl.createMock(KeyColumnValueStore.class);
    exec = ctrl.createMock(ExecutorService.class);
}
 
Example 5
Source File: LockCleanerRunnableTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Before
public void setupMocks() {
    relaxedCtrl = EasyMock.createControl();
    tx = relaxedCtrl.createMock(StoreTransaction.class);

    ctrl = EasyMock.createStrictControl();
    store = ctrl.createMock(KeyColumnValueStore.class);
}
 
Example 6
Source File: RestClientCdiTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawTypes"})
public void testCreationalContextsReleasedOnClientClose() throws Exception {
    IMocksControl control = EasyMock.createStrictControl();
    BeanManager mockedBeanMgr = control.createMock(BeanManager.class);
    CreationalContext<?> mockedCreationalCtx = control.createMock(CreationalContext.class);
    Bean<?> mockedBean = control.createMock(Bean.class);
    List<String> stringList = new ArrayList<>(Collections.singleton("abc"));

    EasyMock.expect(mockedBeanMgr.getBeans(List.class))
            .andReturn(Collections.singleton(mockedBean));
    EasyMock.expect(mockedBeanMgr.createCreationalContext(mockedBean))
            .andReturn((CreationalContext) mockedCreationalCtx);
    EasyMock.expect(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx))
            .andReturn(stringList);
    EasyMock.expect(mockedBean.getScope())
            .andReturn((Class) ApplicationScoped.class);
    EasyMock.expect(mockedBeanMgr.isNormalScope(ApplicationScoped.class))
            .andReturn(false);
    mockedCreationalCtx.release();
    EasyMock.expectLastCall().once();
    control.replay();

    Bus bus = new ExtensionManagerBus();
    bus.setExtension(mockedBeanMgr, BeanManager.class);

    Instance<List> i = CDIUtils.getInstanceFromCDI(List.class, bus);
    assertEquals(stringList, i.getValue());
    i.release();

    control.verify();
}
 
Example 7
Source File: RestClientCdiTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawTypes"})
public void testCreationalContextsNotReleasedOnClientCloseUsingNormalScope() throws Exception {
    IMocksControl control = EasyMock.createStrictControl();
    BeanManager mockedBeanMgr = control.createMock(BeanManager.class);
    CreationalContext<?> mockedCreationalCtx = control.createMock(CreationalContext.class);
    Bean<?> mockedBean = control.createMock(Bean.class);
    List<String> stringList = new ArrayList<>(Collections.singleton("xyz"));

    EasyMock.expect(mockedBeanMgr.getBeans(List.class))
            .andReturn(Collections.singleton(mockedBean));
    EasyMock.expect(mockedBeanMgr.createCreationalContext(mockedBean))
            .andReturn((CreationalContext) mockedCreationalCtx);
    EasyMock.expect(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx))
            .andReturn(stringList);
    EasyMock.expect(mockedBean.getScope())
            .andReturn((Class) NormalScope.class);
    EasyMock.expect(mockedBeanMgr.isNormalScope(NormalScope.class))
            .andReturn(true);
    control.replay();

    Bus bus = new ExtensionManagerBus();
    bus.setExtension(mockedBeanMgr, BeanManager.class);

    Instance<List> i = CDIUtils.getInstanceFromCDI(List.class, bus);

    i.release();

    control.verify();
}
 
Example 8
Source File: CXFBusLifeCycleManagerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleListeners() {

    IMocksControl ctrl = EasyMock.createStrictControl();

    BusLifeCycleListener listener1 = ctrl.createMock(BusLifeCycleListener.class);
    BusLifeCycleListener listener2 = ctrl.createMock(BusLifeCycleListener.class);
    CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();

    mgr.registerLifeCycleListener(listener1);
    mgr.registerLifeCycleListener(listener2);

    ctrl.reset();
    listener1.initComplete();
    listener2.initComplete();
    ctrl.replay();
    mgr.initComplete();
    ctrl.verify();

    ctrl.reset();
    listener2.preShutdown();
    listener1.preShutdown();
    ctrl.replay();
    mgr.preShutdown();
    ctrl.verify();

    ctrl.reset();
    listener2.postShutdown();
    listener1.postShutdown();
    ctrl.replay();
    mgr.postShutdown();
    ctrl.verify();
}
 
Example 9
Source File: CXFBusLifeCycleManagerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeregistration() {

    IMocksControl ctrl = EasyMock.createStrictControl();

    BusLifeCycleListener listener1 = ctrl.createMock(BusLifeCycleListener.class);
    BusLifeCycleListener listener2 = ctrl.createMock(BusLifeCycleListener.class);
    CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();

    mgr.registerLifeCycleListener(listener2);
    mgr.registerLifeCycleListener(listener1);
    mgr.unregisterLifeCycleListener(listener2);

    ctrl.reset();
    listener1.initComplete();
    ctrl.replay();
    mgr.initComplete();
    ctrl.verify();

    ctrl.reset();
    listener1.preShutdown();
    ctrl.replay();
    mgr.preShutdown();
    ctrl.verify();

    ctrl.reset();
    listener1.postShutdown();
    ctrl.replay();
    mgr.postShutdown();
    ctrl.verify();
}
 
Example 10
Source File: TracingTaskListenerTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  mockControl = EasyMock.createStrictControl();
  mockTracer = mockControl.createMock(JavacPhaseTracer.class);
  mockNextListener = mockControl.createMock(BuckJavacTaskListener.class);

  tracingTaskListener = new TracingTaskListener(mockTracer, mockNextListener);
}
 
Example 11
Source File: ExpectedValueCheckingTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Before
public void setupMocks() throws BackendException {

    // Initialize mock controller
    ctrl = EasyMock.createStrictControl();
    ctrl.checkOrder(true);

    // Setup some config mocks and objects
    backingManager = ctrl.createMock(KeyColumnValueStoreManager.class);
    lockerProvider = ctrl.createMock(LockerProvider.class);
    globalConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    localConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    defaultConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    // Set some properties on the configs, just so that global/local/default can be easily distinguished
    globalConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "global");
    localConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "local");
    defaultConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "default");
    defaultTxConfig = new StandardBaseTransactionConfig.Builder().customOptions(defaultConfig).timestampProvider(TimestampProviders.MICRO).build();
    backingFeatures = new StandardStoreFeatures.Builder().keyConsistent(globalConfig, localConfig).build();


    // Setup behavior specification starts below this line


    // 1. Construct manager
    // The EVCSManager ctor retrieves the backing store's features and stores it in an instance field
    expect(backingManager.getFeatures()).andReturn(backingFeatures).once();

    // 2. Begin transaction
    // EVCTx begins two transactions on the backingManager: one with globalConfig and one with localConfig
    // The capture is used in the @After method to check the config
    txConfigCapture = new Capture<BaseTransactionConfig>(CaptureType.ALL);
    inconsistentTx = ctrl.createMock(StoreTransaction.class);
    consistentTx = ctrl.createMock(StoreTransaction.class);
    expect(backingManager.beginTransaction(capture(txConfigCapture))).andReturn(inconsistentTx);
    expect(backingManager.beginTransaction(capture(txConfigCapture))).andReturn(consistentTx);

    // 3. Open a database
    backingLocker = ctrl.createMock(Locker.class);
    backingStore = ctrl.createMock(KeyColumnValueStore.class);
    expect(backingManager.openDatabase(STORE_NAME)).andReturn(backingStore);
    expect(backingStore.getName()).andReturn(STORE_NAME);
    expect(lockerProvider.getLocker(LOCKER_NAME)).andReturn(backingLocker);

    // Carry out setup behavior against mocks
    ctrl.replay();
    // 1. Construct manager
    expectManager = new ExpectedValueCheckingStoreManager(backingManager, LOCK_SUFFIX, lockerProvider, Duration.ofSeconds(1L));
    // 2. Begin transaction
    expectTx = expectManager.beginTransaction(defaultTxConfig);
    // 3. Open a database
    expectStore = expectManager.openDatabase(STORE_NAME);

    // Verify behavior and reset the mocks for test methods to use
    ctrl.verify();
    ctrl.reset();
}
 
Example 12
Source File: UsernameCacheTest.java    From account-provisioning-for-google-apps with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
  control = EasyMock.createStrictControl();
}