【问题标题】:Roo generated test code does not compile for int @Id variableRoo 生成的测试代码无法为 int @Id 变量编译
【发布时间】:2014-07-24 20:40:07
【问题描述】:

我创建了一个非常简单的 Spring Roo 1.2.5 项目,其中有一个实体类 MyEntity,它有几个字符串变量。

我加了一个

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

为MyEntity.java创建主键,并由Spring Roo生成

@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());
}

在 MyEntityIntegrationTest_Roo_IntegrationTest.aj 文件中。但是有两个问题:

1) 类型是 int,那么为什么 Roo 将它分配给 Integer,然后测试是否为 null?如果类型为int,则结果不能为null

2) 由于 JDK 6 编译器无法解析 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

我可以“修复”这个我将字段更改为 Integer 或 Long 但@Id 说原语 是允许的。

我怀疑这是 Roo 1.2.5 的错误吗?有解决办法吗?

【问题讨论】:

    标签: spring-roo


    【解决方案1】:

    我认为这是 Spring Roo 错误,因此,您可以在 Spring Roo Jira 上创建请求。

    要在您的项目中修复它,而该错误尚未解决,您可以推入testFindMyEntity 方法来测试类并手动修复代码。 Spring Roo 不会在.aj 文件中再次生成它。

    【讨论】:

      猜你喜欢
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      相关资源
      最近更新 更多