本文整理汇总了Java中org.mockito.Answers类的典型用法代码示例。如果您正苦于以下问题:Java Answers类的具体用法?Java Answers怎么用?Java Answers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Answers类属于org.mockito包,在下文中一共展示了Answers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSslHandler
import org.mockito.Answers; //导入依赖的package包/类
private SslHandler getSslHandler() throws Exception {
// get SslHandler if it was added to the pipeline
ArgumentCaptor<ChannelHandler> captor = ArgumentCaptor.forClass(ChannelHandler.class);
verify(pipeline).addFirst(captor.capture());
SslHandler sslHandler = (SslHandler) captor.getValue();
// mock and store the context so we can get the handshake future
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
when(context.executor()).thenReturn(ImmediateEventExecutor.INSTANCE);
when(context.channel()).thenReturn(mock(Channel.class, Answers.RETURNS_MOCKS.get()));
// add the handler but prevent the handshake from running automatically
when(channel.isActive()).thenReturn(false);
sslHandler.handlerAdded(context);
return sslHandler;
}
示例2: createExecutionOperator
import org.mockito.Answers; //导入依赖的package包/类
public static ExecutionOperator createExecutionOperator(String name, int numInputs, int numOutputs, Platform platform) {
final ExecutionOperator mockedExecutionOperator = mock(ExecutionOperator.class, Answers.CALLS_REAL_METHODS);
when(mockedExecutionOperator.toString()).thenReturn("ExecutionOperator[" + name + "]");
when(mockedExecutionOperator.getPlatform()).thenReturn(platform);
// Mock input slots.
final InputSlot[] inputSlots = new InputSlot[numInputs];
for (int inputIndex = 0; inputIndex < numInputs; inputIndex++) {
inputSlots[inputIndex] = new InputSlot("input-" + inputIndex, mockedExecutionOperator, mock(DataSetType.class));
}
when(mockedExecutionOperator.getAllInputs()).thenReturn(inputSlots);
when(mockedExecutionOperator.getNumInputs()).thenCallRealMethod();
// Mock output slots.
final OutputSlot[] outputSlots = new OutputSlot[numOutputs];
for (int outputIndex = 0; outputIndex < numOutputs; outputIndex++) {
outputSlots[outputIndex] = new OutputSlot("output" + outputIndex, mockedExecutionOperator, mock(DataSetType.class));
}
when(mockedExecutionOperator.getAllOutputs()).thenReturn(outputSlots);
when(mockedExecutionOperator.getNumOutputs()).thenCallRealMethod();
return mockedExecutionOperator;
}
示例3: testConstructor_avoidsEclipseWriterBug
import org.mockito.Answers; //导入依赖的package包/类
@Test
public void testConstructor_avoidsEclipseWriterBug() throws IOException {
// Due to a bug in Eclipse, we *must* call close on the object returned from openWriter().
// Eclipse proxies a Writer but does not implement the fluent API correctly.
// Here, we implement the fluent Writer API with the same bug:
Writer mockWriter = Mockito.mock(Writer.class, new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (Writer.class.isAssignableFrom(invocation.getMethod().getReturnType())) {
// Erroneously return the delegate writer (matching the Eclipse bug!)
return source;
} else {
return Answers.RETURNS_SMART_NULLS.get().answer(invocation);
}
}
});
when(sourceFile.openWriter()).thenReturn(mockWriter);
FilerUtils.writeCompilationUnit(filer, CLASS_TO_WRITE, originatingElement, "Hello!");
verify(mockWriter).close();
}
示例4: init
import org.mockito.Answers; //导入依赖的package包/类
@BeforeTest
void init() {
EntityDictionary dictionary = new EntityDictionary(TestCheckMappings.MAPPINGS);
dictionary.bindEntity(Parent.class);
dictionary.bindEntity(Child.class);
dictionary.bindInitializer(Parent::doInit, Parent.class);
mapper = new JsonApiMapper(dictionary);
AuditLogger testLogger = new TestAuditLogger();
userScope = new RequestScope(null, new JsonApiDocument(),
mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS), new User(0), null,
new ElideSettingsBuilder(null)
.withJsonApiMapper(mapper)
.withAuditLogger(testLogger)
.withEntityDictionary(dictionary)
.build(), false);
}
示例5: testUpdateToOneRelationHookInAddRelation
import org.mockito.Answers; //导入依赖的package包/类
@Test
public void testUpdateToOneRelationHookInAddRelation() {
FunWithPermissions fun = new FunWithPermissions();
Child child = newChild(1);
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<FunWithPermissions> funResource = new PersistentResource<>(fun, null, "3", goodScope);
PersistentResource<Child> childResource = new PersistentResource<>(child, null, "1", goodScope);
funResource.addRelation("relation3", childResource);
verify(tx, times(1)).updateToOneRelation(eq(tx), eq(fun), any(), any(), eq(goodScope));
verify(tx, never()).updateToOneRelation(eq(tx), eq(child), any(), any(), eq(goodScope));
}
示例6: testUpdateToOneRelationHookInUpdateRelation
import org.mockito.Answers; //导入依赖的package包/类
@Test
public void testUpdateToOneRelationHookInUpdateRelation() {
FunWithPermissions fun = new FunWithPermissions();
Child child1 = newChild(1);
Child child2 = newChild(2);
fun.setRelation1(Sets.newHashSet(child1));
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<FunWithPermissions> funResource = new PersistentResource<>(fun, null, "3", goodScope);
PersistentResource<Child> child2Resource = new PersistentResource<>(child2, null, "1", goodScope);
funResource.updateRelation("relation3", Sets.newHashSet(child2Resource));
verify(tx, times(1)).updateToOneRelation(eq(tx), eq(fun), any(), any(), eq(goodScope));
verify(tx, never()).updateToOneRelation(eq(tx), eq(child1), any(), any(), eq(goodScope));
verify(tx, never()).updateToOneRelation(eq(tx), eq(child2), any(), any(), eq(goodScope));
}
示例7: testUpdateToOneRelationHookInRemoveRelation
import org.mockito.Answers; //导入依赖的package包/类
@Test
public void testUpdateToOneRelationHookInRemoveRelation() {
FunWithPermissions fun = new FunWithPermissions();
Child child = newChild(1);
fun.setRelation3(child);
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<FunWithPermissions> funResource = new PersistentResource<>(fun, null, "3", goodScope);
PersistentResource<Child> childResource = new PersistentResource<>(child, null, "1", goodScope);
funResource.removeRelation("relation3", childResource);
verify(tx, times(1)).updateToOneRelation(eq(tx), eq(fun), any(), any(), eq(goodScope));
verify(tx, never()).updateToOneRelation(eq(tx), eq(child), any(), any(), eq(goodScope));
}
示例8: testUpdateToManyRelationHookInAddRelationBidirection
import org.mockito.Answers; //导入依赖的package包/类
@Test
public void testUpdateToManyRelationHookInAddRelationBidirection() {
Parent parent = new Parent();
Child child = newChild(1);
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<Parent> parentResource = new PersistentResource<>(parent, null, "3", goodScope);
PersistentResource<Child> childResource = new PersistentResource<>(child, null, "1", goodScope);
parentResource.addRelation("children", childResource);
verify(tx, times(1)).updateToManyRelation(eq(tx), eq(parent),
any(), any(), any(), eq(goodScope));
verify(tx, times(1)).updateToManyRelation(eq(tx), eq(child),
any(), any(), any(), eq(goodScope));
}
示例9: testUpdateToManyRelationHookInRemoveRelationBidirection
import org.mockito.Answers; //导入依赖的package包/类
@Test
public void testUpdateToManyRelationHookInRemoveRelationBidirection() {
Parent parent = new Parent();
Child child = newChild(1);
parent.setChildren(Sets.newHashSet(child));
child.setParents(Sets.newHashSet(parent));
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<Parent> parentResource = new PersistentResource<>(parent, null, "3", goodScope);
PersistentResource<Child> childResource = new PersistentResource<>(child, null, "1", goodScope);
parentResource.removeRelation("children", childResource);
verify(tx, times(1)).updateToManyRelation(eq(tx), eq(parent),
any(), any(), any(), eq(goodScope));
verify(tx, times(1)).updateToManyRelation(eq(tx), eq(child),
any(), any(), any(), eq(goodScope));
}
示例10: testUpdateToManyRelationHookInClearRelationBidirection
import org.mockito.Answers; //导入依赖的package包/类
@Test
public void testUpdateToManyRelationHookInClearRelationBidirection() {
Parent parent = new Parent();
Child child1 = newChild(1);
Child child2 = newChild(2);
parent.setChildren(Sets.newHashSet(child1, child2));
child1.setParents(Sets.newHashSet(parent));
child2.setParents(Sets.newHashSet(parent));
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<Parent> parentResource = new PersistentResource<>(parent, null, "3", goodScope);
parentResource.clearRelation("children");
verify(tx, times(1)).updateToManyRelation(eq(tx), eq(parent),
any(), any(), any(), eq(goodScope));
verify(tx, times(1)).updateToManyRelation(eq(tx), eq(child1),
any(), any(), any(), eq(goodScope));
verify(tx, times(1)).updateToManyRelation(eq(tx), eq(child2),
any(), any(), any(), eq(goodScope));
}
示例11: testSuccessfulOneToOneRelationshipAdd
import org.mockito.Answers; //导入依赖的package包/类
@Test
public void testSuccessfulOneToOneRelationshipAdd() throws Exception {
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
Left left = new Left();
Right right = new Right();
left.setId(2);
right.setId(3);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<Left> leftResource = new PersistentResource<>(left, null, "2", goodScope);
Relationship ids = new Relationship(null, new Data<>(new ResourceIdentifier("right", "3").castToResource()));
when(tx.loadObject(eq(Right.class), eq(3L), any(), any())).thenReturn(right);
boolean updated = leftResource.updateRelation("one2one", ids.toPersistentResources(goodScope));
goodScope.saveOrCreateObjects();
verify(tx, times(1)).save(left, goodScope);
verify(tx, times(1)).save(right, goodScope);
Assert.assertEquals(updated, true, "The one-2-one relationship should be added.");
Assert.assertEquals(left.getOne2one().getId(), 3, "The correct object was set in the one-2-one relationship");
}
示例12: testDeleteCascades
import org.mockito.Answers; //导入依赖的package包/类
@Test
void testDeleteCascades() {
Invoice invoice = new Invoice();
invoice.setId(1);
LineItem item = new LineItem();
invoice.setItems(Sets.newHashSet(item));
item.setInvoice(invoice);
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<Invoice> invoiceResource = new PersistentResource<>(invoice, null, "1", goodScope);
invoiceResource.deleteResource();
verify(tx).delete(invoice, goodScope);
/* The inverse relation should not be touched for cascading deletes */
verify(tx, never()).save(item, goodScope);
Assert.assertEquals(invoice.getItems().size(), 1);
}
示例13: testDeleteResourceUpdateRelationshipSuccess
import org.mockito.Answers; //导入依赖的package包/类
@Test
void testDeleteResourceUpdateRelationshipSuccess() {
Parent parent = new Parent();
Child child = newChild(100);
parent.setChildren(Sets.newHashSet(child));
parent.setSpouses(Sets.newHashSet());
child.setParents(Sets.newHashSet(parent));
Assert.assertFalse(parent.getChildren().isEmpty());
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<Parent> parentResource = new PersistentResource<>(parent, null, "1", goodScope);
PersistentResource<Child> childResource = new PersistentResource<>(child, parentResource, "1", goodScope);
childResource.deleteResource();
goodScope.saveOrCreateObjects();
verify(tx, times(1)).delete(child, goodScope);
verify(tx, times(1)).save(parent, goodScope);
verify(tx, never()).delete(parent, goodScope);
Assert.assertTrue(parent.getChildren().isEmpty());
}
示例14: testAddRelationSuccess
import org.mockito.Answers; //导入依赖的package包/类
@Test
void testAddRelationSuccess() {
FunWithPermissions fun = new FunWithPermissions();
fun.setRelation1(Sets.newHashSet());
Child child = newChild(1);
User goodUser = new User(1);
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<FunWithPermissions> funResource = new PersistentResource<>(fun, null, "3", goodScope);
PersistentResource<Child> childResource = new PersistentResource<>(child, null, "1", goodScope);
funResource.addRelation("relation1", childResource);
goodScope.saveOrCreateObjects();
verify(tx, never()).save(child, goodScope); // Child wasn't modified
verify(tx, times(1)).save(fun, goodScope);
Assert.assertTrue(fun.getRelation1().contains(child), "The correct element should be added to the relation");
}
示例15: testRemoveToManyRelationSuccess
import org.mockito.Answers; //导入依赖的package包/类
@Test()
public void testRemoveToManyRelationSuccess() {
Child child = newChild(1);
Parent parent1 = newParent(1, child);
Parent parent2 = newParent(2, child);
Parent parent3 = newParent(3, child);
child.setParents(Sets.newHashSet(parent1, parent2, parent3));
DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS);
User goodUser = new User(1);
RequestScope goodScope = new RequestScope(null, null, tx, goodUser, null, elideSettings, false);
PersistentResource<Child> childResource = new PersistentResource<>(child, null, "1", goodScope);
PersistentResource<Object> removeResource = new PersistentResource<>(parent1, null, "1", goodScope);
childResource.removeRelation("parents", removeResource);
Assert.assertEquals(child.getParents().size(), 2, "The many-2-many relationship should be cleared");
Assert.assertEquals(parent1.getChildren().size(), 0, "The many-2-many inverse relationship should be cleared");
Assert.assertEquals(parent3.getChildren().size(), 1, "The many-2-many inverse relationship should not be cleared");
Assert.assertEquals(parent3.getChildren().size(), 1, "The many-2-many inverse relationship should not be cleared");
goodScope.saveOrCreateObjects();
verify(tx, times(1)).save(child, goodScope);
verify(tx, times(1)).save(parent1, goodScope);
verify(tx, never()).save(parent2, goodScope);
verify(tx, never()).save(parent3, goodScope);
}