diff --git a/src/main/java/com/b/simple/design/business/customer/CustomerBOImpl.java b/src/main/java/com/b/simple/design/business/customer/CustomerBOImpl.java index f80bd8b..a4551ba 100755 --- a/src/main/java/com/b/simple/design/business/customer/CustomerBOImpl.java +++ b/src/main/java/com/b/simple/design/business/customer/CustomerBOImpl.java @@ -11,33 +11,28 @@ public class CustomerBOImpl implements CustomerBO { - @Override - public Amount getCustomerProductsSum(List products) - throws DifferentCurrenciesException { - BigDecimal temp = BigDecimal.ZERO; - - if (products.size() == 0) - return new AmountImpl(temp, Currency.EURO); - - // Throw Exception If Any of the product has a currency different from - // the first product - Currency firstProductCurrency = products.get(0).getAmount() - .getCurrency(); - - for (Product product : products) { - boolean currencySameAsFirstProduct = product.getAmount() - .getCurrency().equals(firstProductCurrency); - if (!currencySameAsFirstProduct) { - throw new DifferentCurrenciesException(); - } - } - - // Calculate Sum of Products - for (Product product : products) { - temp = temp.add(product.getAmount().getValue()); - } - - // Create new product - return new AmountImpl(temp, firstProductCurrency); - } + @Override + public Amount getCustomerProductsSum(List products) throws DifferentCurrenciesException { + if (products.isEmpty()) { + return new AmountImpl(BigDecimal.ZERO, Currency.EURO); + } + Currency firstProductCurrency = products.get(0).getAmount().getCurrency(); + if (!doAllProductsHaveSameCurrency(products, firstProductCurrency)) { + throw new DifferentCurrenciesException(); + } + + return new AmountImpl(calculateSumOfProducts(products), firstProductCurrency); + } + + private static BigDecimal calculateSumOfProducts(List products) { + return products.stream() + .map(product -> product.getAmount().getValue()) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } + + private static boolean doAllProductsHaveSameCurrency(List products, Currency currency) { + return products.stream() + .map(product -> product.getAmount().getCurrency()) + .allMatch(productCurrency -> productCurrency.equals(currency)); + } } \ No newline at end of file diff --git a/src/main/java/com/b/simple/design/business/student/StudentHelper.java b/src/main/java/com/b/simple/design/business/student/StudentHelper.java index 10bb826..7bbc6e4 100644 --- a/src/main/java/com/b/simple/design/business/student/StudentHelper.java +++ b/src/main/java/com/b/simple/design/business/student/StudentHelper.java @@ -1,66 +1,71 @@ package com.b.simple.design.business.student; + public class StudentHelper { - /* PROBLEM 1 */ - /* - * You get a grade B if marks are between 51 and 80 (both inclusive). Except for Maths where the upper limit is increased by 10. - */ - public boolean isGradeB(int marks, boolean isMaths) { - return isMaths ? marks>=51 && marks<=90 : marks>=51 && marks<=80; - } + public static final int GRADE_B_UPPER_LIMIT = 80; + public static final int GRADE_B_LOWER_LIMIT = 51; + public static final int EXTRA_FOR_MATH = 10; + + /* PROBLEM 1 */ + /* + * You get a grade B if marks are between 51 and 80 (both inclusive). + * Except for Maths where the upper limit is increased by 10. + */ + public boolean isGradeB(int marks, boolean isMaths) { + int extraLimit = isMaths ? EXTRA_FOR_MATH : 0; + int upperLimit = GRADE_B_UPPER_LIMIT + extraLimit; + return marks >= GRADE_B_LOWER_LIMIT && marks <= upperLimit; + } - /* PROBLEM 2 */ + /* PROBLEM 2 */ /* You are awarded a grade based on your marks. Grade A = 91 to 100, Grade B = 51 to 90, Otherwise Grade C Except for Maths where marks to get a Grade are 5 higher than required for other subjects. */ - public String getGrade(int mark, boolean isMaths) { - String grade = "C"; - - if (isGradeA(mark, isMaths)) - grade = "A"; - else if (isBGrade(mark, isMaths)) { - grade = "B"; - } - return grade; - } + public String getGrade(int mark, boolean isMaths) { + int extraLimit = isMaths ? 5 : 0; - private boolean isGradeA(int mark, boolean isMaths) { - int lowerLimitForAGrade = isMaths ? 95 - : 90; - return mark > lowerLimitForAGrade; - } - - private boolean isBGrade(int mark, boolean isMaths) { - int lowerLimitGradeB = isMaths ? 55 - : 50; - return mark > lowerLimitGradeB && mark < 90; - } + if (mark >= 91 + extraLimit) { + return "A"; + } + if (mark >= 51 + extraLimit) { + return "B"; + } + return "C"; + } /* PROBLEM 3 * You and your Friend are planning to enter a Subject Quiz. * However, there is a marks requirement that you should attain to qualify. - * + * * Return value can be YES, NO or MAYBE. - * + * * YES If either of you are very good at the subject(has 80 or more marks) * However, there is an exception that if either of you is not good in the subject(20 or less marks), it is NO. * In all other conditions, return MAYBE. - * + * * However, the definition for good and not good are 5 marks higher if the subject is Mathematics. - * + * * marks1 - your marks * marks2 - your friends marks - */ - + */ + public String willQualifyForQuiz(int marks1, int marks2, boolean isMaths) { - if ((isMaths ? marks1 <= 25 : marks1 <= 20) - || (isMaths ? marks2 <= 25 : marks2 <= 20)) return "NO"; - if ((isMaths ? marks1 >= 85 : marks1 >= 80) - || (isMaths ? marks2 >= 85 : marks2 >= 80)) return "YES"; + if (isNotGood(marks1, isMaths) || isNotGood(marks2, isMaths)) return "NO"; + if (isGood(marks1, isMaths) || isGood(marks2, isMaths)) return "YES"; return "MAYBE"; - } + } + + private static boolean isGood(int marks, boolean isMaths) { + int extraLimit = isMaths ? 5 : 0; + return marks >= 80 + extraLimit; + } + + private static boolean isNotGood(int marks, boolean isMaths) { + int extraLimit = isMaths ? 5 : 0; + return marks <= 20 + extraLimit; + } } \ No newline at end of file diff --git a/src/main/java/com/b/simple/design/business/text/TextHelper.java b/src/main/java/com/b/simple/design/business/text/TextHelper.java index 5836347..c1520ca 100755 --- a/src/main/java/com/b/simple/design/business/text/TextHelper.java +++ b/src/main/java/com/b/simple/design/business/text/TextHelper.java @@ -2,11 +2,75 @@ public class TextHelper { - public String swapLastTwoCharacters(String str) { - return null; - } + public String swapLastTwoCharactersMine(String str) { + int len = str.length(); + if (len <= 1) { + return str; + } - public String truncateAInFirst2Positions(String str) { - return null; - } + StringBuilder res = new StringBuilder(); + res.append(str, 0, len - 2); + char lastCharacter = str.charAt(len - 1); + char prevLast = str.charAt(len - 2); + res.append(lastCharacter); + res.append(prevLast); + + return res.toString(); + } + + public String swapLastTwoCharacters(String str) { + int len = str.length(); + if (len <= 1) { + return str; + } + char lastCharacter = str.charAt(len - 1); + char prevLast = str.charAt(len - 2); + + String restOfString = str.substring(0, len - 2); + + return restOfString + lastCharacter + prevLast; + } + + public String truncateAInFirst2PositionsAttempt1(String str) { + int len = str.length(); + if (len == 0) { + return str; + } + StringBuilder res = new StringBuilder(); + char firstCharacter = str.charAt(0); + if (firstCharacter != 'A') { + res.append(firstCharacter); + } + if (len >= 2) { + char secondCharacter = str.charAt(2); + if (secondCharacter != 'A') { + res.append(secondCharacter); + } + } + if (len >= 3) { + String restOfString = str.substring(3); + res.append(restOfString); + } + + return res.toString(); + } + + public String truncateAInFirst2PositionsAttempt2(String str) { + if (str.length() <= 2) { + return str.replaceAll("^A+", ""); + } + String firstTwo = str.substring(0, 2).replaceAll("A", ""); + return firstTwo + str.substring(2); + } + + public String truncateAInFirst2Positions(String str) { + if (str.length() <= 2) { + return str.replaceAll("A", ""); + } + String firstTwo = str.substring(0, 2); + String firstTwoCharactersRemoved = firstTwo.replaceAll("A", ""); + String restOfTheString = str.substring(2); + + return firstTwoCharactersRemoved + restOfTheString; + } } diff --git a/src/main/java/com/c/refactoring/movie/Movie.java b/src/main/java/com/c/refactoring/movie/Movie.java index fcddbe0..9cb97ae 100755 --- a/src/main/java/com/c/refactoring/movie/Movie.java +++ b/src/main/java/com/c/refactoring/movie/Movie.java @@ -2,10 +2,18 @@ import com.c.refactoring.StringUtils; +import java.util.HashSet; +import java.util.Set; + public class Movie { String rating; - + private static final Set VALID_B_RATING = new HashSet() {{ + add("B1"); + add("B2"); + add("B3"); + add("B4"); + }}; public Movie(String rating) { super(); this.rating = rating; @@ -19,21 +27,21 @@ public String getRating() { Where x represents any digit between 0 and 9, and y represents any digit between 1 and 4*/ public boolean isValidRating() { - if (this.getRating() != null) { - if (this.getRating().substring(0, 1).equalsIgnoreCase("B") - && this.getRating().length() == 2) { - if (StringUtils.isNumeric(this.getRating().substring(1, 2)) - && Integer.parseInt(this.getRating().substring(1, 2)) > 0 - && Integer.parseInt(this.getRating().substring(1, 2)) < 5) - return true; - - } else if (this.getRating().substring(0, 1).equalsIgnoreCase("A") - && this.getRating().length() == 3 - && StringUtils.isNumeric(this.getRating().substring(1, 3))) - return true; - + if (getRating() == null) { + return false; } - return false; + return isValidBRating() || isValidARating(); + } + + private boolean isValidBRating() { + return VALID_B_RATING.contains(getRating()); + } + + private boolean isValidARating() { + String rating = this.getRating(); + String firstCharacter = rating.substring(0, 1); + return firstCharacter.equalsIgnoreCase("A") + && rating.length() == 3 && StringUtils.isNumeric(rating.substring(1, 3)); } public void setRating(String rating) { diff --git a/src/test/java/com/a/introduction/gildedrose/GildedRoseMyRefactoredTest.java b/src/test/java/com/a/introduction/gildedrose/GildedRoseMyRefactoredTest.java new file mode 100644 index 0000000..7e00ccd --- /dev/null +++ b/src/test/java/com/a/introduction/gildedrose/GildedRoseMyRefactoredTest.java @@ -0,0 +1,104 @@ +package com.a.introduction.gildedrose; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class GildedRoseMyRefactoredTest { + + public static final int NOT_EXPIRED_SELL_IN = 15; + public static final int DEFAULT_QUALITY = 3; + public static final String DEFAULT_ITEM = "DEFAULT_ITEM"; + public static final int EXPIRED_SELL_IN = -1; + public static final String AGED_BRIE = "Aged Brie"; + public static final int MAX_QUALITY = 50; + public static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert"; + public static final int SELL_IN_GREATER_THAN_10 = 15; + public static final int SELL_IN_BETWEEN_5_AND_10 = 7; + public static final int SELL_LESS_THAN_5 = 5; + public static final int SELL_IN_ZERO = 0; + + private static GildedRose createGildedRoseWithOneItem(String itemType, int sellIn, int quality) { + Item item = new Item(itemType, sellIn, quality); + Item[] items = new Item[]{item}; + return new GildedRose(items); + } + + private static void assertItem(Item expected, Item actual) { + assertEquals(expected.name, actual.name); + assertEquals(expected.sellIn, actual.sellIn); + assertEquals(expected.quality, actual.quality); + } + + @Test + public void notExpiredDefaultItemQualityDecreaseByOne() { + GildedRose app = createGildedRoseWithOneItem(DEFAULT_ITEM, NOT_EXPIRED_SELL_IN, DEFAULT_QUALITY); + app.updateQuality(); + Item expected = new Item(DEFAULT_ITEM, NOT_EXPIRED_SELL_IN - 1, DEFAULT_QUALITY - 1); + assertItem(expected, app.items[0]); + } + + @Test + public void expiredDefaultItemQualityDecreaseByTwo() { + GildedRose app = createGildedRoseWithOneItem(DEFAULT_ITEM, EXPIRED_SELL_IN, DEFAULT_QUALITY); + app.updateQuality(); + Item expected = new Item(DEFAULT_ITEM, EXPIRED_SELL_IN - 1, DEFAULT_QUALITY - 2); + assertItem(expected, app.items[0]); + } + + @Test + public void notExpiredAgedBrieQualityIncreasesByOne() { + GildedRose app = createGildedRoseWithOneItem(AGED_BRIE, NOT_EXPIRED_SELL_IN, DEFAULT_QUALITY); + app.updateQuality(); + Item expected = new Item(AGED_BRIE, NOT_EXPIRED_SELL_IN - 1, DEFAULT_QUALITY + 1); + assertItem(expected, app.items[0]); + } + + @Test + public void expiredAgedBrieQualityIncreaseByTwo() { + GildedRose app = createGildedRoseWithOneItem(AGED_BRIE, EXPIRED_SELL_IN, DEFAULT_QUALITY); + app.updateQuality(); + Item expected = new Item(AGED_BRIE, EXPIRED_SELL_IN - 1, DEFAULT_QUALITY + 2); + assertItem(expected, app.items[0]); + } + + @Test + public void notExpiredAgedBrieQualityDoesNotGoBeyondMaximum() { + GildedRose app = createGildedRoseWithOneItem(AGED_BRIE, NOT_EXPIRED_SELL_IN, MAX_QUALITY); + app.updateQuality(); + Item expected = new Item(AGED_BRIE, NOT_EXPIRED_SELL_IN - 1, MAX_QUALITY); + assertItem(expected, app.items[0]); + } + + @Test + public void notExpiredBackstagePassesQualityIncreaseByOne() { + GildedRose app = createGildedRoseWithOneItem(BACKSTAGE_PASSES, SELL_IN_GREATER_THAN_10, DEFAULT_QUALITY); + app.updateQuality(); + Item expected = new Item(BACKSTAGE_PASSES, SELL_IN_GREATER_THAN_10 - 1, DEFAULT_QUALITY + 1); + assertItem(expected, app.items[0]); + } + + @Test + public void lessThanTenDaysBackstagePassesQualityIncreaseByTwo() { + GildedRose app = createGildedRoseWithOneItem(BACKSTAGE_PASSES, SELL_IN_BETWEEN_5_AND_10, DEFAULT_QUALITY); + app.updateQuality(); + Item expected = new Item(BACKSTAGE_PASSES, SELL_IN_BETWEEN_5_AND_10 - 1, DEFAULT_QUALITY + 2); + assertItem(expected, app.items[0]); + } + + @Test + public void lessThanFiveDaysBackstagePassesQualityIncreaseByThree() { + GildedRose app = createGildedRoseWithOneItem(BACKSTAGE_PASSES, SELL_LESS_THAN_5, DEFAULT_QUALITY); + app.updateQuality(); + Item expected = new Item(BACKSTAGE_PASSES, SELL_LESS_THAN_5 - 1, DEFAULT_QUALITY + 3); + assertItem(expected, app.items[0]); + } + + @Test + public void negativeSellInBackstagePassesQualityDropsToZero() { + GildedRose app = createGildedRoseWithOneItem(BACKSTAGE_PASSES, SELL_IN_ZERO, DEFAULT_QUALITY); + app.updateQuality(); + Item expected = new Item(BACKSTAGE_PASSES, SELL_IN_ZERO - 1, 0); + assertItem(expected, app.items[0]); + } +} \ No newline at end of file diff --git a/src/test/java/com/b/simple/design/business/customer/CustomerBORefactoredTest.java b/src/test/java/com/b/simple/design/business/customer/CustomerBORefactoredTest.java index 4bce56c..4b7f518 100644 --- a/src/test/java/com/b/simple/design/business/customer/CustomerBORefactoredTest.java +++ b/src/test/java/com/b/simple/design/business/customer/CustomerBORefactoredTest.java @@ -24,8 +24,7 @@ public class CustomerBORefactoredTest { private CustomerBO customerBO = new CustomerBOImpl(); @Test - public void testCustomerProductSum_TwoProductsSameCurrencies() - throws DifferentCurrenciesException { + public void testCustomerProductSum_TwoProductsSameCurrencies() throws DifferentCurrenciesException { Amount[] amounts = { new AmountImpl(new BigDecimal("5.0"), Currency.EURO), @@ -79,17 +78,6 @@ private List createProductsWithAmounts(Amount[] amounts) { new ProductImpl(100, "Product 15", ProductType.BANK_GUARANTEE, amount)) .collect(Collectors.toList()); - -// List products = new ArrayList(); -// -// for(Amount amount:amounts) { -// products.add( -// new ProductImpl(100, "Product 15", ProductType.BANK_GUARANTEE, -// amount)); -// -// } -// -// return products; } } \ No newline at end of file diff --git a/src/test/java/com/b/simple/design/business/customer/CustomerBOTest.java b/src/test/java/com/b/simple/design/business/customer/CustomerBOTest.java index 095c52d..b1ab977 100755 --- a/src/test/java/com/b/simple/design/business/customer/CustomerBOTest.java +++ b/src/test/java/com/b/simple/design/business/customer/CustomerBOTest.java @@ -1,12 +1,13 @@ package com.b.simple.design.business.customer; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import com.b.simple.design.business.exception.DifferentCurrenciesException; @@ -19,64 +20,53 @@ public class CustomerBOTest { - private CustomerBO customerBO = new CustomerBOImpl(); - - @Test - public void testCustomerProductSum_TwoProductsSameCurrencies() - throws DifferentCurrenciesException { - - List products = new ArrayList(); - - products.add( - new ProductImpl(100, "Product 15", ProductType.BANK_GUARANTEE, - new AmountImpl(new BigDecimal("5.0"), Currency.EURO))); - - products.add( - new ProductImpl(120, "Product 20", ProductType.BANK_GUARANTEE, - new AmountImpl(new BigDecimal("6.0"), Currency.EURO))); - - Amount temp = customerBO.getCustomerProductsSum(products); - - assertEquals(Currency.EURO, temp.getCurrency()); - assertEquals(new BigDecimal("11.0"), temp.getValue()); - } - - @Test - public void testCustomerProductSum1() { - - List products = new ArrayList(); - - products.add(new ProductImpl(100, "Product 15", - ProductType.BANK_GUARANTEE, - new AmountImpl(new BigDecimal("5.0"), Currency.INDIAN_RUPEE))); - - products.add( - new ProductImpl(120, "Product 20", ProductType.BANK_GUARANTEE, - new AmountImpl(new BigDecimal("6.0"), Currency.EURO))); - - @SuppressWarnings("unused") - Amount temp = null; - - try { - temp = customerBO.getCustomerProductsSum(products); - fail("DifferentCurrenciesException is expected"); - } catch (DifferentCurrenciesException e) { - } - } - - @Test - public void testCustomerProductSum2() { - - List products = new ArrayList(); - - Amount temp = null; - - try { - temp = customerBO.getCustomerProductsSum(products); - } catch (DifferentCurrenciesException e) { - } - assertEquals(Currency.EURO, temp.getCurrency()); - assertEquals(BigDecimal.ZERO, temp.getValue()); - } + private final CustomerBO customerBOImpl = new CustomerBOImpl(); + + @Test + public void customerProductSumTwoProductsSameCurrencies() throws DifferentCurrenciesException { + List amounts = new ArrayList() {{ + add(new AmountImpl(new BigDecimal("5.0"), Currency.EURO)); + add(new AmountImpl(new BigDecimal("6.0"), Currency.EURO)); + }}; + List products = getProductsWithAmounts(amounts); + + Amount actual = customerBOImpl.getCustomerProductsSum(products); + Amount expected = new AmountImpl(new BigDecimal("11.0"), Currency.EURO); + + assertCurrency(expected, actual); + } + + @Test + public void customerProductSumOfTwoDifferentCurrenciesThrowsException(){ + List amounts = new ArrayList() {{ + add(new AmountImpl(new BigDecimal("5.0"), Currency.INDIAN_RUPEE)); + add(new AmountImpl(new BigDecimal("6.0"), Currency.EURO)); + }}; + + List products = getProductsWithAmounts(amounts); + + Assertions.assertThrows(DifferentCurrenciesException.class, () -> + customerBOImpl.getCustomerProductsSum(products)); + } + + @Test + public void customerProductSumEmptyProduct() throws DifferentCurrenciesException { + Amount expected = new AmountImpl(BigDecimal.ZERO, Currency.EURO); + Amount actual = customerBOImpl.getCustomerProductsSum( new ArrayList<>()); + + assertCurrency(expected, actual); + } + + private static void assertCurrency(Amount expected, Amount actual) { + assertEquals(expected.getCurrency(), actual.getCurrency()); + assertEquals(expected.getValue(), actual.getValue()); + } + + List getProductsWithAmounts(List amounts) { + return amounts.stream(). + map(amount -> + new ProductImpl(100, "Product 15", ProductType.BANK_GUARANTEE, amount)) + .collect(Collectors.toList()); + } } \ No newline at end of file diff --git a/src/test/java/com/b/simple/design/business/text/TextHelperTest.java b/src/test/java/com/b/simple/design/business/text/TextHelperTest.java index b6c20e7..d3a6878 100755 --- a/src/test/java/com/b/simple/design/business/text/TextHelperTest.java +++ b/src/test/java/com/b/simple/design/business/text/TextHelperTest.java @@ -12,7 +12,6 @@ public class TextHelperTest { TextHelper helper = new TextHelper(); @Test - @Disabled public void testSwapLastTwoCharacters() { assertEquals("",helper.swapLastTwoCharacters("")); assertEquals("A",helper.swapLastTwoCharacters("A")); @@ -21,12 +20,35 @@ public void testSwapLastTwoCharacters() { } @Test - @Disabled public void testTruncateAInFirst2Positions() { assertEquals("",helper.truncateAInFirst2Positions("")); assertEquals("BCD",helper.truncateAInFirst2Positions("ABCD")); assertEquals("CD",helper.truncateAInFirst2Positions("AACD")); assertEquals("BCD",helper.truncateAInFirst2Positions("BACD")); assertEquals("BBAA",helper.truncateAInFirst2Positions("BBAA")); + assertEquals("",helper.truncateAInFirst2Positions("A")); + assertEquals("",helper.truncateAInFirst2Positions("AA")); + } + + @Test + public void testTruncateAInFirst2PositionsAttempt1() { + assertEquals("",helper.truncateAInFirst2PositionsAttempt1("")); + assertEquals("BCD",helper.truncateAInFirst2PositionsAttempt1("ABCD")); + assertEquals("CD",helper.truncateAInFirst2PositionsAttempt1("AACD")); + assertEquals("BCD",helper.truncateAInFirst2PositionsAttempt1("BACD")); + assertEquals("BBAA",helper.truncateAInFirst2PositionsAttempt1("BBAA")); + assertEquals("",helper.truncateAInFirst2PositionsAttempt1("A")); + assertEquals("",helper.truncateAInFirst2PositionsAttempt1("AA")); + } + + @Test + public void testTruncateAInFirst2PositionsAttempt2() { + assertEquals("",helper.truncateAInFirst2PositionsAttempt2("")); + assertEquals("BCD",helper.truncateAInFirst2PositionsAttempt2("ABCD")); + assertEquals("CD",helper.truncateAInFirst2PositionsAttempt2("AACD")); + assertEquals("BCD",helper.truncateAInFirst2PositionsAttempt2("BACD")); + assertEquals("BBAA",helper.truncateAInFirst2PositionsAttempt2("BBAA")); + assertEquals("",helper.truncateAInFirst2PositionsAttempt2("A")); + assertEquals("",helper.truncateAInFirst2PositionsAttempt2("AA")); } } diff --git a/src/test/java/com/c/refactoring/menuexamples/MenuAccessTestRefactored.java b/src/test/java/com/c/refactoring/menuexamples/MenuAccessTestRefactored.java index 47669ba..9a0c814 100644 --- a/src/test/java/com/c/refactoring/menuexamples/MenuAccessTestRefactored.java +++ b/src/test/java/com/c/refactoring/menuexamples/MenuAccessTestRefactored.java @@ -1,6 +1,7 @@ package com.c.refactoring.menuexamples; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.List; @@ -54,12 +55,12 @@ public void testSetAuthorizationsInEachMenus_UserHasOnlyWriteRole() { private void assertMenuItemIsWritable(MenuItem actual) { assertEquals(Constants.WRITE, actual.getAccess()); - assertEquals(true, actual.isVisible()); + assertTrue(actual.isVisible()); } private void assertMenuItemIsReadable(MenuItem actual) { assertEquals(Constants.READ, actual.getAccess()); - assertEquals(true, actual.isVisible()); + assertTrue(actual.isVisible()); } }