vendredi 18 décembre 2015

Second call to mock returns null - jmockit

When the mock is invoked the first time, it returns today's date but when it's invoked the second time, it returns null. Why? How can I fix it?

Class under test:

public class MyService{

    public String execute(){
            Controller.getDBMSCurrentDate(); // returns today's date
            //Some other code....
            Controller.getDBMSCurrentDate(); // returns null
    }
}

Test:

@Test
public void testMyMethod(@Mocked Controller controller){
    new NonStrictExpectations() {           
            {
                Controller.getDBMSCurrentDate();
                result = new Date().toString();
            }
    };

    service.execute();

}

Aucun commentaire:

Enregistrer un commentaire