本文整理汇总了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));
}
示例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));
}
示例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();
}
示例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);
}
示例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();
}
示例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));
}
示例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));
}
示例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);
}
示例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());
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
}
示例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());
}