You have several problems here.
One of the important points of a unit test of some CUT (code under test) is that you actually have to execute the CUT in order to test it. The flow of a test typically starts with a “setup” phase, where you assign some property values, create some mocks, and inject those mocks. You might then have a “execute CUT” phase, where you now execute the method of the CUT that you want to exercise and test. This is followed by a “assert and verify” phase, where you inspect the side effects of the CUT method and verify their correctness, and you also verify that particular business-logic-critical methods of your mocked instances were executed properly.
In your test, you seem to sort of have a “setup” phase, but you never execute the CUT, and you certainly don’t verify the side-effects of the CUT.
You should probably remove the creation of the “props” Map in your test, as you are only attempting to put things into it, but you never use it. In addition, you should almost never create a mock instance of a Map, and because you’re doing that, your “put” calls are ineffective. If you need to supply a Map with specific contents, just create an ordinary Map and populate it.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
For more options, visit https://groups.google.com/d/optout.
Hi Thanks, I just tried and modified but getting some excption :
public void testGetConfigProps() throws Exception {
SalesforceLeadSearch1 clt=new SalesforceLeadSearch1();Configuration config=mock(Configuration.class);Map props=new HashMap();
CryptoSupport cryptoSupport=mock(CryptoSupport.class);when(config.get("instanceurl","")).thenReturn("instanceurlVal").thenReturn(null);props.put("instanceurl", "instanceurlVal");when(config.get("accesstoken","")).thenReturn("accesstokenVal").thenReturn(null);props.put("accesstoken", "accesstokenVal");when(config.get("clientId","")).thenReturn("clientIdVal").thenReturn(null);props.put("clientId", "clientIdVal");
when(config.get("customersecret","")).thenReturn("customersecretVal").thenReturn("");when(cryptoSupport.isProtected("customersecretVal")).thenReturn(true);when(cryptoSupport.unprotect("customersecretVal")).thenReturn("customersecretValNew");when(config.get("customersecret","")).thenReturn("customersecretValNew").thenReturn(null);props.put("customersecret","customersecretValNew");
when(config.get("refreshToken", "")).thenReturn("refreshTokenVal").thenReturn(null);
when(cryptoSupport.isProtected("refreshTokenVal")).thenReturn(true);when(cryptoSupport.unprotect("refreshTokenVal")).thenReturn("refreshTokenValNew");when(config.get("refreshToken", "")).thenReturn("refreshTokenValNew").thenReturn(null);props.put("refreshToken","refreshTokenValNew");assertEquals(props,clt.getConfigProps(config));}Exception is :Expected :{accesstoken=accesstokenVal, instanceurl=instanceurlVal, refreshToken=refreshTokenValNew, clientId=clientIdVal, customersecret=customersecretValNew}Actual :{accesstoken=accesstokenVal, refreshToken=null, customerSecret=customersecretValNew, clientId=null, instanceUrl=instanceurlVal}
Learn how to execute your tests in the debugger. Set a breakpoint at that line and determine what is null, which should lead you to your next steps.
From: moc...@googlegroups.com [mailto:moc...@googlegroups.com] On Behalf Of Vivek
Sent: Tuesday, July 15, 2014 2:41 AM
To: moc...@googlegroups.com
--