I developed a component in a library with sprin libraries. My component is as follows:
@Component
@RequestScope
public class RequestInfoComponent {
@Autowired
private HttpServletRequest reques;
...
}
The needed dependencies are as follows:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
Now I want to write some test case. I add spring-boot-starter-test
dependency. Now I want to mock HttpServletRequest.getHeader('Authorization')
in a @SpringBootTest
test case. I want to know How define test services?
I developed a spring component and I want to write unit test for it.