Moved tests to correct location
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package net.minecraft.commands;
|
||||
|
||||
import net.minecraft.commands.context.CommandContext;
|
||||
import net.minecraft.commands.exceptions.UnknownCommandException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||
import static net.minecraft.commands.builder.LiteralArgumentBuilder.literal;
|
||||
import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandDispatcherTest {
|
||||
CommandDispatcher subject;
|
||||
@Mock Command command;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
subject = new CommandDispatcher();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndExecuteCommand() throws Exception {
|
||||
subject.register(literal("foo").executes(command));
|
||||
|
||||
subject.execute("foo");
|
||||
verify(command).run(any(CommandContext.class));
|
||||
}
|
||||
|
||||
@Test(expected = UnknownCommandException.class)
|
||||
public void testExecuteUnknownCommand() throws Exception {
|
||||
subject.execute("foo");
|
||||
}
|
||||
|
||||
@Test(expected = UnknownCommandException.class)
|
||||
public void testExecuteUnknownSubcommand() throws Exception {
|
||||
subject.register(literal("foo").executes(command));
|
||||
subject.execute("foo bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteSubcommand() throws Exception {
|
||||
Command subCommand = mock(Command.class);
|
||||
|
||||
subject.register(literal("foo").then(
|
||||
literal("a")
|
||||
).then(
|
||||
literal("b").executes(subCommand)
|
||||
).then(
|
||||
literal("c")
|
||||
).executes(command));
|
||||
|
||||
subject.execute("foo b");
|
||||
verify(subCommand).run(any(CommandContext.class));
|
||||
}
|
||||
|
||||
@Test(expected = UnknownCommandException.class)
|
||||
public void testExecuteInvalidSubcommand() throws Exception {
|
||||
subject.register(literal("foo").then(
|
||||
argument("bar", integer())
|
||||
).executes(command));
|
||||
|
||||
subject.execute("foo bar");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package net.minecraft.commands.arguments;
|
||||
|
||||
import net.minecraft.commands.context.CommandContext;
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import net.minecraft.commands.context.ParsedArgument;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class IntegerArgumentTypeTest {
|
||||
IntegerArgumentType type;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
type = integer(-100, 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
ParsedArgument<Integer> result = type.parse("50");
|
||||
|
||||
assertThat(result.getRaw(), is("50"));
|
||||
assertThat(result.getResult(), is(50));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentSyntaxException.class)
|
||||
public void testParseInvalid() throws Exception {
|
||||
type.parse("fifty");
|
||||
}
|
||||
|
||||
@Test(expected = ArgumentValidationException.class)
|
||||
public void testParseTooLow() throws Exception {
|
||||
type.parse("-101");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLowerLimit() throws Exception {
|
||||
ParsedArgument<Integer> result = type.parse("-100");
|
||||
|
||||
assertThat(result.getRaw(), is("-100"));
|
||||
assertThat(result.getResult(), is(-100));
|
||||
}
|
||||
|
||||
@Test(expected = ArgumentValidationException.class)
|
||||
public void testParseTooHigh() throws Exception {
|
||||
type.parse("101");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseHigherLimit() throws Exception {
|
||||
ParsedArgument<Integer> result = type.parse("100");
|
||||
|
||||
assertThat(result.getRaw(), is("100"));
|
||||
assertThat(result.getResult(), is(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInteger() throws Exception {
|
||||
CommandContext context = new CommandContextBuilder().withArgument("foo", type.parse("100")).build();
|
||||
|
||||
assertThat(IntegerArgumentType.getInteger(context, "foo"), is(100));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.minecraft.commands.builder;
|
||||
|
||||
import net.minecraft.commands.tree.CommandNode;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||
import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class ArgumentBuilderTest {
|
||||
TestableArgumentBuilder builder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
builder = new TestableArgumentBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArguments() throws Exception {
|
||||
RequiredArgumentBuilder argument = argument("bar", integer());
|
||||
|
||||
builder.then(argument);
|
||||
|
||||
assertThat(builder.getArguments(), hasSize(1));
|
||||
assertThat(builder.getArguments(), hasItems((ArgumentBuilder) argument));
|
||||
}
|
||||
|
||||
private static class TestableArgumentBuilder extends ArgumentBuilder<TestableArgumentBuilder> {
|
||||
@Override
|
||||
protected TestableArgumentBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandNode build() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.minecraft.commands.builder;
|
||||
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.tree.LiteralCommandNode;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||
import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class LiteralArgumentBuilderTest {
|
||||
LiteralArgumentBuilder builder;
|
||||
@Mock
|
||||
Command command;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
builder = new LiteralArgumentBuilder("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuild() throws Exception {
|
||||
LiteralCommandNode node = builder.build();
|
||||
|
||||
assertThat(node.getLiteral(), is("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithExecutor() throws Exception {
|
||||
LiteralCommandNode node = builder.executes(command).build();
|
||||
|
||||
assertThat(node.getLiteral(), is("foo"));
|
||||
assertThat(node.getCommand(), is(command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithChildren() throws Exception {
|
||||
builder.then(argument("bar", integer()));
|
||||
builder.then(argument("baz", integer()));
|
||||
LiteralCommandNode node = builder.build();
|
||||
|
||||
assertThat(node.getChildren(), hasSize(2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.minecraft.commands.builder;
|
||||
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.arguments.CommandArgumentType;
|
||||
import net.minecraft.commands.tree.ArgumentCommandNode;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||
import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class RequiredArgumentBuilderTest {
|
||||
@Mock CommandArgumentType<Integer> type;
|
||||
RequiredArgumentBuilder<Integer> builder;
|
||||
@Mock
|
||||
Command command;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
builder = argument("foo", type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuild() throws Exception {
|
||||
ArgumentCommandNode<Integer> node = builder.build();
|
||||
|
||||
assertThat(node.getName(), is("foo"));
|
||||
assertThat(node.getType(), is(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithExecutor() throws Exception {
|
||||
ArgumentCommandNode<Integer> node = builder.executes(command).build();
|
||||
|
||||
assertThat(node.getName(), is("foo"));
|
||||
assertThat(node.getType(), is(type));
|
||||
assertThat(node.getCommand(), is(command));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildWithChildren() throws Exception {
|
||||
builder.then(argument("bar", integer()));
|
||||
builder.then(argument("baz", integer()));
|
||||
ArgumentCommandNode node = builder.build();
|
||||
|
||||
assertThat(node.getChildren(), hasSize(2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.minecraft.commands.context;
|
||||
|
||||
import net.minecraft.commands.arguments.IntegerArgumentType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class CommandContextTest {
|
||||
CommandContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
context = new CommandContextBuilder().build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetArgument_nonexistent() throws Exception {
|
||||
context.getArgument("foo", Object.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetArgument_wrongType() throws Exception {
|
||||
context = new CommandContextBuilder().withArgument("foo", IntegerArgumentType.integer().parse("123")).build();
|
||||
context.getArgument("foo", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArgument() throws Exception {
|
||||
context = new CommandContextBuilder().withArgument("foo", IntegerArgumentType.integer().parse("123")).build();
|
||||
assertThat(context.getArgument("foo", int.class).getResult(), is(123));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||
import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class ArgumentCommandNodeTest {
|
||||
ArgumentCommandNode node;
|
||||
CommandContextBuilder contextBuilder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
node = argument("foo", integer()).build();
|
||||
contextBuilder = new CommandContextBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
assertThat(node.parse("123 456", contextBuilder), is("456"));
|
||||
|
||||
assertThat(contextBuilder.getArguments().containsKey("foo"), is(true));
|
||||
assertThat(contextBuilder.getArguments().get("foo").getResult(), is((Object) 123));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseExact() throws Exception {
|
||||
assertThat(node.parse("123", contextBuilder), is(""));
|
||||
|
||||
assertThat(contextBuilder.getArguments().containsKey("foo"), is(true));
|
||||
assertThat(contextBuilder.getArguments().get("foo").getResult(), is((Object) 123));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentSyntaxException.class)
|
||||
public void testParseInvalid() throws Exception {
|
||||
node.parse("foo", contextBuilder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static net.minecraft.commands.builder.LiteralArgumentBuilder.literal;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class LiteralCommandNodeTest {
|
||||
LiteralCommandNode node;
|
||||
CommandContextBuilder contextBuilder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
node = literal("foo").build();
|
||||
contextBuilder = new CommandContextBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
assertThat(node.parse("foo bar", contextBuilder), is("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseExact() throws Exception {
|
||||
assertThat(node.parse("foo", contextBuilder), is(""));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentSyntaxException.class)
|
||||
public void testParseSimilar() throws Exception {
|
||||
node.parse("foobar", contextBuilder);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentSyntaxException.class)
|
||||
public void testParseInvalid() throws Exception {
|
||||
node.parse("bar", contextBuilder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class RootCommandNodeTest {
|
||||
RootCommandNode node;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
node = new RootCommandNode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
assertThat(node.parse("foo bar baz", new CommandContextBuilder()), is("foo bar baz"));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user