Mapper { public CommandNode<R> map(CommandNode<T> command) { if (command instanceof ArgumentCommandNode<?, ?>) { return argument(command); } else if (command instanceof LiteralCommandNode<?>) { return literal(command); } else if (command instanceof RootCommandNode<?>) { return root(command); } else { return otherwise(command); } }  CommandNode<R> map(CommandNode<T> command); static final Command<?> NONE; static final Predicate<?> TRUE; static final SuggestionProvider<?> EMPTY; }
@Test void map_argument() { var unmapped = Argument.<String, String>builder("b", StringArgumentType.word()).build(); var argument = (ArgumentCommandNode<String, String>) mapper.map(unmapped); assertEquals("b", argument.getName()); assertSame(unmapped.getType(), argument.getType()); assertSame(Mapper.NONE, argument.getCommand()); assertSame(Mapper.TRUE, argument.getRequirement()); assertNull(argument.getCustomSuggestions()); }
@Test void map_literal() { var literal = mapper.map(Literal.<String>builder("a").build()); assertTrue(literal instanceof LiteralCommandNode<?>); assertEquals("a", literal.getName()); assertSame(Mapper.NONE, literal.getCommand()); assertSame(Mapper.TRUE, literal.getRequirement()); }
@Test void map_root() { assertEquals(RootCommandNode.class, mapper.map(new RootCommandNode<>()).getClass()); }
@Test void map_otherwise() { var command = mock(CommandNode.class); assertEquals( "Unsupported command, '" + command.getName() + "' of type: " + command.getClass().getName(), assertThrows(IllegalArgumentException.class, () -> mapper.map(command)).getMessage() ); }