Skip to content

Instantly share code, notes, and snippets.

@tinmegali
Created October 28, 2019 16:17
Show Gist options
  • Save tinmegali/9de2fe21e44ec62ac0215b0e207ee503 to your computer and use it in GitHub Desktop.
Save tinmegali/9de2fe21e44ec62ac0215b0e207ee503 to your computer and use it in GitHub Desktop.
// reference: https://stackoverflow.com/a/34613097/4871489
@RunWith(SpringRunner.class)
// use the exclusive configuration for the test
@SpringBootTest(classes = {CourseApp.class, InstructorResourceIntTest.InstructorResourceTestConfig.class})
public class InstructorResourceIntTest {
// create an exclusive configuration for the test, turning on global security for it
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
protected static class InstructorResourceTestConfig {
@Bean
@Primary
public InstructorService instructorService(InstructorRepository repository, InstructorMapper mapper) {
// mocked classes
EurekaClients eurekaClients = Mockito.mock(EurekaClients.class);
RestTemplate restTemplate = Mockito.mock(RestTemplate.class);
// use the mocks to build the class using @PreAuthorize methods
return new InstructorServiceImpl( repository, mapper, eurekaClients, restTemplate);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment