當前位置: 首頁>>代碼示例>>Java>>正文


Java Mockery類代碼示例

本文整理匯總了Java中org.jmock.Mockery的典型用法代碼示例。如果您正苦於以下問題:Java Mockery類的具體用法?Java Mockery怎麽用?Java Mockery使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Mockery類屬於org.jmock包,在下文中一共展示了Mockery類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testEmptyDriveIsIgnored

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testEmptyDriveIsIgnored() throws Exception {
	Mockery context = new Mockery() {{
		setThreadingPolicy(new Synchroniser());
	}};
	final Executor executor = context.mock(Executor.class);
	final SimplexPluginCallback callback =
			context.mock(SimplexPluginCallback.class);
	final RemovableDriveFinder finder =
			context.mock(RemovableDriveFinder.class);
	final RemovableDriveMonitor monitor =
			context.mock(RemovableDriveMonitor.class);

	context.checking(new Expectations() {{
		oneOf(monitor).start(with(any(Callback.class)));
	}});

	RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
			callback, finder, monitor, 0);
	plugin.start();

	plugin.driveInserted(testDir);

	context.assertIsSatisfied();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:26,代碼來源:RemovableDrivePluginTest.java

示例2: testFilenames

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testFilenames() {
	Mockery context = new Mockery() {{
		setThreadingPolicy(new Synchroniser());
	}};
	final Executor executor = context.mock(Executor.class);
	final SimplexPluginCallback callback =
			context.mock(SimplexPluginCallback.class);
	final RemovableDriveFinder finder =
			context.mock(RemovableDriveFinder.class);
	final RemovableDriveMonitor monitor =
			context.mock(RemovableDriveMonitor.class);

	RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
			callback, finder, monitor, 0);

	assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
	assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
	assertFalse(plugin.isPossibleConnectionFilename("abcdefgh_dat"));
	assertFalse(plugin.isPossibleConnectionFilename("abcdefgh.rat"));
	assertTrue(plugin.isPossibleConnectionFilename("abcdefgh.dat"));
	assertTrue(plugin.isPossibleConnectionFilename("ABCDEFGH.DAT"));

	context.assertIsSatisfied();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:26,代碼來源:RemovableDrivePluginTest.java

示例3: testEmptyFramesAreSkipped

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testEmptyFramesAreSkipped() throws Exception {
	Mockery context = new Mockery();
	final StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
	context.checking(new Expectations() {{
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(0)); // Empty frame
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(2)); // Non-empty frame with two payload bytes
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(0)); // Empty frame
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(-1)); // No more frames
	}});
	StreamReaderImpl r = new StreamReaderImpl(decrypter);
	assertEquals(0, r.read()); // Skip the first empty frame, read a byte
	assertEquals(0, r.read()); // Read another byte
	assertEquals(-1, r.read()); // Skip the second empty frame, reach EOF
	assertEquals(-1, r.read()); // Still at EOF
	context.assertIsSatisfied();
	r.close();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:23,代碼來源:StreamReaderImplTest.java

示例4: testMultipleReadsPerFrame

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testMultipleReadsPerFrame() throws Exception {
	Mockery context = new Mockery();
	final StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
	context.checking(new Expectations() {{
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(MAX_PAYLOAD_LENGTH)); // Nice long frame
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(-1)); // No more frames
	}});
	StreamReaderImpl r = new StreamReaderImpl(decrypter);
	byte[] buf = new byte[MAX_PAYLOAD_LENGTH / 2];
	// Read the first half of the payload
	assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf));
	// Read the second half of the payload
	assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf));
	// Reach EOF
	assertEquals(-1, r.read(buf, 0, buf.length));
	context.assertIsSatisfied();
	r.close();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:22,代碼來源:StreamReaderImplTest.java

示例5: testFlushWithoutBufferedDataWritesFrameAndFlushes

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testFlushWithoutBufferedDataWritesFrameAndFlushes()
		throws Exception {
	Mockery context = new Mockery();
	final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
	StreamWriterImpl w = new StreamWriterImpl(encrypter);
	context.checking(new Expectations() {{
		// Write a non-final frame with an empty payload
		oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
				with(0), with(false));
		// Flush the stream
		oneOf(encrypter).flush();
	}});
	w.flush();
	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,代碼行數:27,代碼來源:StreamWriterImplTest.java

示例6: testSingleByteWritesWriteFullFrame

import org.jmock.Mockery; //導入依賴的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

示例7: testLargeMultiByteWriteWritesFullFrames

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testLargeMultiByteWriteWritesFullFrames() throws Exception {
	Mockery context = new Mockery();
	final StreamEncrypter encrypter = context.mock(StreamEncrypter.class);
	StreamWriterImpl w = new StreamWriterImpl(encrypter);
	context.checking(new Expectations() {{
		// Write two full non-final frames
		exactly(2).of(encrypter).writeFrame(with(any(byte[].class)),
				with(MAX_PAYLOAD_LENGTH), with(0), with(false));
		// Write a final frame with a one-byte payload
		oneOf(encrypter).writeFrame(with(any(byte[].class)), with(1),
				with(0), with(true));
		// Flush the stream
		oneOf(encrypter).flush();
	}});
	// Write two full payloads using one large multi-byte write
	byte[] b = new byte[MAX_PAYLOAD_LENGTH * 2 + 1];
	w.write(b);
	// There should be one byte left in the buffer
	w.close();
	context.assertIsSatisfied();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:23,代碼來源:StreamWriterImplTest.java

示例8: testCannotStartTransactionDuringTransaction

import org.jmock.Mockery; //導入依賴的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

示例9: testEmptyFramesAreSkippedWithBuffer

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testEmptyFramesAreSkippedWithBuffer() throws Exception {
	Mockery context = new Mockery();
	final StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
	context.checking(new Expectations() {{
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(0)); // Empty frame
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(2)); // Non-empty frame with two payload bytes
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(0)); // Empty frame
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(-1)); // No more frames
	}});
	StreamReaderImpl r = new StreamReaderImpl(decrypter);
	byte[] buf = new byte[MAX_PAYLOAD_LENGTH];
	// Skip the first empty frame, read the two payload bytes
	assertEquals(2, r.read(buf));
	// Skip the second empty frame, reach EOF
	assertEquals(-1, r.read(buf));
	// Still at EOF
	assertEquals(-1, r.read(buf));
	context.assertIsSatisfied();
	r.close();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:26,代碼來源:StreamReaderImplTest.java

示例10: testMultipleReadsPerFrameWithOffsets

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testMultipleReadsPerFrameWithOffsets() throws Exception {
	Mockery context = new Mockery();
	final StreamDecrypter decrypter = context.mock(StreamDecrypter.class);
	context.checking(new Expectations() {{
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(MAX_PAYLOAD_LENGTH)); // Nice long frame
		oneOf(decrypter).readFrame(with(any(byte[].class)));
		will(returnValue(-1)); // No more frames
	}});
	StreamReaderImpl r = new StreamReaderImpl(decrypter);
	byte[] buf = new byte[MAX_PAYLOAD_LENGTH];
	// Read the first half of the payload
	assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, MAX_PAYLOAD_LENGTH / 2,
			MAX_PAYLOAD_LENGTH / 2));
	// Read the second half of the payload
	assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, 123,
			MAX_PAYLOAD_LENGTH / 2));
	// Reach EOF
	assertEquals(-1, r.read(buf, 0, buf.length));
	context.assertIsSatisfied();
	r.close();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:24,代碼來源:StreamReaderImplTest.java

示例11: testOutgoingStreamContextIsNullIfContactIsNotFound

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testOutgoingStreamContextIsNullIfContactIsNotFound()
		throws Exception {
	Mockery context = new Mockery();
	final DatabaseComponent db = context.mock(DatabaseComponent.class);
	final CryptoComponent crypto = context.mock(CryptoComponent.class);
	final Executor dbExecutor = context.mock(Executor.class);
	final ScheduledExecutorService scheduler =
			context.mock(ScheduledExecutorService.class);
	final Clock clock = context.mock(Clock.class);

	final Transaction txn = new Transaction(null, false);

	TransportKeyManager
			transportKeyManager = new TransportKeyManagerImpl(db,
			crypto, dbExecutor, scheduler, clock, transportId, maxLatency);
	assertNull(transportKeyManager.getStreamContext(txn, contactId));

	context.assertIsSatisfied();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:21,代碼來源:TransportKeyManagerImplTest.java

示例12: testCannotAddLocalIdentityAsContact

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testCannotAddLocalIdentityAsContact() 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));
		oneOf(database).containsLocalAuthor(txn, localAuthorId);
		will(returnValue(true));
		// Contact is a local identity
		oneOf(database).containsLocalAuthor(txn, authorId);
		will(returnValue(true));
		oneOf(database).abortTransaction(txn);
	}});

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

	Transaction transaction = db.startTransaction(false);
	try {
		db.addContact(transaction, author, localAuthorId, true, true);
		fail();
	} catch (ContactExistsException expected) {
		// Expected
	} finally {
		db.endTransaction(transaction);
	}

	context.assertIsSatisfied();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:35,代碼來源:DatabaseComponentImplTest.java

示例13: testWriterIsNullIfNoDriveIsChosen

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testWriterIsNullIfNoDriveIsChosen() throws Exception {
	final File drive1 = new File(testDir, "1");
	final File drive2 = new File(testDir, "2");
	final List<File> drives = new ArrayList<>();
	drives.add(drive1);
	drives.add(drive2);

	Mockery context = new Mockery() {{
		setThreadingPolicy(new Synchroniser());
	}};
	final Executor executor = context.mock(Executor.class);
	final SimplexPluginCallback callback =
			context.mock(SimplexPluginCallback.class);
	final RemovableDriveFinder finder =
			context.mock(RemovableDriveFinder.class);
	final RemovableDriveMonitor monitor =
			context.mock(RemovableDriveMonitor.class);

	context.checking(new Expectations() {{
		oneOf(monitor).start(with(any(Callback.class)));
		oneOf(finder).findRemovableDrives();
		will(returnValue(drives));
		oneOf(callback).showChoice(with(any(String[].class)),
				with(any(String[].class)));
		will(returnValue(-1)); // The user cancelled the choice
	}});

	RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
			callback, finder, monitor, 0);
	plugin.start();

	assertNull(plugin.createWriter(contactId));
	File[] files = drive1.listFiles();
	assertTrue(files == null || files.length == 0);

	context.assertIsSatisfied();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:39,代碼來源:RemovableDrivePluginTest.java

示例14: setUp

import org.jmock.Mockery; //導入依賴的package包/類
@Before
public void setUp() {
  mockContext = new Mockery() {
    {
      setImposteriser(ClassImposteriser.INSTANCE);
    }
  };
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:9,代碼來源:DiskStoreCommandsJUnitTest.java

示例15: testReceiveDuplicateMessage

import org.jmock.Mockery; //導入依賴的package包/類
@Test
public void testReceiveDuplicateMessage() 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));
		oneOf(database).containsContact(txn, contactId);
		will(returnValue(true));
		oneOf(database).containsMessage(txn, messageId);
		will(returnValue(true));
		oneOf(database).getGroupVisibility(txn, contactId, groupId);
		will(returnValue(VISIBLE));
		// The message wasn't stored but it must still be acked
		oneOf(database).raiseSeenFlag(txn, contactId, messageId);
		oneOf(database).raiseAckFlag(txn, contactId, messageId);
		oneOf(database).commitTransaction(txn);
		// The message was received but not added
		oneOf(eventBus).broadcast(with(any(MessageToAckEvent.class)));
	}});
	DatabaseComponent db = createDatabaseComponent(database, eventBus,
			shutdown);

	Transaction transaction = db.startTransaction(false);
	try {
		db.receiveMessage(transaction, contactId, message);
		db.commitTransaction(transaction);
	} finally {
		db.endTransaction(transaction);
	}

	context.assertIsSatisfied();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:37,代碼來源:DatabaseComponentImplTest.java


注:本文中的org.jmock.Mockery類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。