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


Java Mockery.mock方法代碼示例

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


在下文中一共展示了Mockery.mock方法的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();
	}
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:26,代碼來源:DatabaseComponentImplTest.java

示例2: 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

示例3: 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

示例4: 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();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:33,代碼來源:DatabaseComponentImplTest.java

示例5: testGenerateRequest

import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testGenerateRequest() throws Exception {
	final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
	final Collection<MessageId> ids = Arrays.asList(messageId, messageId1);
	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).getMessagesToRequest(txn, contactId, 123);
		will(returnValue(ids));
		oneOf(database).removeOfferedMessages(txn, contactId, ids);
		oneOf(database).commitTransaction(txn);
	}});
	DatabaseComponent db = createDatabaseComponent(database, eventBus,
			shutdown);

	Transaction transaction = db.startTransaction(false);
	try {
		Request r = db.generateRequest(transaction, contactId, 123);
		assertNotNull(r);
		assertEquals(ids, r.getMessageIds());
		db.commitTransaction(transaction);
	} finally {
		db.endTransaction(transaction);
	}

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

示例6: testLocalMessagesAreNotStoredUnlessGroupExists

import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testLocalMessagesAreNotStoredUnlessGroupExists()
		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).containsGroup(txn, groupId);
		will(returnValue(false));
		oneOf(database).abortTransaction(txn);
	}});
	DatabaseComponent db = createDatabaseComponent(database, eventBus,
			shutdown);

	Transaction transaction = db.startTransaction(false);
	try {
		db.addLocalMessage(transaction, message, metadata, true);
		fail();
	} catch (NoSuchGroupException expected) {
		// Expected
	} finally {
		db.endTransaction(transaction);
	}

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

示例7: testReceiveMessageWithoutVisibleGroup

import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testReceiveMessageWithoutVisibleGroup() 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).getGroupVisibility(txn, contactId, groupId);
		will(returnValue(INVISIBLE));
		oneOf(database).commitTransaction(txn);
	}});
	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,代碼行數:30,代碼來源:DatabaseComponentImplTest.java

示例8: 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

示例9: SimplexOutgoingSessionTest

import org.jmock.Mockery; //導入方法依賴的package包/類
public SimplexOutgoingSessionTest() {
	context = new Mockery();
	db = context.mock(DatabaseComponent.class);
	dbExecutor = new ImmediateExecutor();
	eventBus = context.mock(EventBus.class);
	recordWriter = context.mock(RecordWriter.class);
	contactId = new ContactId(234);
	messageId = new MessageId(TestUtils.getRandomId());
	maxLatency = Integer.MAX_VALUE;
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:11,代碼來源:SimplexOutgoingSessionTest.java

示例10: IntroducerManagerTest

import org.jmock.Mockery; //導入方法依賴的package包/類
public IntroducerManagerTest() {
	context = new Mockery();
	context.setImposteriser(ClassImposteriser.INSTANCE);
	messageSender = context.mock(MessageSender.class);
	cryptoComponent = context.mock(CryptoComponent.class);
	clientHelper = context.mock(ClientHelper.class);
	clock = context.mock(Clock.class);
	introductionGroupFactory =
			context.mock(IntroductionGroupFactory.class);

	introducerManager =
			new IntroducerManager(messageSender, clientHelper, clock,
					cryptoComponent, introductionGroupFactory);

	AuthorId authorId1 = new AuthorId(TestUtils.getRandomId());
	Author author1 = new Author(authorId1, "Introducee1",
			TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
	AuthorId localAuthorId1 = new AuthorId(TestUtils.getRandomId());
	ContactId contactId1 = new ContactId(234);
	introducee1 =
			new Contact(contactId1, author1, localAuthorId1, true, true);

	AuthorId authorId2 = new AuthorId(TestUtils.getRandomId());
	Author author2 = new Author(authorId2, "Introducee2",
			TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
	AuthorId localAuthorId2 = new AuthorId(TestUtils.getRandomId());
	ContactId contactId2 = new ContactId(235);
	introducee2 =
			new Contact(contactId2, author2, localAuthorId2, true, true);

	localGroup0 = new Group(new GroupId(TestUtils.getRandomId()),
			getClientId(), new byte[0]);
	introductionGroup1 = new Group(new GroupId(TestUtils.getRandomId()),
			getClientId(), new byte[0]);
	introductionGroup2 = new Group(new GroupId(TestUtils.getRandomId()),
			getClientId(), new byte[0]);

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

示例11: 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();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:48,代碼來源:DatabaseComponentImplTest.java

示例12: testTagIsNotRecognisedTwice

import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testTagIsNotRecognisedTwice() 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 boolean alice = true;
	final TransportKeys transportKeys = createTransportKeys(1000, 0);
	// Keep a copy of the tags
	final List<byte[]> tags = new ArrayList<byte[]>();
	final Transaction txn = new Transaction(null, false);

	context.checking(new Expectations() {{
		oneOf(crypto).deriveTransportKeys(transportId, masterKey, 1000,
				alice);
		will(returnValue(transportKeys));
		// Get the current time (the start of rotation period 1000)
		oneOf(clock).currentTimeMillis();
		will(returnValue(rotationPeriodLength * 1000));
		// Encode the tags (3 sets)
		for (long i = 0; i < REORDERING_WINDOW_SIZE; i++) {
			exactly(3).of(crypto).encodeTag(with(any(byte[].class)),
					with(tagKey), with(i));
			will(new EncodeTagAction(tags));
		}
		// Rotate the transport keys (the keys are unaffected)
		oneOf(crypto).rotateTransportKeys(transportKeys, 1000);
		will(returnValue(transportKeys));
		// Save the keys
		oneOf(db).addTransportKeys(txn, contactId, transportKeys);
		// Encode a new tag after sliding the window
		oneOf(crypto).encodeTag(with(any(byte[].class)),
				with(tagKey), with((long) REORDERING_WINDOW_SIZE));
		will(new EncodeTagAction(tags));
		// Save the reordering window (previous rotation period, base 1)
		oneOf(db).setReorderingWindow(txn, contactId, transportId, 999,
				1, new byte[REORDERING_WINDOW_SIZE / 8]);
	}});

	TransportKeyManager
			transportKeyManager = new TransportKeyManagerImpl(db,
			crypto, dbExecutor, scheduler, clock, transportId, maxLatency);
	// The timestamp is at the start of rotation period 1000
	long timestamp = rotationPeriodLength * 1000;
	transportKeyManager.addContact(txn, contactId, masterKey, timestamp,
			alice);
	// Use the first tag (previous rotation period, stream number 0)
	assertEquals(REORDERING_WINDOW_SIZE * 3, tags.size());
	byte[] tag = tags.get(0);
	// The first request should return a stream context
	StreamContext ctx = transportKeyManager.getStreamContext(txn, tag);
	assertNotNull(ctx);
	assertEquals(contactId, ctx.getContactId());
	assertEquals(transportId, ctx.getTransportId());
	assertEquals(tagKey, ctx.getTagKey());
	assertEquals(headerKey, ctx.getHeaderKey());
	assertEquals(0L, ctx.getStreamNumber());
	// Another tag should have been encoded
	assertEquals(REORDERING_WINDOW_SIZE * 3 + 1, tags.size());
	// The second request should return null, the tag has already been used
	assertNull(transportKeyManager.getStreamContext(txn, tag));

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

示例13: testSendingMessages

import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testSendingMessages() 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 Transaction txn = new Transaction(null, false);
	final byte[] body = new byte[123];
	final Metadata groupMetadata = new Metadata();
	final Metadata messageMetadata = new Metadata();
	final Metadata groupMetadata1 = new Metadata();
	final byte[] queueState = new byte[123];
	groupMetadata1.put(QUEUE_STATE_KEY, queueState);

	context.checking(new Expectations() {{
		// First message: queue state does not exist
		oneOf(db).getGroupMetadata(txn, groupId);
		will(returnValue(groupMetadata));
		oneOf(clientHelper).toByteArray(with(any(BdfDictionary.class)));
		will(new EncodeQueueStateAction(1L, 0L, new BdfList()));
		oneOf(db).mergeGroupMetadata(with(txn), with(groupId),
				with(any(Metadata.class)));
		oneOf(queueMessageFactory).createMessage(groupId, timestamp, 0L,
				body);
		will(new CreateMessageAction());
		oneOf(db).addLocalMessage(with(txn), with(any(QueueMessage.class)),
				with(messageMetadata), with(true));
		// Second message: queue state exists
		oneOf(db).getGroupMetadata(txn, groupId);
		will(returnValue(groupMetadata1));
		oneOf(clientHelper).toDictionary(queueState, 0, queueState.length);
		will(new DecodeQueueStateAction(1L, 0L, new BdfList()));
		oneOf(clientHelper).toByteArray(with(any(BdfDictionary.class)));
		will(new EncodeQueueStateAction(2L, 0L, new BdfList()));
		oneOf(db).mergeGroupMetadata(with(txn), with(groupId),
				with(any(Metadata.class)));
		oneOf(queueMessageFactory).createMessage(groupId, timestamp, 1L,
				body);
		will(new CreateMessageAction());
		oneOf(db).addLocalMessage(with(txn), with(any(QueueMessage.class)),
				with(messageMetadata), with(true));
	}});

	MessageQueueManagerImpl mqm = new MessageQueueManagerImpl(db,
			clientHelper, queueMessageFactory, validationManager);

	// First message
	QueueMessage q = mqm.sendMessage(txn, group, timestamp, body,
			messageMetadata);
	assertEquals(groupId, q.getGroupId());
	assertEquals(timestamp, q.getTimestamp());
	assertEquals(0L, q.getQueuePosition());
	assertEquals(QUEUE_MESSAGE_HEADER_LENGTH + body.length, q.getLength());

	// Second message
	QueueMessage q1 = mqm.sendMessage(txn, group, timestamp, body,
			messageMetadata);
	assertEquals(groupId, q1.getGroupId());
	assertEquals(timestamp, q1.getTimestamp());
	assertEquals(1L, q1.getQueuePosition());
	assertEquals(QUEUE_MESSAGE_HEADER_LENGTH + body.length, q1.getLength());

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

示例14: testOutgoingStreamContextIsNullIfStreamCounterIsExhausted

import org.jmock.Mockery; //導入方法依賴的package包/類
@Test
public void testOutgoingStreamContextIsNullIfStreamCounterIsExhausted()
		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 boolean alice = true;
	// The stream counter has been exhausted
	final TransportKeys transportKeys = createTransportKeys(1000,
			MAX_32_BIT_UNSIGNED + 1);
	final Transaction txn = new Transaction(null, false);

	context.checking(new Expectations() {{
		oneOf(crypto).deriveTransportKeys(transportId, masterKey, 1000,
				alice);
		will(returnValue(transportKeys));
		// Get the current time (the start of rotation period 1000)
		oneOf(clock).currentTimeMillis();
		will(returnValue(rotationPeriodLength * 1000));
		// Encode the tags (3 sets)
		for (long i = 0; i < REORDERING_WINDOW_SIZE; i++) {
			exactly(3).of(crypto).encodeTag(with(any(byte[].class)),
					with(tagKey), with(i));
			will(new EncodeTagAction());
		}
		// Rotate the transport keys (the keys are unaffected)
		oneOf(crypto).rotateTransportKeys(transportKeys, 1000);
		will(returnValue(transportKeys));
		// Save the keys
		oneOf(db).addTransportKeys(txn, contactId, transportKeys);
	}});

	TransportKeyManager
			transportKeyManager = new TransportKeyManagerImpl(db,
			crypto, dbExecutor, scheduler, clock, transportId, maxLatency);
	// The timestamp is at the start of rotation period 1000
	long timestamp = rotationPeriodLength * 1000;
	transportKeyManager.addContact(txn, contactId, masterKey, timestamp,
			alice);
	assertNull(transportKeyManager.getStreamContext(txn, contactId));

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

示例15: 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();
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:78,代碼來源:DatabaseComponentImplTest.java


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