我有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/