Quarkus : Mock bean in dev mode

63 Views Asked by At

In my Quarkus application have a bean with a grpc client :

@ApplicationScoped
@Slf4j
public class AuthorizationAdapter implements AuthorizationPort {

    private final AuthorizationGrpc.AuthorizationBlockingStub authorizationBlockingStub;

    public AuthorizationAdapter(
            @GrpcClient("authorization") AuthorizationGrpc.AuthorizationBlockingStub authorizationBlockingStub) {
        this.authorizationBlockingStub = authorizationBlockingStub;
    }

    @Override
    public boolean canActorReadReport(Actor actor, UUID reportId) {
        ... call authorizationBlockingStub here

    }
}

For test i managed to mock this bean with :

@ApplicationScoped
@Mock
public class MockAuthorizationAdapter implements AuthorizationPort {

    @Override
    public boolean canActorReadReport(Actor actor, UUID reportId) {
        return true;
    }
}

But in dev mode i want to do the same (i don't have and want to start a grpc server). How can i do ? I am aware that i could annotate this bean with @IfBuildProfile("prod") and create another one mocked but it would pollute my src/main/java and i don't want that. Is it possible to achieve this in an elegant way ?

0

There are 0 best solutions below