From 27559b3a7fab1bd1e97e5d3690eb07a76afe2ed0 Mon Sep 17 00:00:00 2001 From: Sushant Date: Sun, 7 Apr 2019 15:14:30 +0300 Subject: [PATCH] Split into separate test cases --- .../baeldung/guava/GuavaMultiSetUnitTest.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/guava-collections/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java b/guava-collections/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java index 3d75cc38a3..47411031b9 100644 --- a/guava-collections/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java +++ b/guava-collections/src/test/java/org/baeldung/guava/GuavaMultiSetUnitTest.java @@ -13,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; public class GuavaMultiSetUnitTest { @Test - public void givenMultiSet_whenAddAndRemoveValues_shouldReturnCorrectCount() { + public void givenMultiSet_whenAddingValues_shouldReturnCorrectCount() { Multiset bookStore = HashMultiset.create(); bookStore.add("Potter"); bookStore.add("Potter"); @@ -21,10 +21,17 @@ public class GuavaMultiSetUnitTest { assertThat(bookStore.contains("Potter")).isTrue(); assertThat(bookStore.count("Potter")).isEqualTo(3); + } + + @Test + public void givenMultiSet_whenRemovingValues_shouldReturnCorrectCount() { + Multiset bookStore = HashMultiset.create(); + bookStore.add("Potter"); + bookStore.add("Potter"); bookStore.remove("Potter"); assertThat(bookStore.contains("Potter")).isTrue(); - assertThat(bookStore.count("Potter")).isEqualTo(2); + assertThat(bookStore.count("Potter")).isEqualTo(1); } @Test @@ -37,14 +44,32 @@ public class GuavaMultiSetUnitTest { @Test public void givenMultiSet_whenSettingNegativeCount_shouldThrowException() { Multiset bookStore = HashMultiset.create(); - assertThatThrownBy(() -> bookStore.setCount("Potter", -1)).isInstanceOf(IllegalArgumentException.class); + assertThatThrownBy(() -> bookStore.setCount("Potter", -1)) + .isInstanceOf(IllegalArgumentException.class); } @Test - public void givenMultiSet_whenSettingCountWithOldCount_shouldReturnCorrectValue() { + public void givenMultiSet_whenSettingCountWithEmptySet_shouldBeSuccessful() { Multiset bookStore = HashMultiset.create(); assertThat(bookStore.setCount("Potter", 0, 2)).isTrue(); - assertThat(bookStore.setCount("Potter", 50, 5)).isFalse(); + } + + @Test + public void givenMultiSet_whenSettingCountWithCorrectValue_shouldBeSuccessful() { + Multiset bookStore = HashMultiset.create(); + bookStore.add("Potter"); + bookStore.add("Potter"); + + assertThat(bookStore.setCount("Potter", 2, 52)).isTrue(); + } + + @Test + public void givenMultiSet_whenSettingCountWithIncorrectValue_shouldFail() { + Multiset bookStore = HashMultiset.create(); + bookStore.add("Potter"); + bookStore.add("Potter"); + + assertThat(bookStore.setCount("Potter", 5, 52)).isFalse(); } @Test