本文整理匯總了Java中org.jmock.Mockery.checking方法的典型用法代碼示例。如果您正苦於以下問題:Java Mockery.checking方法的具體用法?Java Mockery.checking怎麽用?Java Mockery.checking使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jmock.Mockery
的用法示例。
在下文中一共展示了Mockery.checking方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: 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();
}
示例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();
}
示例4: 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();
}
示例5: testWriterIsNullIfOutputDirDoesNotExist
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testWriterIsNullIfOutputDirDoesNotExist() 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(0)); // The user chose drive1 but it doesn't exist
}});
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();
}
示例6: testChangingVisibilityCallsListeners
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testChangingVisibilityCallsListeners() 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).containsGroup(txn, groupId);
will(returnValue(true));
oneOf(database).getGroupVisibility(txn, contactId, groupId);
will(returnValue(INVISIBLE)); // Not yet visible
oneOf(database).addGroupVisibility(txn, contactId, groupId, false);
oneOf(database).getMessageIds(txn, groupId);
will(returnValue(Collections.singletonList(messageId)));
oneOf(database).removeOfferedMessage(txn, contactId, messageId);
will(returnValue(false));
oneOf(database).addStatus(txn, contactId, messageId, false, false);
oneOf(database).commitTransaction(txn);
oneOf(eventBus).broadcast(with(any(
GroupVisibilityUpdatedEvent.class)));
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
Transaction transaction = db.startTransaction(false);
try {
db.setGroupVisibility(transaction, contactId, groupId, VISIBLE);
db.commitTransaction(transaction);
} finally {
db.endTransaction(transaction);
}
context.assertIsSatisfied();
}
示例7: testCreateConnectionWhenDialReturnsFalse
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testCreateConnectionWhenDialReturnsFalse() throws Exception {
Mockery context = new Mockery();
final ModemFactory modemFactory = context.mock(ModemFactory.class);
final SerialPortList serialPortList =
context.mock(SerialPortList.class);
final DuplexPluginCallback callback =
context.mock(DuplexPluginCallback.class);
final ModemPlugin plugin = new ModemPlugin(modemFactory,
serialPortList, callback, 0);
final Modem modem = context.mock(Modem.class);
final TransportProperties local = new TransportProperties();
local.put("iso3166", ISO_1336);
TransportProperties p = new TransportProperties();
p.put("iso3166", ISO_1336);
p.put("number", NUMBER);
ContactId contactId = new ContactId(234);
final Map<ContactId, TransportProperties> remote =
Collections.singletonMap(contactId, p);
context.checking(new Expectations() {{
// start()
oneOf(serialPortList).getPortNames();
will(returnValue(new String[] { "foo" }));
oneOf(modemFactory).createModem(plugin, "foo");
will(returnValue(modem));
oneOf(modem).start();
will(returnValue(true));
// createConnection()
oneOf(callback).getLocalProperties();
will(returnValue(local));
oneOf(callback).getRemoteProperties();
will(returnValue(remote));
oneOf(modem).dial(NUMBER);
will(returnValue(false));
}});
plugin.start();
// No connection should be returned
assertNull(plugin.createConnection(contactId));
context.assertIsSatisfied();
}
示例8: testSaveLoad
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test(dataProvider = "editionProvider")
public void testSaveLoad(@NotNull final PowerShellEdition edition) throws IOException {
PowerShellInfo info = new PowerShellInfo(PowerShellBitness.x64, createTempDir(), "1.0", edition, "powershell.exe");
final Mockery m = new Mockery();
final BuildAgentConfiguration conf = m.mock(BuildAgentConfiguration.class);
final Map<String, String> confParams = new HashMap<String, String>();
m.checking(new Expectations(){{
allowing(conf).getConfigurationParameters(); will(returnValue(Collections.unmodifiableMap(confParams)));
allowing(conf).addConfigurationParameter(with(any(String.class)), with(any(String.class)));
will(new Action() {
public Object invoke(final Invocation invocation) throws Throwable {
final String key = (String) invocation.getParameter(0);
final String value = (String) invocation.getParameter(1);
Assert.assertNotNull(key);
Assert.assertNotNull(value);
confParams.put(key, value);
return null;
}
public void describeTo(final Description description) {
description.appendText("add Parameters");
}
});
}});
info.saveInfo(conf);
PowerShellInfo i = PowerShellInfo.loadInfo(conf, PowerShellBitness.x64);
Assert.assertNotNull(i);
Assert.assertEquals(i.getBitness(), info.getBitness());
Assert.assertEquals(i.getHome(), info.getHome());
Assert.assertEquals(i.getExecutablePath(), info.getExecutablePath());
Assert.assertEquals(i.getVersion(), info.getVersion());
Assert.assertEquals(i.getEdition(), info.getEdition());
Assert.assertEquals(i.getExecutable(), info.getExecutable());
}
示例9: testNotChangingVisibilityDoesNotCallListeners
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testNotChangingVisibilityDoesNotCallListeners()
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).containsGroup(txn, groupId);
will(returnValue(true));
oneOf(database).getGroupVisibility(txn, contactId, groupId);
will(returnValue(VISIBLE)); // Already visible
oneOf(database).commitTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
Transaction transaction = db.startTransaction(false);
try {
db.setGroupVisibility(transaction, contactId, groupId, VISIBLE);
db.commitTransaction(transaction);
} finally {
db.endTransaction(transaction);
}
context.assertIsSatisfied();
}
示例10: setUp
import org.jmock.Mockery; //導入方法依賴的package包/類
@BeforeMethod
@Override
protected void setUp() throws Exception {
super.setUp();
m = new Mockery();
ServerSettings serverSettings = m.mock(ServerSettings.class);
KubeAuthStrategyProvider authStrategies = m.mock(KubeAuthStrategyProvider.class);
myDeploymentContentProvider = m.mock(DeploymentContentProvider.class);
m.checking(new Expectations(){{
allowing(serverSettings).getServerUUID(); will(returnValue("server uuid"));
allowing(authStrategies).get(with(UnauthorizedAccessStrategy.ID)); will(returnValue(myAuthStrategy));
}});
myPodTemplateProvider = new DeploymentBuildAgentPodTemplateProvider(serverSettings, myDeploymentContentProvider);
}
開發者ID:JetBrains,項目名稱:teamcity-kubernetes-plugin,代碼行數:15,代碼來源:DeploymentBuildAgentPodTemplateProviderTest.java
示例11: testMessageDependencies
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testMessageDependencies() throws Exception {
final int shutdownHandle = 12345;
Mockery context = new Mockery();
final Database<Object> database = context.mock(Database.class);
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
final EventBus eventBus = context.mock(EventBus.class);
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
context.checking(new Expectations() {{
// open()
oneOf(database).open();
will(returnValue(false));
oneOf(shutdown).addShutdownHook(with(any(Runnable.class)));
will(returnValue(shutdownHandle));
// startTransaction()
oneOf(database).startTransaction();
will(returnValue(txn));
// addLocalMessage()
oneOf(database).containsGroup(txn, groupId);
will(returnValue(true));
oneOf(database).containsMessage(txn, messageId);
will(returnValue(false));
oneOf(database).addMessage(txn, message, DELIVERED, true);
oneOf(database).getGroupVisibility(txn, groupId);
will(returnValue(Collections.singletonList(contactId)));
oneOf(database).mergeMessageMetadata(txn, messageId, metadata);
oneOf(database).removeOfferedMessage(txn, contactId, messageId);
will(returnValue(false));
oneOf(database).addStatus(txn, contactId, messageId, false, false);
// addMessageDependencies()
oneOf(database).containsMessage(txn, messageId);
will(returnValue(true));
oneOf(database).addMessageDependency(txn, groupId, messageId,
messageId1);
oneOf(database).addMessageDependency(txn, groupId, messageId,
messageId2);
// getMessageDependencies()
oneOf(database).containsMessage(txn, messageId);
will(returnValue(true));
oneOf(database).getMessageDependencies(txn, messageId);
// getMessageDependents()
oneOf(database).containsMessage(txn, messageId);
will(returnValue(true));
oneOf(database).getMessageDependents(txn, messageId);
// broadcast for message added event
oneOf(eventBus).broadcast(with(any(MessageAddedEvent.class)));
oneOf(eventBus).broadcast(with(any(
MessageStateChangedEvent.class)));
oneOf(eventBus).broadcast(with(any(MessageSharedEvent.class)));
// endTransaction()
oneOf(database).commitTransaction(txn);
// close()
oneOf(shutdown).removeShutdownHook(shutdownHandle);
oneOf(database).close();
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
assertFalse(db.open());
Transaction transaction = db.startTransaction(false);
try {
db.addLocalMessage(transaction, message, metadata, true);
Collection<MessageId> dependencies = new ArrayList<MessageId>(2);
dependencies.add(messageId1);
dependencies.add(messageId2);
db.addMessageDependencies(transaction, message, dependencies);
db.getMessageDependencies(transaction, messageId);
db.getMessageDependents(transaction, messageId);
db.commitTransaction(transaction);
} finally {
db.endTransaction(transaction);
}
db.close();
context.assertIsSatisfied();
}
示例12: testWriterIsNotNullIfOutputDirIsADir
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testWriterIsNotNullIfOutputDirIsADir() 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);
// Create drive1 as a directory
assertTrue(drive1.mkdir());
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(0)); // The user chose drive1
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
callback, finder, monitor, 0);
plugin.start();
assertNotNull(plugin.createWriter(contactId));
// The output file should exist and should be empty
File[] files = drive1.listFiles();
assertNotNull(files);
assertEquals(1, files.length);
assertEquals(0, files[0].length());
context.assertIsSatisfied();
}
示例13: testWritingToWriter
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testWritingToWriter() 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);
// Create drive1 as a directory
assertTrue(drive1.mkdir());
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(0)); // The user chose drive1
oneOf(callback).showMessage(with(any(String[].class)));
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
callback, finder, monitor, 0);
plugin.start();
TransportConnectionWriter writer = plugin.createWriter(contactId);
assertNotNull(writer);
// The output file should exist and should be empty
File[] files = drive1.listFiles();
assertNotNull(files);
assertEquals(1, files.length);
assertEquals(0, files[0].length());
// Writing to the output stream should increase the size of the file
OutputStream out = writer.getOutputStream();
out.write(new byte[1234]);
out.flush();
out.close();
// Disposing of the writer should not delete the file
writer.dispose(false);
assertTrue(files[0].exists());
assertEquals(1234, files[0].length());
context.assertIsSatisfied();
}
示例14: testMergeSettings
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testMergeSettings() throws Exception {
final Settings before = new Settings();
before.put("foo", "bar");
before.put("baz", "bam");
final Settings update = new Settings();
update.put("baz", "qux");
final Settings merged = new Settings();
merged.put("foo", "bar");
merged.put("baz", "qux");
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() {{
// startTransaction()
oneOf(database).startTransaction();
will(returnValue(txn));
// mergeSettings()
oneOf(database).getSettings(txn, "namespace");
will(returnValue(before));
oneOf(database).mergeSettings(txn, update, "namespace");
oneOf(eventBus).broadcast(with(any(SettingsUpdatedEvent.class)));
// mergeSettings() again
oneOf(database).getSettings(txn, "namespace");
will(returnValue(merged));
// endTransaction()
oneOf(database).commitTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
Transaction transaction = db.startTransaction(false);
try {
// First merge should broadcast an event
db.mergeSettings(transaction, update, "namespace");
// Second merge should not broadcast an event
db.mergeSettings(transaction, update, "namespace");
db.commitTransaction(transaction);
} finally {
db.endTransaction(transaction);
}
context.assertIsSatisfied();
}
示例15: testValidatorRejectsShortMessage
import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testValidatorRejectsShortMessage() throws Exception {
Mockery context = new Mockery();
final DatabaseComponent db = context.mock(DatabaseComponent.class);
final ClientHelper clientHelper = context.mock(ClientHelper.class);
final QueueMessageFactory queueMessageFactory =
context.mock(QueueMessageFactory.class);
final ValidationManager validationManager =
context.mock(ValidationManager.class);
final AtomicReference<MessageValidator> captured =
new AtomicReference<MessageValidator>();
final QueueMessageValidator queueMessageValidator =
context.mock(QueueMessageValidator.class);
// The message is too short to be a valid queue message
final MessageId messageId = new MessageId(TestUtils.getRandomId());
final byte[] raw = new byte[QUEUE_MESSAGE_HEADER_LENGTH - 1];
final Message message = new Message(messageId, groupId, timestamp, raw);
context.checking(new Expectations() {{
oneOf(validationManager).registerMessageValidator(with(clientId),
with(any(MessageValidator.class)));
will(new CaptureArgumentAction<MessageValidator>(captured,
MessageValidator.class, 1));
}});
MessageQueueManagerImpl mqm = new MessageQueueManagerImpl(db,
clientHelper, queueMessageFactory, validationManager);
// Capture the delegating message validator
mqm.registerMessageValidator(clientId, queueMessageValidator);
MessageValidator delegate = captured.get();
assertNotNull(delegate);
// The message should be invalid
try {
delegate.validateMessage(message, group);
fail();
} catch (InvalidMessageException expected) {
// Expected
}
context.assertIsSatisfied();
}