From f91bc15e19bf4bb20cf0407e5f3a75ffd45b1637 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Thu, 25 Sep 2014 13:25:29 +0200 Subject: [PATCH] Added a nice toString to IntegerArgumentType --- .../commands/arguments/IntegerArgumentType.java | 11 +++++++++++ .../commands/arguments/IntegerArgumentTypeTest.java | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/net/minecraft/commands/arguments/IntegerArgumentType.java b/src/main/java/net/minecraft/commands/arguments/IntegerArgumentType.java index e1559b6..720df78 100644 --- a/src/main/java/net/minecraft/commands/arguments/IntegerArgumentType.java +++ b/src/main/java/net/minecraft/commands/arguments/IntegerArgumentType.java @@ -67,4 +67,15 @@ public class IntegerArgumentType implements CommandArgumentType { public int hashCode() { return 31 * minimum + maximum; } + + @Override + public String toString() { + if (minimum == Integer.MIN_VALUE && maximum == Integer.MAX_VALUE) { + return "integer()"; + } else if (maximum == Integer.MAX_VALUE) { + return "integer(" + minimum + ")"; + } else { + return "integer(" + minimum + ", " + maximum + ")"; + } + } } diff --git a/src/test/java/net/minecraft/commands/arguments/IntegerArgumentTypeTest.java b/src/test/java/net/minecraft/commands/arguments/IntegerArgumentTypeTest.java index c64dc3c..8be9b6d 100644 --- a/src/test/java/net/minecraft/commands/arguments/IntegerArgumentTypeTest.java +++ b/src/test/java/net/minecraft/commands/arguments/IntegerArgumentTypeTest.java @@ -10,6 +10,7 @@ import org.junit.Before; import org.junit.Test; import static net.minecraft.commands.arguments.IntegerArgumentType.integer; +import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -76,4 +77,12 @@ public class IntegerArgumentTypeTest { .addEqualityGroup(integer(-50, 100), integer(-50, 100)) .testEquals(); } + + @Test + public void testToString() throws Exception { + assertThat(integer(), hasToString("integer()")); + assertThat(integer(-100), hasToString("integer(-100)")); + assertThat(integer(-100, 100), hasToString("integer(-100, 100)")); + assertThat(integer(Integer.MIN_VALUE, 100), hasToString("integer(-2147483648, 100)")); + } } \ No newline at end of file