Added a 'source' for commands that may be passed around in the context
This commit is contained in:
@@ -3,32 +3,42 @@ package net.minecraft.commands.context;
|
||||
import net.minecraft.commands.arguments.IntegerArgumentType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandContextTest {
|
||||
CommandContext context;
|
||||
CommandContextBuilder<Object> builder;
|
||||
@Mock Object source;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
context = new CommandContextBuilder().build();
|
||||
builder = new CommandContextBuilder<Object>(source);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetArgument_nonexistent() throws Exception {
|
||||
context.getArgument("foo", Object.class);
|
||||
builder.build().getArgument("foo", Object.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetArgument_wrongType() throws Exception {
|
||||
context = new CommandContextBuilder().withArgument("foo", IntegerArgumentType.integer().parse("123")).build();
|
||||
CommandContext<Object> context = builder.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();
|
||||
CommandContext<Object> context = builder.withArgument("foo", IntegerArgumentType.integer().parse("123")).build();
|
||||
assertThat(context.getArgument("foo", int.class).getResult(), is(123));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSource() throws Exception {
|
||||
assertThat(builder.build().getSource(), is(source));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user