Issue 413 in mockito: Wanted but not invoked: Actually, there were zero interactions with this mock

411 views
Skip to first unread message

moc...@googlecode.com

unread,
Jan 25, 2013, 7:49:09 AM1/25/13
to mocki...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 413 by dlaksh...@cordys.com: Wanted but not invoked: Actually,
there were zero interactions with this mock
http://code.google.com/p/mockito/issues/detail?id=413

Error:

Wanted but not invoked:
provider.startAudit(
"cn=dlakshman,cn=organizational
users,o=system,cn=cordys,cn=Audit,o=vanenburg.com",
"XMLS tore",
"/Cordys/Test/test.log",
"UpdateXMLObject",
"o=system,cn=cordys,cn=Audit,o=vanenburg.com",
"Add",
"input",
Cordys.XMLStore.Messages.xmlstoreUpdateEntryStart,
""
);->



at
com.cordys.XMLStoreAudit.MockXMLStoreAuditTest.verifyUpdate(MockXMLStoreAuditTest.java:146)
Actually, there were zero interactions with this mock.

at
com.cordys.XMLStoreAudit.MockXMLStoreAuditTest.verifyUpdate(MockXMLStoreAuditTest.java:146)
at
com.cordys.XMLStoreAudit.MockXMLStoreAuditTest.testAuditXMLStoreCreate(MockXMLStoreAuditTest.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)



test class:
{@RunWith(MockitoJUnitRunner.class)
public class MockXMLStoreAuditTest
{
private static final String XMLSTORE_ARTIFACT_TYPE = "XMLS tore";

private static final String USER_DN
= "cn=dlakshman,cn=organizational
users,o=system,cn=cordys,cn=Audit,o=vanenburg.com";

private static final String DESCRIPTION
= "UpdateXMLObject";

private static final String ORG_DN
= "o=system,cn=cordys,cn=Audit,o=vanenburg.com";

public @Rule
SystemPropertySetter propertiesSetter = new
SystemPropertySetter();

@Mock
AuditProvider provider;
@Mock
AuditRecording recording;

private Connector connector;
@Before
public void setAuditInspector() throws ExceptionGroup,
DirectoryException
{
propertiesSetter.setValue(Audit.AUDITPROVIDER_PROPERTY_NAME,
TestAuditProvider.class.getCanonicalName());
TestAuditProvider.auditProvider = provider;

when(provider.isAuditEnabled(anyString(),
anyString())).thenReturn(true);
when(provider.startAudit(anyString(),
isA(String.class),
isA(String.class),
isA(String.class),
isA(String.class),
isA(String.class),
anyString(),
isA(IStringResource.class),
anyVararg())).thenReturn(recording);

connector = Connector.getInstance("XMLStore");
if(!connector.isOpen())
{
connector.open();
}
}
@Test
public void testAuditXMLStoreCreate () throws Exception
{
updateXMLObject("Add");
verifyUpdate("Add");
}


private void updateXMLObject ( String operation ) throws
DirectoryException, XMLException, TimeoutException,
ExceptionGroup, UnsupportedEncodingException
{
int request = 0;
int response = 0;
try
{
request =
connector.createSOAPMethod("http://schemas.cordys.com/1.0/xmlstore", "UpdateXMLObject");
Node.appendToChildren(XPath.getFirstMatch(".//" + operation
+ "/tuple",
null,NomUtil.readResourceAsNom(getClass(), "UpdateXMLRequests.xml")),
request);
response = connector.sendAndWait(request);
}
finally
{
Node.delete(request);
Node.delete(response);
}
}

private void verifyUpdate (String actionType)
{
verify(provider).startAudit(USER_DN,
XMLSTORE_ARTIFACT_TYPE,
"/Cordys/Test/test.log",
DESCRIPTION,
ORG_DN,
actionType,
"input",

Messages.XMLSTORE_UPDATE_ENTRY_START,
"");
verify(recording).completed(AuditStatus.COMPLETE,
Messages.XMLSTORE_AUDIT_ENTRY_COMPLETE, anyString());
verify(provider).isAuditEnabled(ORG_DN, XMLSTORE_ARTIFACT_TYPE);

}
}

The following statement will call startAudit() method internally.

response = connector.sendAndWait(request);

I think it is not calling the mocked startAudit()(from TestAuditProvider)
instead it is calling actual startAudit()(from AuditProvider).

please help:

thanks





moc...@googlecode.com

unread,
Jan 25, 2013, 7:51:00 AM1/25/13
to mocki...@googlegroups.com

Comment #1 on issue 413 by dlaksh...@cordys.com: Wanted but not invoked:
Actually, there were zero interactions with this mock
http://code.google.com/p/mockito/issues/detail?id=413

SystemPropertySetter is to set system properties with key and value.

Mocking is not happening I guess.

moc...@googlecode.com

unread,
Jan 28, 2013, 10:30:21 AM1/28/13
to mocki...@googlegroups.com
Updates:
Status: Invalid

Comment #2 on issue 413 by brice.du...@gmail.com: Wanted but not invoked:
Actually, there were zero interactions with this mock
http://code.google.com/p/mockito/issues/detail?id=413

Hi,

Your test code looks complex, I'm not sure what's wrong because it's not
straightforward. Plus it seems the code is using statics which is most of
the time a bad idea.

In my opinion you should check that the code is actually calling the real
mock instance, or that the method being mocked is not final.

I'll invalidate the issue, but if you feel there is a real bug, please say
so :)
Also instead of creating an issue please ask on the mailing-list.
Hope that helps.

Reply all
Reply to author
Forward
0 new messages