dimanche 22 janvier 2017

Take JSONObject as a parameter in Mockito mock method

I am trying to use Mockito to mock a method for my JUnit testing. The Method takes a JSONObject from simple-json as a parameter and responds with a JSONObject. I can not seem to get Mockito to catch my request and respond accordingly. Am I completely missing something here?

JSONObject jsonRequest;
JSONObject jsonReturn;

TestClass testClass = Mockito.mock(TestClass.class);

@Before
public void setUp(){
    jsonRequest = this.readJSONFromFile("jsonRequest.json");
    jsonReturn = this.readJSONFromFile("jsonReturn.json");
    Mockito.when(testClass.method(jsonRequest)).thenReturn(jsonReturn);
}

@Test
public void testMethod(){
   TestClass testClass = new TestClass();
   assertEquals(testClass.method(jsonRequest, jsonReturn));
}

Aucun commentaire:

Enregistrer un commentaire