You still need to call the replay() / verify() easymock methods, which can
be examined further here:

http://easymock.org/EasyMock2_2_Documentation.html

I think getSession(boolean) also returns a value - so you'd have to define
what that return value is with a statement like:

expect(webRequest.getSession(true)).andReturn(session); (or andReturn(null)
) .

On 6/1/07, Ray McBride <[EMAIL PROTECTED]> wrote:

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]




--
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

Reply via email to