java-fundamentals-exercises icon indicating copy to clipboard operation
java-fundamentals-exercises copied to clipboard

1-3-1-crazy-generics, hasDuplicates' test accepts the broken code

Open obaibula opened this issue 2 years ago • 0 comments

The broken code:

public static <T extends BaseEntity> boolean hasDuplicates(List<T> entities, T targetEntity) {
            return entities.stream()
                    .map(BaseEntity::getUuid)
                    .distinct()
                    .count() != entities.size();
        }

This code doesn't check if the target entity is in the list, so we need to add something like this to the tests to ensure that the target entity is in the list:

...
arguments(List.of(uniqueEntity, uniqueEntity, uniqueEntity), duplicateEntity1, false)
...

obaibula avatar Apr 11 '23 14:04 obaibula