Created
September 16, 2018 18:13
-
-
Save lynas/6de5caec74ff95684112f8243be20ece to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.lynas.test.service; | |
import com.lynas.model.Course; | |
import com.lynas.model.Organization; | |
import com.lynas.model.OrganizationInfo; | |
import com.lynas.model.util.Section; | |
import com.lynas.model.util.Shift; | |
import com.lynas.repo.ClassRepository; | |
import com.lynas.service.ClassService; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.InjectMocks; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import org.mockito.runners.MockitoJUnitRunner; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import static org.mockito.Mockito.*; | |
import static org.junit.Assert.*; | |
@RunWith(MockitoJUnitRunner.class) | |
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) | |
//do not load web component | |
public class ClassServiceTest { | |
@Mock | |
private ClassRepository classRepository; | |
@InjectMocks | |
private ClassService classService; | |
@Before | |
public void setup() { | |
MockitoAnnotations.initMocks(this); | |
} | |
@Test | |
public void testCreateClass() { | |
Course mockCourse = new Course(1L, "One", Shift.MORNING, Section.SECTION_1, | |
new Organization(1L, "Police Lines", 1990, | |
new OrganizationInfo(1L, "Policeman", "Good man"))); | |
when(classRepository.save(any(Course.class))).thenReturn(mockCourse); | |
Course course = null; | |
Course course1 = classService.create(mockCourse); | |
assertEquals("one",course1.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment