mardi 2 mai 2017

Static method returns empty value

I'm trying to add a test class for a static method :

class SomeClass {

    public static int getLoginPage() {
    if (otherStaticMethod()) {
      return Screen.FOO;
    }
    return Screen.BAR;
  }
}

Note that FOO and BAR have values differents of zero.

My test class :

@RunWith(PowerMockRunner.class)
@PrepareForTest({SomeClass.class})
public class SomeClass_getLoginPage {

  @Test
  public void testgetLoginPage() {    
PowerMockito.mockStatic(SomeClass.class);


    Mockito.when(SomeClass.otherStaticMethod()).thenReturn(true);

    assertTrue(SomeClass.getLoginPage() == Screen.FOO);


    Mockito.when(SomeClass.otherStaticMethod()).thenReturn(false);

    assertTrue(SomeClass.getLoginPage() == Screen.BAR);
  }
}

But when the method "otherStaticMethod" is called, the method getLoginPage returns 0, where it should return FOO or BAR. How can I fix that ?

Aucun commentaire:

Enregistrer un commentaire