Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gwtmockito and GXT #74

Open
fpezzati opened this issue Jun 7, 2018 · 1 comment
Open

gwtmockito and GXT #74

fpezzati opened this issue Jun 7, 2018 · 1 comment

Comments

@fpezzati
Copy link

fpezzati commented Jun 7, 2018

Hello,

I'm trying to build unit tests about widget who uses GWT 2.7.0 and GXT 3.1.4 components. Unfortunately as soon as test encounter a GXT component it raises a NullPointerException. Here is my dummy widget:

public class SomePanel {

private HorizontalPanel pnl;
private Button btn;
private Label lbl;
private TextButton displaySome;

public SomePanel() {
   pnl = new HorizontalPanel();
   btn = new Button("Hey");
   lbl = new Label("Unclicked");
   btn.addClickHandler(new ClickHandler() {
       @Override
       public void onClick(ClickEvent event) {
           if ("Unclicked".equals(lbl.getText())) {
               lbl.setText("Clicked");
           } else {
               lbl.setText("Unclicked");
           }
       }
   });
   displaySome = new TextButton("Display some.");
 }

 public HorizontalPanel getPnl() {
   return pnl;
 }

 public Button getBtn() {
   return btn;
 }

 public Label getLbl() {
   return lbl;
 }

 public TextButton getDisplaySome() {
   return displaySome;
 }
}

And this is the test who goes wrong:

@RunWith(GwtMockitoTestRunner.class)
public class SomePanelTest {

  private SomePanel pnl;

  @Test
  public void checkLabels() {
    pnl = new SomePanel();
    Assert.assertEquals("Unclicked", pnl.getLbl().getText());
    pnl.getBtn().click();
    Assert.assertEquals("Clicked", pnl.getLbl().getText());
    pnl.getBtn().click();
    Assert.assertEquals("Unclicked", pnl.getLbl().getText());
    Assert.assertEquals("Display", pnl.getDisplaySome().getText());
  }
}

This is the exception:

java.lang.NullPointerException
at com.sencha.gxt.core.client.resources.CommonStyles.get(CommonStyles.java:96)
at com.sencha.gxt.widget.core.client.cell.CellComponent.createDefaultWrapperElement(CellComponent.java:55)
at com.sencha.gxt.widget.core.client.cell.CellComponent.<init>(CellComponent.java:141)
at com.sencha.gxt.widget.core.client.button.CellButtonBase.<init>(CellButtonBase.java:44)
at com.sencha.gxt.widget.core.client.button.TextButton.<init>(TextButton.java:35)
at com.sencha.gxt.widget.core.client.button.TextButton.<init>(TextButton.java:25)
at edu.me.gwt.client.SomePanel.<init>(SomePanel.java:32)
...

I would like to know if gwtmockito is the right tool to use together GXT (I am bound to GXT 3.1.4) and if it is, what am I missing then. TIA.

@ekuefler
Copy link
Collaborator

Most likely this means that there's a class inside GXT somewhere that's relying on a native method. Could you try annotating your test with either @WithClassesToStub(TextButton.class) or @WithClassesToSub(CommonStyle.class) and see if that helps? More details at https://static.javadoc.io/com.google.gwt.gwtmockito/gwtmockito/1.1.8/com/google/gwtmockito/WithClassesToStub.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants