From ee1225360970d9a7da49b9599b8f80fbfd86c609 Mon Sep 17 00:00:00 2001 From: "Kai.Yuan" Date: Fri, 2 Feb 2024 17:13:57 +0100 Subject: [PATCH] [count-upper-lower] review comments related changes --- .../CountUpperAndLowercaseCharsUnitTest.java | 44 +++++++------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/core-java-modules/core-java-string-operations-8/src/test/java/com/baeldung/countupperandlowercasechars/CountUpperAndLowercaseCharsUnitTest.java b/core-java-modules/core-java-string-operations-8/src/test/java/com/baeldung/countupperandlowercasechars/CountUpperAndLowercaseCharsUnitTest.java index cfef8d53ad..a05b067f5a 100644 --- a/core-java-modules/core-java-string-operations-8/src/test/java/com/baeldung/countupperandlowercasechars/CountUpperAndLowercaseCharsUnitTest.java +++ b/core-java-modules/core-java-string-operations-8/src/test/java/com/baeldung/countupperandlowercasechars/CountUpperAndLowercaseCharsUnitTest.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class CountUpperAndLowercaseCharsUnitTest { private static final String MY_STRING = "Hi, Welcome to Baeldung! Let's count letters!"; - private static final LetterCount EXPECTED = new LetterCount(4, 31); @Test void whenIteratingCharArrayCompareAndCount_thenGetExpectedResult() { @@ -21,7 +20,8 @@ public class CountUpperAndLowercaseCharsUnitTest { } } LetterCount result = new LetterCount(upperCnt, lowerCnt); - assertEquals(EXPECTED, result); + assertEquals(4, result.getUppercaseCount()); + assertEquals(31, result.getLowercaseCount()); } @Test @@ -37,7 +37,8 @@ public class CountUpperAndLowercaseCharsUnitTest { } } LetterCount result = new LetterCount(upperCnt, lowerCnt); - assertEquals(EXPECTED, result); + assertEquals(4, result.getUppercaseCount()); + assertEquals(31, result.getLowercaseCount()); } @Test @@ -46,40 +47,25 @@ public class CountUpperAndLowercaseCharsUnitTest { (int) MY_STRING.chars().filter(Character::isUpperCase).count(), (int) MY_STRING.chars().filter(Character::isLowerCase).count() ); - assertEquals(EXPECTED, result); + assertEquals(4, result.getUppercaseCount()); + assertEquals(31, result.getLowercaseCount()); } } class LetterCount { - private int uppercaseCnt; - private int lowercaseCnt; + private int uppercaseCount; + private int lowercaseCount; - public LetterCount(int uppercaseCnt, int lowercaseCnt) { - this.uppercaseCnt = uppercaseCnt; - this.lowercaseCnt = lowercaseCnt; + public LetterCount(int uppercaseCount, int lowercaseCount) { + this.uppercaseCount = uppercaseCount; + this.lowercaseCount = lowercaseCount; } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof LetterCount)) { - return false; - } - - LetterCount that = (LetterCount) o; - - if (uppercaseCnt != that.uppercaseCnt) { - return false; - } - return lowercaseCnt == that.lowercaseCnt; + public int getUppercaseCount() { + return uppercaseCount; } - @Override - public int hashCode() { - int result = uppercaseCnt; - result = 31 * result + lowercaseCnt; - return result; + public int getLowercaseCount() { + return lowercaseCount; } } \ No newline at end of file