다음과 같은 방법으로 DAO 생성을 모의하고 싶습니다.일반 개체 생성을 모의 할 수 없습니다.
private ReturnType createTenant(){
TenantDto tenantDto = new TenantDto();
TenantGroupDto tenantUserGroupDto = new TenantGroupDto(DEFAULT_USER_GROUP_NAME,Type.HUMAN,DEFAULT_USER_GROUP_DESCR, true);
TenantGroupDto tenantDeviceGroupDto = new TenantGroupDto(DEFAULT_DEVICE_GROUP_NAME,Type.DEVICE,DEFAULT_DEVICE_GROUP_DESCR, true);
Set<TenantGroupDto> tenantGroups = new HashSet<TenantGroupDto>();
tenantGroups.add(tenantUserGroupDto);
tenantGroups.add(tenantDeviceGroupDto);
tenantDto.setTenantGroup(tenantGroups);
tenantDto = tenantDao.create(tenantDto);
return someOtherOperation(tenantDto);
}
나는 나머지 것들을 모의 할 수 있습니다. 나는 일반적인 창조물을 모의 할 수 없다.
즉 tenantGroups 때문에 조롱 할 필요가
Set<TenantGroupDto> tenantGroups = new HashSet<TenantGroupDto>();
일반 객체가 어떤 메서드에서 반환됩니다 때 대해 검색 링크/질문의 대부분은
tenantDao.create(tenantDto);
에 매개 변수입니다. 나는 일반적인 객체 생성에 대한 해결책을 찾지 못했습니다. 어떤 도움을 주셔서 감사합니다.
Thx in Advance.
이와 같은 것을 조롱 할 이유가 없습니다. – Makoto
제네릭은 유형 안전을 보장하기 위해 사용됩니다. 그들은 런타임에 잊어 버린다고 생각합니다. –
Luis가 맞다면, PowerMock 또는 무엇인가를 사용하여 모든 HashSet의 생성을 조롱해야 할 것입니다. HashSet을 모의하려는 이유에 관심이 있습니다 ... – BretC