I have a class which is dependent on an environment variable. I would like to test it with a mock environment variable.
I think a good structure would be to inject the dependency in Spring Boot and then mock it in the test environment. How do I achieve this?
For example with the following code:
@Component
public class ProcessorClass implements Processor {
public String readFile(String fileName) throws IOException {
String fileOut;
String path = Environment.getVariable("READ_PATH");
fileOut = new String(Files.readAllBytes(Paths.get(path + fileName)));
return fileOut
How would I inject READ_PATH
such that I can then mock it within JUnit5.
Environment
is a fake class that currently returns a value from System.getenv("...")
Thank you.
Aucun commentaire:
Enregistrer un commentaire