[ROO-3521] generated tests yield bad code for int @Id field Created: 25/Jul/14  Updated: 28/Jul/14

Status: Open
Project: Spring Roo
Component/s: PERSISTENCE
Affects Version/s: 1.2.5.RELEASE
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: David Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: roo
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Linux, JDK


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

@GeneratedValue(strategy = GenerationType.AUTO)
private int id;

to MyEntity.java to create a primary key, and Spring Roo generated

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

See also See http://stackoverflow.com/questions/24943538/roo-generated-test-code-does-not-compile-for-int-id-variable

Generated at Sun Jul 05 23:08:42 UTC 2020 using Jira 8.5.4#805004-sha1:0444eab799707f9ad7b248d69f858774aadfd250.