Test the parsing of the time and all the variations.
This commit is contained in:
parent
c4b1eb6d1a
commit
ed481ff925
@ -12,7 +12,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Util {
|
||||
private final static Pattern DURATION_PATTERN = Pattern.compile("^(\\d+)\\s*(min(?:ute)?s?|h(?:ours?)?|d(?:ays?)?|s(?:econd)?s?)?$", Pattern.CASE_INSENSITIVE);
|
||||
private final static Pattern DURATION_PATTERN = Pattern.compile("^(\\d+)\\s*(m(?:inute)?s?|h(?:ours?)?|d(?:ays?)?|s(?:econd)?s?)?$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
/** Checks if the first {@link Vector} is inside the other two. */
|
||||
public static boolean isInsideAB(Vector point, Vector first, Vector second) {
|
||||
@ -79,7 +79,7 @@ public class Util {
|
||||
String units = match.group(2);
|
||||
if ("seconds".equals(units) || "second".equals(units) || "s".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.SECONDS);
|
||||
if ("minutes".equals(units) || "minute".equals(units) || "mins".equals(units) || "min".equals(units))
|
||||
if ("minutes".equals(units) || "minute".equals(units) || "mins".equals(units) || "min".equals(units) || "m".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.MINUTES);
|
||||
else if ("hours".equals(units) || "hour".equals(units) || "h".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.HOURS);
|
||||
@ -95,7 +95,7 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
return Long.valueOf(t);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -0,0 +1,37 @@
|
||||
package test.java.com.graywolf336.jail;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graywolf336.jail.Util;
|
||||
|
||||
public class TestTimeParsing {
|
||||
|
||||
@Test
|
||||
public void testSeconds() throws Exception {
|
||||
assertThat(1000L, is(Util.getTime("1s")));
|
||||
assertThat(1000L, is(Util.getTime("1second")));
|
||||
assertThat(1000L, is(Util.getTime("1seconds")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutes() throws Exception {
|
||||
assertThat(60000L, is(Util.getTime("1m")));
|
||||
assertThat(60000L, is(Util.getTime("1minute")));
|
||||
assertThat(60000L, is(Util.getTime("1minutes")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHours() throws Exception {
|
||||
assertThat(3600000L, is(Util.getTime("1h")));
|
||||
assertThat(3600000L, is(Util.getTime("1hours")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDays() throws Exception {
|
||||
assertThat(86400000L, is(Util.getTime("1d")));
|
||||
assertThat(86400000L, is(Util.getTime("1days")));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user