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