4

Given this really simple Wicket component:

public class ProductImage extends WebComponent {

    public ProductImage(String id, Product p) {
        super(id, new Model(p));
        add(new AttributeModifier("src", true, new Model(p.getImage())));
    }
}

How to unit test it using WicketTester? Do I need a page?

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
Eduardo Costa
  • 1,974
  • 1
  • 16
  • 22

2 Answers2

6

In Wicket 1.5 there is #startComponentInPage(Component) which will create a page for you so you can test any kind of component.

martin-g
  • 17,243
  • 2
  • 23
  • 35
3

I haven't actually done that (I've only tested panels), but startComponent() seems to be the way to do it.

Something like this:

Product product = new Product(/* initialize product here */);
ProductImage pi = new ProductImage("image", product);
tester.startComponent(pi);
tester.assertContains(Pattern.quote(product.getImage()));
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588