diff options
author | Wesley Wolfe <weswolf@aol.com> | 2014-01-04 12:43:49 -0600 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2014-01-04 12:43:49 -0600 |
commit | 81d3f6367e0f7fc76fc6f7e3625c1d12819a7807 (patch) | |
tree | 2d7877f7eb8ac1fdb3458a480cf43e07ff48d7cf /src/test | |
parent | aa4f9093241e64d6dd19d9f7cdbdeb6617443797 (diff) | |
download | bukkit-81d3f6367e0f7fc76fc6f7e3625c1d12819a7807.tar bukkit-81d3f6367e0f7fc76fc6f7e3625c1d12819a7807.tar.gz bukkit-81d3f6367e0f7fc76fc6f7e3625c1d12819a7807.tar.lz bukkit-81d3f6367e0f7fc76fc6f7e3625c1d12819a7807.tar.xz bukkit-81d3f6367e0f7fc76fc6f7e3625c1d12819a7807.zip |
Add unit tests for org.bukkit.util.StringUtil
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/bukkit/util/StringUtilStartsWithTest.java | 86 | ||||
-rw-r--r-- | src/test/java/org/bukkit/util/StringUtilTest.java | 61 |
2 files changed, 147 insertions, 0 deletions
diff --git a/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java b/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java new file mode 100644 index 00000000..b85a2b21 --- /dev/null +++ b/src/test/java/org/bukkit/util/StringUtilStartsWithTest.java @@ -0,0 +1,86 @@ +package org.bukkit.util; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +import com.google.common.collect.ImmutableList; + +@RunWith(Parameterized.class) +public class StringUtilStartsWithTest { + + @Parameters(name= "{index}: {0} startsWith {1} == {2}") + public static List<Object[]> data() { + return ImmutableList.<Object[]>of( + new Object[] { + "Apple", + "Apples", + false + }, + new Object[] { + "Apples", + "Apple", + true + }, + new Object[] { + "Apple", + "Apple", + true + }, + new Object[] { + "Apple", + "apples", + false + }, + new Object[] { + "apple", + "Apples", + false + }, + new Object[] { + "apple", + "apples", + false + }, + new Object[] { + "Apples", + "apPL", + true + }, + new Object[] { + "123456789", + "1234567", + true + }, + new Object[] { + "", + "", + true + }, + new Object[] { + "string", + "", + true + } + ); + } + + @Parameter(0) + public String base; + @Parameter(1) + public String prefix; + @Parameter(2) + public boolean result; + + @Test + public void testFor() { + assertThat(base + " starts with " + prefix + ": " + result, StringUtil.startsWithIgnoreCase(base, prefix), is(result)); + } +} diff --git a/src/test/java/org/bukkit/util/StringUtilTest.java b/src/test/java/org/bukkit/util/StringUtilTest.java new file mode 100644 index 00000000..9c8444c1 --- /dev/null +++ b/src/test/java/org/bukkit/util/StringUtilTest.java @@ -0,0 +1,61 @@ +package org.bukkit.util; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import com.google.common.collect.ImmutableList; + +public class StringUtilTest { + + @Test(expected=NullPointerException.class) + public void nullPrefixTest() { + StringUtil.startsWithIgnoreCase("String", null); + } + + @Test(expected=IllegalArgumentException.class) + public void nullStringTest() { + StringUtil.startsWithIgnoreCase(null, "String"); + } + + @Test(expected=IllegalArgumentException.class) + public void nullCollectionTest() { + StringUtil.copyPartialMatches("Token", ImmutableList.<String>of(), null); + } + + @Test(expected=IllegalArgumentException.class) + public void nullIterableTest() { + StringUtil.copyPartialMatches("Token", null, new ArrayList<String>()); + } + + @Test(expected=IllegalArgumentException.class) + public void nullTokenTest() { + StringUtil.copyPartialMatches(null, ImmutableList.<String>of(), new ArrayList<String>()); + } + + @Test + public void copyTokenTest() { + String token = "ab"; + Iterable<String> original = ImmutableList.of("ab12", "aC561", "AB5195", "Ab76", "", "a"); + List<String> expected = ImmutableList.of("ab12", "AB5195", "Ab76" ); + List<String> list = new ArrayList<String>(); + assertThat(StringUtil.copyPartialMatches(token, original, list), is(expected)); + assertThat(StringUtil.copyPartialMatches(token, original, list), is(sameInstance(list))); + assertThat(list.size(), is(expected.size() * 2)); + } + + @Test(expected=UnsupportedOperationException.class) + public void copyUnsupportedTest() { + StringUtil.copyPartialMatches("token", ImmutableList.of("token1", "token2"), ImmutableList.of()); + } + + @Test(expected=IllegalArgumentException.class) + public void copyNullTest() { + StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList<String>()); + } +} |