Lavnish Lalchandani
unread,May 14, 2009, 9:21:49 AM5/14/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to powe...@googlegroups.com
Hi
I need to write a junit test case just for purpose of "code coverage". I know i am not really testing anything here.
here is the code that i need to mock
public static Object invokeEL(String el, Class[] paramTypes,
Object[] params)
{
theLogger.entering("TemplateBean","invokeEL");
// FacesContext facesContext = FacesContext.getCurrentInstance();
// ELContext elContext = facesContext.getELContext();
// Application app = facesContext.getApplication();
// ExpressionFactory expressionFactory =app.getExpressionFactory();
// MethodExpression exp =expressionFactory.createMethodExpression(elContext, el,Object.class, paramTypes);
theLogger.exiting("TemplateBean","invokeEL");
// Object retVal = exp.invoke(elContext, params);
return null;
}
here is my test case
public void testInvokeEL()
{
FacesContext mockFC =
PowerMock.createMock(FacesContext.class); //System.out.println("testRefreshPage 2");
PowerMock.mockStatic(FacesContext.class);
ELContext mockEC = PowerMock.createMock(ELContext.class);
Application mockAPP = PowerMock.createMock(Application.class);
ExpressionFactory mockEF = PowerMock.createMock(ExpressionFactory.class);
MethodExpression mockME = PowerMock.createMock(MethodExpression.class);
Object retObj = new Object();
// org.easymock.EasyMock.expect(FacesContext.getCurrentInstance()).andReturn(mockFC);
// org.easymock.EasyMock.expect(mockFC.getELContext()).andReturn(mockEC);
// org.easymock.EasyMock.expect(mockFC.getApplication()).andReturn(mockAPP);
// org.easymock.EasyMock.expect(mockAPP.getExpressionFactory()).andReturn(mockEF);
// org.easymock.EasyMock.expect(mockEF.createMethodExpression(mockEC,"testInvokeEL",Object.class,null)).andReturn(mockME);
// org.easymock.EasyMock.expect(mockME.invoke(mockEC,null)).andReturn(retObj);
PowerMock.replayAll();
Object temp = TemplateBean.invokeEL("testInvokeEL",null,null); // this is line no 289 , where i get error
PowerMock.verifyAll();
}
I get the error with either lines commented or uncommented
I get exception
java.lang.IllegalStateException : This method must not be called in replay state
org.easymock.internal.MocksControl.replay(mocksControl.java:91)
org.powermock.api.easymock.internal.invocationcontrol.EasyMockMethodInvocationControl.replay(EasyMockMethodInvocationControl:104)
org.powermock.api.easymock.PowerMock.replay(PowerMock:1573)
org.powermock.api.easymock.PowerMock.replayAll(PowerMock:1438)
mypackage.QATemplateBean.testinvokeEL(QATemplateBean:289)
I dont understand what the error is and why i am getting it ?
will appreciate any help.