Initialization problems while testing a GWTP Presenter

44 views
Skip to first unread message

Nils Werner

unread,
Sep 23, 2014, 2:44:04 AM9/23/14
to juk...@googlegroups.com
Hello :)

I am new to GWTP and Jukito. I am working on a webapp with the following sourcecode, which I simplified for your better understanding:

public class ClassA {
   
ClassB classB = null;
   
   
public void setClassB(ClassB classB) {
       
this.classB = classB;
   
}
   
   
public void reset() {
        classB
= null;
   
}
}

public class ClassB {
   
String text;
   
   
public String getText() {
       
return text;
   
}
   
   
public void setText(String text) {
       
this.text = text;
   
}
}

public class PresenterClass extends Presenter<PresenterClass.IView, PresenterClass.IProxy> {
   
public void interface IView extends View {
       
void setText(String text);
   
}
   
   
@ProxyStandard
   
public interfcae IProxy extends ProxyPlace<PresenterClass> {
   
}
   
   
private final ClassA classA;
   
   
@Inject
   
PresenterClass(final EventBus eventBus, final IView view, final IProxy proxy, final ClassA classA) {
       
super(eventBus, view, proxy, RevealType.RootLayout);
       
       
this.classA = classA;
   
}
   
   
@Override
   
protected void onReveal() {
       
super.onReveal();
       
       
String text;
       
if(classA.getClassB() != null && (text = classA.getClassB().getText()) != null)
            getView
().setText(text);
   
}
}

public class ViewClass extends ViewImpl implements PresenterClass.IView {
   
interface Binder extends UiBinder<Widget, ViewClass> {
   
}
   
   
@UiField
   
TextBox text;
   
   
@Inject
   
ViewClass(final Binder uiBinder) {
        initWidget
(uiBinder.createAndBindUi(this));
   
}
   
   
@Override
   
public void setText(String text) {
       
this.text.setText(text);
   
}
}

public class AppModule extends AbstractPresenterModule {
   
@Override
   
protected void configure() {
        install
(new DefaultModule());
       
        bind
(ClassA.class).asEagerSingleton();
       
        bindPresenter
(PresenterClass.class, PresenterClass.IView.class, ViewClass.class, PresenterClass.IProxy.class);
   
}
}

@RunWith(JukitoRunner.class)
public class PresenterClassTest {
   
@Inject
   
PresenterClass presenter;
   
   
@Test
   
public void shouldSetTextOnReveal(ClassA classA, PresenterClass.IView view) {
       
// given
       
String text = "dummy";
       
       
// when
        presenter
.onReveal();
       
       
// then
        verify
(view).setText(text);
   
}
}

The app is working like I expect it, but the test is failing. The problem is that the getView().setText(text) Method ist never called, because the text in ClassB in ClassA is null. So I should initialize it in the test, but how do I do this correctly?
I've been testing for a while, but without success.

I hope someone has a helpfull hint.

Greeting from germany ;)
Reply all
Reply to author
Forward
0 new messages