I created a very simple Spring Roo 1.2.5 project with one entity class MyEntity which has a few string variables.
I added a
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
to MyEntity.java to create a primary key, and Spring Roo generated
@Test
public void MyEntityIntegrationTest.testFindMyEntity() {
MyEntity obj = dod.getRandomMyEntity();
Assert.assertNotNull("Data on demand for 'MyEntity' failed to initialize correctly", obj);
Integer id = obj.getPrimaryKey();
Assert.assertNotNull("Data on demand for 'MyEntity' failed to provide an identifier", id);
obj = MyEntity.findMyEntity(id);
Assert.assertNotNull("Find method for 'MyEntity' illegally returned null for id '" + id + "'", obj);
Assert.assertEquals("Find method for 'MyEntity' returned the incorrect identifier", id, obj.getPrimaryKey());
}
in the MyEntityIntegrationTest_Roo_IntegrationTest.aj file. However there are two problems:
1) the type is int, so why does Roo assign this to Integer, then test for null? If the type is int, the result can't be null
2) the final assertion does not compile because the JDK 6 compiler can't resolve the types for assertEquals(Integer, int):
The method assertEquals(String, Object, Object) is ambiguous for the type Assert MyEntityIntegrationTest_Roo_IntegrationTest.aj /mu/src/test/java/com/sas/mu line 47 Java Problem
I can"fix" this my changing the field to Integer or Long but @Id says primitives are allowed.
Is this a Roo 1.2.5 bug as I suspect? Is there a fix?