EnumTrieCreator { public static TrieNode<Enum<?>> create(Class<? extends Enum<?>> firstClass) { return new Branch<>(firstClass.getSimpleName(), generateNodes(firstClass)); } private  EnumTrieCreator(); static TrieNode<Enum<?>> create(Class<? extends Enum<?>> firstClass);  }
@Test void onlyLeafNodesCreatedForSimpleEnum() { TrieNode<Enum<?>> simpleTrie = EnumTrieCreator.create(SimpleEnum.class); assertThat(simpleTrie).isInstanceOf(Branch.class); Map<String, ? extends TrieNode<?>> branches = ((Branch<?>) simpleTrie).branches; assertThat(branches).hasSize(2); assertThat(branches.values()).allMatch(n -> n instanceof TrieNode.Leaf); assertThat(branches.get("YES")).isEqualTo(new Leaf<>(SimpleEnum.YES)); assertThat(branches.get("NO")).isEqualTo(new Leaf<>(SimpleEnum.NO)); }
@Test void noEntriesForEmptyEnum() { TrieNode<Enum<?>> enumNode = EnumTrieCreator.create(EmptyEnum.class); assertThat(enumNode).isInstanceOf(Branch.class); Branch<Enum<?>> node = (Branch<Enum<?>>) enumNode; assertThat(node.name).isEqualTo(EmptyEnum.class.getSimpleName()); assertThat(node.branches).isEmpty(); }