How does one mock ConnectionHub.attach() using Mockito? Here is my
unsuccessful attempt where the matcher fails to match:
public TestHl7GatewayStatusUpdateSender() throws HL7Exception
{
mConnectionHubFactory = new FakeHapiConnectionHubFactory();
Connection fakeConnection = mock( Connection.class );
ConnectionHub connectionHub =
mConnectionHubFactory.newConnectionHub();
when( connectionHub.attach( anyString(),
anyInt(),
(Parser) any(),
(MinLowerLayerProtocol)any(),
anyBoolean() ) ).thenReturn(
fakeConnection );
}
public class FakeHapiConnectionHubFactory implements
HapiConnectionHubFactory
{
@Override
public ConnectionHub newConnectionHub()
{
return mock( ConnectionHub.class, "fake connection hub" );
}
}
Code under test:
...
// Returns the same "fake connection hub" as in the constructor.
ConnectionHub connectionHub =
mConnectionHubFactory.newConnectionHub();
// Returns null instead of mock connection.
Connection connection =
connectionHub.attach( "localhost",
5005,
createNonValidatingPipingParser(),
MinLowerLayerProtocol.class,
false );
// The initiator is used to transmit unsolicited messages to a
server.
Initiator initiator = connection.getInitiator();
...
Any ideas?
Derek
--
Derek Mahar
Senior Software Developer
Intelerad Medical Systems Incorporated
895 de la Gauchetiere W. Suite 400
Montreal, QC, Canada, H3B 4G1
Tel: 514.931.6222 x7754
Fax: 514.931.4653
derek.ma...@intelerad.com
www.intelerad.com
--
This email or any attachments may contain confidential or legally
privileged information intended for the sole use of the addressees. Any
use, redistribution, disclosure, or reproduction of this information,
except as intended, is prohibited. If you received this email in error,
please notify the sender and remove all copies of the message, including
any attachments.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel