So, I don't even know where to start with this one. This whole fiasco began over eight hours ago, jerry rigging my way out of one issue after another. Now, this:
And it gets even better, after clicking "Click to see difference":
I have:
- Invalidated caches and restarted IntelliJ
- Attempted running where Double[] numSet = {23.0};
and then setting the expected result to numSet
rather than "[23.0]"
. No dice.
- The answer regarding adding a delta didn't work: JUnit test fails even if the expected result is correct
I feel it is also worth noting that the error supposedly occuring at line 48 does not show up when calling the method from the main class, so I have no clue as to what that might be about.
Any help will be appreciated.
Here is the code for the method being tested. Almost forgot it:
public List<Object> trimNumberSet(Double[] numSet) {
List<Object> trimmedNumberSet = new ArrayList<>();
for (int i = 0; i < numSet.length; i++) {
if (numSet[i] != null) {
trimmedNumberSet.add(numSet[i]);
}
}
return trimmedNumberSet;
}
You are comparing a String
and a List<Object>
.
So you're using the method assertEquals(Object expected, Object actual);
Obviously a String
is not equals to a List<Object>
and hence the fail.
But since the String representation of the list is the same as you wrote, it hides you the result in the console because it uses this representation to show you the result of this test.
So you should compare the String representation of boths :
assertEquals("[23.0]", setSorteer.trimNumberSet(numSet).toString());
A better idea would be to compare two Lists directly, and not base your test on the String representations because they can change in the future and your test will fail :
assertEquals(Arrays.asList(23.0), setSorteer.trimNumberSet(numSet));
List<Double>
in your method?
public List<Double> trimNumberSet(Double[] numSet) {
List<Double> trimmedNumberSet = new ArrayList<>();
...
return trimmedNumberSet;
}