Last active
October 5, 2018 05:51
-
-
Save kasramp/3b7c43d0ce66ddeab1548328ce5725cd to your computer and use it in GitHub Desktop.
A test class written in JUnit4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.madadipouya.junit5.service.StudentService; | |
import com.madadipouya.junit5.service.CourseService; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.InjectMocks; | |
import org.mockito.Mock; | |
import org.mockito.runners.MockitoJUnitRunner; | |
import static org.mockito.Mockito.*; | |
import static org.junit.Assert.assertEquals; | |
@RunWith(MockitoJUnitRunner.class) | |
public class StudentServiceJUnit4Test { | |
@InjectMocks | |
private StudentService studentService; | |
@Mock | |
private CourseService courseService; | |
@Test | |
public void testCalculatingCGPA() { | |
long studentId = 1L | |
when(courseService.getAllCoursesByStudentId(anyLong())).thenReturn(stubCourses()); | |
long cGPA = studentService.getCGPA(studentId); | |
verify(courseService, times(1)).getAllCoursesByStudentId(anyLong()); | |
assertEquals("3.4", cGPA); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment