Hi All,
We have recently upgrading one of our apps to Tapestry 4.1 and I have
been asked to write some unit tests for the existing components.
I am new to Tapestry, TestNG and Easymock, so please bear with me.
I am trying to get the test to run through an if statement, but I keep
getting the following runtime exception:
java.lang.IllegalStateException: missing behavior definition for the
preceeding method call getSession(true)
The class for the component is as follows:
public abstract class ViewProductDetail extends BaseComponent
{
@InjectObject("infrastructure:request")
public abstract WebRequest getRequest();
public abstract void setRequest(WebRequest webRequest);
@InjectState("visit")
public abstract Visit getSession();
public Double getSaving()
{
...
if(getRequest().getSession(false) != null)
{
Visit visit = getSession();
String discountcode = visit.getDiscountCode();
Double saving = new Double(rrp.getValue().doubleValue() -
price.getValue(discountcode).doubleValue());
return saving;
}
else
{
...
}
}
My Test class is as follows:
public class ViewProductDetailTest extends TestBase
{
...
@BeforeClass
public void setUp() {
viewProductDetail = newInstance(ViewProductDetail.class);
webRequest = createMock(WebRequest.class);
webRequest.getSession(true);
viewProductDetail.setRequest(webRequest);
}
@Test (dataProvider = "CreateProduct")
public void testGetSaving(Product product) {
try
{
viewProductDetail.setProduct(product);
Double saving = viewProductDetail.getSaving();
assertEquals(saving, 0.02);
}
catch(RuntimeException e){
System.out.println(e.toString());
}
}
I'm not sure to the best way to create a session so that my if statement
will be true. I'm trying to use webRequest.getSession(true), but it
doesnt seem to work and I don't know if there is a better way or if I
have missed something.
Thanks for any help
Ray
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]