This is my service class:
@Path("/foo")
@RequestScoped
public class FooService {
@Inject @Log
Logger logger;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String ping() {
return "pong";
}
}
In the same module I have an util class that provides the logger using a Log interface with @Qualifier annotation
public class WebResources {
@Produces
@RequestScoped
public FacesContext produceFacesContext() {
return FacesContext.getCurrentInstance();
}
@Produces @Log
public Logger produceLog(InjectionPoint injectionPoint) {
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
}
Then I wrote a UnitTest using JUnit 5 + Weld SE
@EnableWeld
public class FooTest {
@WeldSetup
public WeldInitiator weld = WeldInitiator.from(FooService.class)
.activate(RequestScoped.class)
.build();
@Test
public void ping(FooService fooService) {
fooService.ping();
}
}
This produces the following error:
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Logger with qualifiers @Log
at injection point [BackedAnnotatedField] @Inject @Log it.infocert.shop.rest.FooService.logger
at it.infocert.shop.rest.FooService.logger(FooService.java:0)
How can I add the @Log dependency to Weld SE properly in a unit test?