[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
Environment:

Linux, JDK



 Description   

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

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

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

MyEntityIntegrationTest.testFindMyEntity()
@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

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


Generated at Sun Dec 08 05:10:58 UTC 2019 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.