java - 为什么我在 JUnit 的返回列表中得到额外的方括号

标签 java list oop junit mockito

我有ff。测试代码:

@Before
    public void setup() {
        RefAccountType refAcctType = new RefAccountType();
        refAcctType.setCode("tax");
        refAcctType.setAccessLevel("1");
        refAcctType.setCreatedBy("anonymous");
        refAcctType.setCreatedDate(new Date(04/18/2018));
        refAcctType.setDescription("taxDesc");
        refAcctType.setEffectiveDate(new Date(04/18/2018));
        refAcctType.setExpiryDate(new Date(04/18/2019));
        refAcctType.setOrderSeq(new BigDecimal(0));
        refAcctType.setStatus("A");
        refAcctType.setUpdatedBy("anonymous1");
        refAcctType.setUpdatedDate(new Date(04/18/2018));
        refAcctType.setVersion("1");

        List<RefAccountType> refAcctTypeList = new ArrayList<>();
        refAcctTypeList.add(refAcctType);

        Mockito.when(refAccountTypeRepository.findAll())
        .thenReturn(refAcctTypeList);

    }

    @Test
    public void testFindAll() {
        List<RefAccountType> refAcctTypeList = new ArrayList<>();
        RefAccountType refAccountType = new RefAccountType( "tax","1", "anonymous", 
        new Date(04/18/2018), "taxDesc",new Date(04/18/2018),
        new Date(04/18/2019),new BigDecimal(0), "A", "anonymous1",  new Date(04/18/2018), "1");

        refAcctTypeList = refAccountTypeService.findAll();
        assertThat(refAcctTypeList).isEqualTo(refAccountType);
        }

但我不知道为什么在运行测试时返回以下错误。

org.junit.ComparisonFailure: expected:<[RefAccountType [code=tax, accessLevel=1, createdBy=anonymous, createdDate=Thu Jan 01 08:00:00 CST 1970, description=taxDesc, effectiveDate=Thu Jan 01 08:00:00 CST 1970, expiryDate=Thu Jan 01 08:00:00 CST 1970, orderSeq=0, status=A, updatedBy=anonymous1, updatedDate=Thu Jan 01 08:00:00 CST 1970, version=1]]> 


but was:<[[RefAccountType [code=tax, accessLevel=1, createdBy=anonymous, createdDate=Thu Jan 01 08:00:00 CST 1970, description=taxDesc, effectiveDate=Thu Jan 01 08:00:00 CST 1970, expiryDate=Thu Jan 01 08:00:00 CST 1970, orderSeq=0, status=A, updatedBy=anonymous1, updatedDate=Thu Jan 01 08:00:00 CST 1970, version=1]]]>

我怀疑错误出在额外的方括号上。 如何删除 but was 结果开头和结尾的多余括号?

最佳答案

额外的方括号表示传递的引用是 RefAccountType 对象的列表。当然,它不等于 RefAccountType 对象本身。

关于java - 为什么我在 JUnit 的返回列表中得到额外的方括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49897836/

相关文章:

Java JTable 未填充 DefaultTableModel

Javascript 用 props 扩展类?

php - SQL 和 PHP : Find all "assets" connected to "presentation"

python - 如何在 python 中将 2d 列表分成两个单独的列表?

WCF 返回自定义类型

python - 将字符串保存到列表中

oop - 您应该将接口(interface)相对于它们的实现者放在哪个命名空间中?

java - 如何使用条件内定义的内容

java - 如何从结果集中打印整列?

Java在ubuntu上找不到文件