I wonder if it is possible to test somehow class which is dependent on static final field? For example I have the following class:
public final class Foo
{
private static Foo instance;
public static final String BAR_FILE = "/usr/bin/bar.bar";
private Foo()
{
loadBar();
}
public static synchronized Foo getInstance()
{
if (instance == null)
{
instance = new Foo();
}
return instance;
}
private void loadBar()
{
final Properties prop = new Properties();
try
{
final FileInputStream fis = new FileInputStream(BAR_FILE);
prop.load(fis);
fis.close();
}
catch (final IOException ex)
{
System.out.println("Exception!");
}
}
}
So how can I test getInstance()
(I know there is nothing to test, but this is just an example) method on windows if BAR_FILE is hardcoded and equals to some unix-style path. I tried to change this field via reflection, but no luck, and, moreover, in accordance with this discussion it is not even possible. Any help is appreciated!