Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-3521

generated tests yield bad code for int @Id field

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.5.RELEASE
    • Fix Version/s: None
    • Component/s: PERSISTENCE
    • Labels:
    • 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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              davidbiesack David
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: