Home How to test OS-specific method with JUnit?

# How to test OS-specific method with JUnit?

user3881
1#
user3881 Published in September 19, 2018, 9:23 am

I would like to test the following method with JUnit:

private static boolean systemIsWindows() {
String os = System.getProperty("os.name").toLowerCase();
return os.startsWith("win");
}


Frankly, the only thing I've come up with is to basically copy to same logic to the test. This would, of course, protect against the method being inadvertently broken, but sounds somehow counter-intuitive.

What would be a better way to test this method?