当前位置: 首页>>代码示例>>Java>>正文


Java Expectations类代码示例

本文整理汇总了Java中org.jmock.Expectations的典型用法代码示例。如果您正苦于以下问题:Java Expectations类的具体用法?Java Expectations怎么用?Java Expectations使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Expectations类属于org.jmock包,在下文中一共展示了Expectations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNAMEtoDOTS

import org.jmock.Expectations; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testNAMEtoDOTS() {
  final StringBuilder sb = new StringBuilder();
  final byte[] buf = "xyzzy\n".getBytes();

  final EventListener<String> nl = context.mock(EventListener.class, "nl");
  final EventListener<Integer> pl = context.mock(EventListener.class, "pl");

  context.checking(new Expectations() {
    {
      oneOf(nl).receive(with(aNonNull(TileProgressPumpStateMachine.class)),
                        with(equal("xyzzy")));
      never(pl).receive(with(any(Object.class)),
                        with(any(Integer.class)));
    }
  });

  final TileProgressPumpStateMachine sm =
    new TileProgressPumpStateMachine(nl, pl);

  assertEquals(DOTS, sm.run(NAME, buf, 0, buf.length, sb));
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:24,代码来源:TileProgressPumpStateMachineTest.java

示例2: testNAME_LFtoDOTS

import org.jmock.Expectations; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testNAME_LFtoDOTS() {
  final StringBuilder sb = new StringBuilder();
  final byte[] buf = "\n".getBytes();

  final EventListener<String> nl = context.mock(EventListener.class, "nl");
  final EventListener<Integer> pl = context.mock(EventListener.class, "pl");

  context.checking(new Expectations() {
    {
      never(nl).receive(with(any(Object.class)),
                        with(any(String.class)));
      never(pl).receive(with(any(Object.class)),
                        with(any(Integer.class)));
    }
  });

  final TileProgressPumpStateMachine sm =
    new TileProgressPumpStateMachine(nl, pl);

  assertEquals(DOTS, sm.run(NAME_LF, buf, 0, buf.length, sb));
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:24,代码来源:TileProgressPumpStateMachineTest.java

示例3: testSignatureVerification

import org.jmock.Expectations; //导入依赖的package包/类
@Test
public void testSignatureVerification()
		throws FormatException, DbException, GeneralSecurityException {

	final byte[] publicKeyBytes = introducee2.getAuthor().getPublicKey();
	final byte[] nonce = TestUtils.getRandomBytes(MAC_LENGTH);
	final byte[] sig = TestUtils.getRandomBytes(MAC_LENGTH);

	BdfDictionary state = new BdfDictionary();
	state.put(PUBLIC_KEY, publicKeyBytes);
	state.put(NONCE, nonce);
	state.put(SIGNATURE, sig);

	context.checking(new Expectations() {{
		oneOf(cryptoComponent).verify(SIGNING_LABEL_RESPONSE, nonce,
				publicKeyBytes, sig);
		will(returnValue(true));
	}});
	introduceeManager.verifySignature(state);
	context.assertIsSatisfied();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:22,代码来源:IntroduceeManagerTest.java

示例4: testDOTStoIllegal

import org.jmock.Expectations; //导入依赖的package包/类
@Test(expected=IllegalStateException.class)
@SuppressWarnings("unchecked")
public void testDOTStoIllegal() {
  final StringBuilder sb = new StringBuilder();
  final byte[] buf = "x".getBytes();

  final EventListener<String> nl = context.mock(EventListener.class, "nl");
  final EventListener<Integer> pl = context.mock(EventListener.class, "pl");

  context.checking(new Expectations() {
    {
      never(nl).receive(with(any(Object.class)),
                        with(any(String.class)));
      never(pl).receive(with(any(Object.class)),
                        with(any(Integer.class)));
    }
  });

  final TileProgressPumpStateMachine sm =
    new TileProgressPumpStateMachine(nl, pl);

  sm.run(DOTS, buf, 0, buf.length, sb);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:24,代码来源:TileProgressPumpStateMachineTest.java

示例5: testSingleByteWritesWriteFullFrame

import org.jmock.Expectations; //导入依赖的package包/类
@Test
public void testSingleByteWritesWriteFullFrame() throws Exception {
	Mockery context = new Mockery();
	final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
	StreamWriterImpl w = new StreamWriterImpl(encrypter);
	context.checking(new Expectations() {{
		// Write a full non-final frame
		oneOf(encrypter).writeFrame(with(any(byte[].class)),
				with(MAX_PAYLOAD_LENGTH), with(0), with(false));
	}});
	for (int i = 0; i < MAX_PAYLOAD_LENGTH; i++) w.write(0);
	context.assertIsSatisfied();

	// Clean up
	context.checking(new Expectations() {{
		// Closing the writer writes a final frame and flushes again
		oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
				with(0), with(true));
		oneOf(encrypter).flush();
	}});
	w.close();
	context.assertIsSatisfied();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:24,代码来源:StreamWriterImplTest.java

示例6: testIsRegionUsingDiskStoreWhenDiskStoresMismatch

import org.jmock.Expectations; //导入依赖的package包/类
@Test
public void testIsRegionUsingDiskStoreWhenDiskStoresMismatch() {
  final Region mockRegion = mockContext.mock(Region.class, "Region");
  final RegionAttributes mockRegionAttributes =
      mockContext.mock(RegionAttributes.class, "RegionAttributes");
  final DiskStore mockDiskStore = mockContext.mock(DiskStore.class, "DiskStore");

  mockContext.checking(new Expectations() {
    {
      atLeast(1).of(mockRegion).getAttributes();
      will(returnValue(mockRegionAttributes));
      oneOf(mockRegionAttributes).getDataPolicy();
      will(returnValue(DataPolicy.PERSISTENT_PARTITION));
      oneOf(mockRegionAttributes).getDiskStoreName();
      will(returnValue("mockDiskStore"));
      oneOf(mockDiskStore).getName();
      will(returnValue("testDiskStore"));
    }
  });

  final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null);

  assertFalse(function.isUsingDiskStore(mockRegion, mockDiskStore));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:25,代码来源:DescribeDiskStoreFunctionJUnitTest.java

示例7: setupGatewaysForTestExecute

import org.jmock.Expectations; //导入依赖的package包/类
private Set<DiskStoreDetails.GatewayDetails> setupGatewaysForTestExecute(
    final InternalCache mockCache, final String diskStoreName) {
  final GatewaySender mockGatewaySender = mockContext.mock(GatewaySender.class, "GatewaySender");

  mockContext.checking(new Expectations() {
    {
      oneOf(mockCache).getGatewaySenders();
      will(returnValue(CollectionUtils.asSet(mockGatewaySender)));
      oneOf(mockGatewaySender).getDiskStoreName();
      will(returnValue(diskStoreName));
      oneOf(mockGatewaySender).getId();
      will(returnValue("0123456789"));
      oneOf(mockGatewaySender).isPersistenceEnabled();
      will(returnValue(true));
    }
  });

  return CollectionUtils.asSet(createGatewayDetails("0123456789", true));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:DescribeDiskStoreFunctionJUnitTest.java

示例8: testNotify

import org.jmock.Expectations; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testNotify() {
  final EventListenerSupport<Boolean> lsup =
    new DefaultEventListenerSupport<Boolean>(this);

  final EventListener<Boolean> listener = context.mock(EventListener.class);

  context.checking(new Expectations() {
    {
      oneOf(listener).receive(DefaultEventListenerSupportTest.this, true);
      oneOf(listener).receive(DefaultEventListenerSupportTest.this, false);
    }
  });

  lsup.addEventListener(listener);

  lsup.notify(true);
  lsup.notify(false);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:21,代码来源:DefaultEventListenerSupportTest.java

示例9: testPumpNormal

import org.jmock.Expectations; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPumpNormal() {
  final byte[] eout = "Jackdaws love my big sphinx of quartz.\n".getBytes();

  final ByteArrayInputStream in = new ByteArrayInputStream(eout);
  final ByteArrayOutputStream out = new ByteArrayOutputStream();

  final EventListener<IOException> el = context.mock(EventListener.class);
  context.checking(new Expectations() {
    {
      never(el).receive(with(any(Object.class)),
                        with(any(IOException.class)));
    }
  });

  final InputOutputStreamPump p = new InputOutputStreamPump(in, out, el);
  p.run();

  assertArrayEquals(eout, out.toByteArray());
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:22,代码来源:InputOutputStreamPumpTest.java

示例10: testPumpOutClosed

import org.jmock.Expectations; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPumpOutClosed() {
  final byte[] eout = "Jackdaws love my big sphinx of quartz.\n".getBytes();

  final ByteArrayInputStream in = new ByteArrayInputStream(eout);
  final OutputStream out = new ClosedOutputStream();

  final EventListener<IOException> el = context.mock(EventListener.class);
  context.checking(new Expectations() {
    {
      oneOf(el).receive(with(aNonNull(InputOutputStreamPump.class)),
                        with(any(IOException.class)));
    }
  });

  final InputOutputStreamPump p = new InputOutputStreamPump(in, out, el);
  p.run();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:20,代码来源:InputOutputStreamPumpTest.java

示例11: testAddLocalMessage

import org.jmock.Expectations; //导入依赖的package包/类
@Test
public void testAddLocalMessage() throws Exception {
	final boolean shared = true;
	final Transaction txn = new Transaction(null, false);

	context.checking(new Expectations() {{
		oneOf(db).startTransaction(false);
		will(returnValue(txn));
		oneOf(metadataEncoder).encode(dictionary);
		will(returnValue(metadata));
		oneOf(db).addLocalMessage(txn, message, metadata, shared);
		oneOf(db).commitTransaction(txn);
		oneOf(db).endTransaction(txn);
	}});

	clientHelper.addLocalMessage(message, dictionary, shared);
	context.assertIsSatisfied();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:19,代码来源:ClientHelperImplTest.java

示例12: testPumpBothClosed

import org.jmock.Expectations; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testPumpBothClosed() {
  final InputStream in = new ClosedInputStream();
  final OutputStream out = new ClosedOutputStream();

  final EventListener<IOException> el = context.mock(EventListener.class);
  context.checking(new Expectations() {
    {
      never(el).receive(with(any(Object.class)),
                        with(any(IOException.class)));
    }
  });

  final InputOutputStreamPump p = new InputOutputStreamPump(in, out, el);
  p.run();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:18,代码来源:InputOutputStreamPumpTest.java

示例13: init

import org.jmock.Expectations; //导入依赖的package包/类
@SuppressWarnings("unchecked")
  @Before
  public void init() throws Exception {
    if (initialized) {
      return;
    }
    final GameModule module = context.mock(GameModule.class);
    context.checking(new Expectations() {
      {
        allowing(module).setGpIdSupport(with(any(GameModule.class)));
        allowing(module).build();
        allowing(module).getDataArchive();
        allowing(module).getComponentsOf(with(any(Class.class)));
//        allowing(module).sliceLargeImages();
        allowing(module).getFrame();
      }
    });
    GameModule.init(module);
    initialized = true;
  }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:21,代码来源:MockModuleTest.java

示例14: testCannotStartTransactionDuringTransaction

import org.jmock.Expectations; //导入依赖的package包/类
private void testCannotStartTransactionDuringTransaction(
		boolean firstTxnReadOnly, boolean secondTxnReadOnly)
		throws Exception {
	Mockery context = new Mockery();
	@SuppressWarnings("unchecked")
	final Database<Object> database = context.mock(Database.class);
	final ShutdownManager shutdown = context.mock(ShutdownManager.class);
	final EventBus eventBus = context.mock(EventBus.class);

	context.checking(new Expectations() {{
		oneOf(database).startTransaction();
		will(returnValue(txn));
	}});

	DatabaseComponent db = createDatabaseComponent(database, eventBus,
			shutdown);

	assertNotNull(db.startTransaction(firstTxnReadOnly));
	try {
		db.startTransaction(secondTxnReadOnly);
		fail();
	} finally {
		context.assertIsSatisfied();
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:26,代码来源:DatabaseComponentImplTest.java

示例15: testRevealRelationship

import org.jmock.Expectations; //导入依赖的package包/类
@Test
public void testRevealRelationship() throws Exception {
	context.checking(new Expectations() {{
		oneOf(db).startTransaction(false);
		will(returnValue(txn));
		oneOf(db).getContact(txn, contactId);
		will(returnValue(contact));
		oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, contact);
		will(returnValue(contactGroup));
		oneOf(sessionParser)
				.parsePeerSession(contactGroup.getId(), bdfSession);
		will(returnValue(peerSession));
		oneOf(peerEngine).onJoinAction(txn, peerSession);
		will(returnValue(peerSession));
		oneOf(db).commitTransaction(txn);
		oneOf(db).endTransaction(txn);
	}});
	expectGetSession(oneResult, sessionId, contactGroup.getId());
	expectStoreSession(peerSession, storageMessage.getId());

	groupInvitationManager
			.revealRelationship(contactId, privateGroup.getId());
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:24,代码来源:GroupInvitationManagerImplTest.java


注:本文中的org.jmock.Expectations类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。