refactoring: Issues #2326 and #2325 (#2327)

* Fix comment typo #2325

* Minor enchancements to flyweight #2326

* Minor enchancements to flyweight #2326
This commit is contained in:
Stefanel Stan
2022-11-20 13:14:13 +00:00
committed by GitHub
parent 3a446f8e9c
commit a05cf33643
3 changed files with 7 additions and 10 deletions
@@ -46,27 +46,25 @@ public class PotionFactory {
switch (type) {
case HEALING:
potion = new HealingPotion();
potions.put(type, potion);
break;
case HOLY_WATER:
potion = new HolyWaterPotion();
potions.put(type, potion);
break;
case INVISIBILITY:
potion = new InvisibilityPotion();
potions.put(type, potion);
break;
case POISON:
potion = new PoisonPotion();
potions.put(type, potion);
break;
case STRENGTH:
potion = new StrengthPotion();
potions.put(type, potion);
break;
default:
break;
}
if (potion != null) {
potions.put(type, potion);
}
}
return potion;
}
@@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
import java.util.HashSet;
import org.junit.jupiter.api.Test;
/**
@@ -55,8 +56,6 @@ class AlchemistShopTest {
// There are 13 potion instances, but only 5 unique instance types
assertEquals(13, allPotions.size());
assertEquals(5, allPotions.stream().map(System::identityHashCode).distinct().count());
assertEquals(5, new HashSet<>(allPotions).size());
}
}