jeudi 24 mars 2016

how does Mockito.when().return() works

I am trying mockito with Junit for the first time. I have written test method to test students details. Below is code, Please help me in understanding better, I have created studentService Mock object, and calling it go get student details. I am getting test passed, But I am not sure whether I am doing right or not

@mock
StudentService client;

@Test

    public void testGetStudentDetails() throws Exception {
            Student  student= new Student()
            student.setCustomerId("123");
            student.setRId("234");
            student.setClassNumber("100");
            Mockito.when(client.getStudentDetails(new Long(123), "1234")).thenReturn(student);
            Student sd=client.getStudentDetails(new Long(123), "1234");
            assertNotNull(sd);
        }

Aucun commentaire:

Enregistrer un commentaire