lundi 4 février 2019

How to test a function which modify a mock member?

I have a problem with Mockito. I have two different class. My purpose is test “setChanges” function. this is my first class :

class M {
private String a;
private String b;
private boolean c = false;

public String getA() {
    return a;
} 
public String getC() {
    return c;
} 
public void setC( inal boolean imp ) {
     c = imp;
} 

}

this is the main class which has “setChanges” function:

class MyMainClass {
private String getMyA() {
    return "Data";
}

private static void setChanges(final M m) {
    if (getMyA().equals(m.getA())){
        m.setC(true);
    }
}

}

How can I test "setChanges"? Which means that if getA() returns "Data", How can I check getC() that should be "true"?

Aucun commentaire:

Enregistrer un commentaire