I have a spring bean component which I want to unit test for example:
@Component
public class UploadRequestTasklet implements Tasklet {
private final Uploader fileUploader;
public UploadRequestTasklet(@Qualifier("mainUploader") final Uploader fileUploader) {
this.fileUploader = fileUploader;
}
@Override
public RepeatStatus execute(final StepContribution stepContribution,
final ChunkContext chunkContext) throws IOException, InterruptedException {
Info result = fileUploader.remoteUpload(context, info);
return RepeatStatus.FINISHED;
}
}
I have multiple different implementation of Uploader
interface. For production, I use the mainUploader
which uploads files to remote server. For integration and unit test, I want to use the localFileUploader
implementation. The uploader classes live outside of my project and I have imported these classes from another project using maven dependency.
My question is, how can I override the mainuploader and in unit test, use the localFileUploader version?
the class UploadRequestTasklet has Qualifier annotation specifying to use main implementation which I cannot seem to override in unit test.
question from:
https://stackoverflow.com/questions/65617530/how-to-use-different-implementation-in-unit-test-when-class-injects-with-qualifi 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…