Junit 4, inner class, initializationError0

J

jeppe.epeli

Hi,

I just don't understand why this test code doesn't work with Junit 4:
-------------------------------------------
import static org.junit.Assert.assertEquals;

import java.awt.geom.Point2D;
import java.util.LinkedList;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class ParametricTest {
private DataItem dI;

public ParametricTest(DataItem dI) {
this.dI=dI;
}

@Parameters
public static LinkedList data() {
float x,y;
LinkedList params = new LinkedList();
x=0.0f;
y=0.0f;
params.add(new DataItem(x, y, new Point2D.Float(x,y)));
x+=1.0f;
params.add(new DataItem(x, y, new Point2D.Float(x,y)));
return params;
}

@Test
public void testPoint() {
assertEquals(dI.x, dI.p.x);
assertEquals(dI.y, dI.p.y);
}

private static class DataItem {
private float x, y;
private Point2D.Float p;

public DataItem(float x, float y, Point2D.Float p) {
this.x=x;
this.y=y;
this.p=p;
}

}
}
-------------------------------------------
When I run JUnit test, JUnit returns initializationError0 before
executing constructor of class ParametricTest. When I replace rows

params.add(new DataItem(x, y, new Point2D.Float(x,y)));

with rows

params.add(new Object[] { new DataItem(x, y, new
Point2D.Float(x,y))});

test runs correctly. Do I really have to include 'new Object[] {...} '
in my test?

Please help me...I'm new with JUnit...

-Jeppe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top