To convert -1.0D to a Double, the best way us usually to use Double.valueOf(-1.0D). The Double class caches the results of calls to valueOf so that you won't always be creating a new object on the heap. But even better is to convert out to a double, which is cheaper. Use out.doubleValue()
to get the value as a double. The only caveat is that out might be null, which is a separate case that is probably worth detecting in its own right.
You should also be wary of floating-point inaccuracies when testing direct equality this way. Two numbers that are theoretically equal may not have representations that are exactly equal because there is some rounding error introduced with most floating-point operations. A simple solution that would work in this case is to test if the difference is less than some delta:
assertTrue(Math.abs(-1.0D-out.doubleValue()) < delta);
You can also use JUnit's convenience method for doing just this:
assertEquals(-1.0d, out.doubleValue(), delta);
Use a very small value for delta, like 10E-10, or something appropriate for your application. In the most general case, if you don't know the range of the values you're comparing, you need to multiply the delta by the relative size of each number, like so:
double tDelta = delta*(Math.abs(-1.0D)+Math.abs(out.doubleValue()));
assertEquals(-1.0d, out.doubleValue(), tDelta);
If you're comparing very huge numbers, you want the allowed delta to be larger, and if you're comparing very small numbers you want the allowed delta to be smaller. But for your case you know one of your parameters beforehand, so you can just hard-code the delta.