Take the 2-minute tour ×

I had some tests working fine. Then, I moved it to a different package, and am now getting errors. Here is the code:

import static org.junit.Assert.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.jgrapht.Graphs;
import org.jgrapht.WeightedGraph;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.SimpleWeightedGraph;
import org.junit.*; 

    public void testEccentricity() {
    	WeightedGraph<String, DefaultWeightedEdge> g = generateSimpleCaseGraph();
    	Map<String, Double> eccen = JGraphtUtilities.eccentricities(g);

    	assertEquals(70, eccen.get("alpha"));
    	assertEquals(80, eccen.get("l"));
    	assertEquals(130, eccen.get("l-0"));
    	assertEquals(100, eccen.get("l-1"));
    	assertEquals(90, eccen.get("r"));
    	assertEquals(120, eccen.get("r-0"));
    	assertEquals(130, eccen.get("r-1"));

The error message is this:

The method assertEquals(Object, Object) is ambiguous for the type JGraphtUtilitiesTest

How can I fix this? Why did this problem occur as I moved the class to a different package?

share|improve this question
tell us how your class is declared. Looks to me as if you've inherited from JUnit3 and then tried to statically import from JUnit4. –  bmargulies Nov 28 '09 at 0:32
yeah, actually, I had JUnit3 in package A, and used JUnit4 in package B, where I originally wrote these tests. Then I switched from Package B to Package A, and the problem arose. But I don't see anything in this class that would indicate JUnit 3. Where is that declared? –  Rosarch Nov 28 '09 at 0:38
@Rosarch Are these JGraphtUtilities available anywhere? I can't see methods to produce eccentricities in JGraphT! –  Nick Dec 13 '12 at 12:17
add comment

1 Answer

up vote 66 down vote accepted

The method assertEquals(Object, Object) is ambiguous for the type ...

What this error means is that you're passing a double and and Double into a method that has two different signatures: assertEquals(Object, Object) and assertEquals(double, double) both of which could be called, thanks to autoboxing.

To avoid the ambiguity, make sure that you either call assertEquals(Object, Object) (by passing two Doubles) or assertEquals(double, double) (by passing two doubles).

So, in your case, you should use:

assertEquals(Double.valueOf(70), eccen.get("alpha"));


assertEquals(70.0d, eccen.get("alpha").doubleValue());
share|improve this answer
ok, or I could just switch it to use JUnit 4 instead of JUnit 3. How do I do that? –  Rosarch Nov 28 '09 at 1:38
The solution is not really to switch from one version to the other. Instead, help the compiler and remove the ambiguity as I suggested. –  Pascal Thivent Nov 28 '09 at 2:55
Anyway, shouldn't it be assertEquals(70.0d, eccen.get("alpha")); ? –  mhaller Nov 28 '09 at 3:06
but it wasn't a problem in JUnit 4, and I'd like to avoid changing a bunch of things in my code. –  Rosarch Nov 28 '09 at 5:18
@mahller Not sure who you are talking to but, even if it's more correct than the OP's code, it still ambiguous if the version of JUnit has both assertEquals(Object, Object) and assertEquals(double, double) which is the case of JUnit 4.4, 4.5. But as I said, changing the version of JUnit is not the real solution, just fix the problem. –  Pascal Thivent Nov 28 '09 at 5:58
show 3 more comments

Your Answer


