Please add the above dependency in your build.gradle code.
2. Make the sample VO Object.
We need a sample VO Object for knowing how does the Mockito Test is configured. so We will make the PersonVO like the below code.
1 2 3 4 5 6 7 8
@Data publicclassPersonVO { String name; int age; String major; }
3. @Mock
You can create the new object using this annotation. It’s really similar with the ‘autowired’ annotation in Spring but Mock annotation is only able to use in Test case.
1 2 3 4 5 6 7 8 9 10
import org.mockito.Mock;
publicclassPersonVOTest {
@Mock PersonVO;
}
at the above code, You can see the code creating the PersonVO object using @Mock annotation. Actually You need a one more code for creating the object using @Mock. It’s like the below
@Test publicvoidexample() { when(personVO.getName()).thenReturn("Mark"); // when you call the 'personVO.getName()' function then please return the 'Mark' String.
when(personVO.getAge()).thenReturn(20); // when you call the 'personVO.getAge()' function then return '20'.
when(personVO.getMajor()).thenReturn("Computer Engineering"); // when you call the 'personVO.getMajor()' then return 'Computer Engineering'.