Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
StringUtilTest.java
1 package org.bukkit.util;
2 
3 import static org.hamcrest.Matchers.*;
4 import static org.junit.Assert.*;
5 
6 import java.util.ArrayList;
7 import java.util.Arrays;
8 import java.util.List;
9 
10 import org.junit.Test;
11 
12 import com.google.common.collect.ImmutableList;
13 
14 public class StringUtilTest {
15 
16  @Test(expected=NullPointerException.class)
17  public void nullPrefixTest() {
18  StringUtil.startsWithIgnoreCase("String", null);
19  }
20 
21  @Test(expected=IllegalArgumentException.class)
22  public void nullStringTest() {
23  StringUtil.startsWithIgnoreCase(null, "String");
24  }
25 
26  @Test(expected=IllegalArgumentException.class)
27  public void nullCollectionTest() {
28  StringUtil.copyPartialMatches("Token", ImmutableList.<String>of(), null);
29  }
30 
31  @Test(expected=IllegalArgumentException.class)
32  public void nullIterableTest() {
33  StringUtil.copyPartialMatches("Token", null, new ArrayList<String>());
34  }
35 
36  @Test(expected=IllegalArgumentException.class)
37  public void nullTokenTest() {
38  StringUtil.copyPartialMatches(null, ImmutableList.<String>of(), new ArrayList<String>());
39  }
40 
41  @Test
42  public void copyTokenTest() {
43  String token = "ab";
44  Iterable<String> original = ImmutableList.of("ab12", "aC561", "AB5195", "Ab76", "", "a");
45  List<String> expected = ImmutableList.of("ab12", "AB5195", "Ab76" );
46  List<String> list = new ArrayList<String>();
47  assertThat(StringUtil.copyPartialMatches(token, original, list), is(expected));
48  assertThat(StringUtil.copyPartialMatches(token, original, list), is(sameInstance(list)));
49  assertThat(list.size(), is(expected.size() * 2));
50  }
51 
52  @Test(expected=UnsupportedOperationException.class)
53  public void copyUnsupportedTest() {
54  StringUtil.copyPartialMatches("token", ImmutableList.of("token1", "token2"), ImmutableList.of());
55  }
56 
57  @Test(expected=IllegalArgumentException.class)
58  public void copyNullTest() {
59  StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList<String>());
60  }
61 }
static< TextendsCollection<?superString > T copyPartialMatches(final String token, final Iterable< String > originals, final T collection)
Definition: StringUtil.java:24
static boolean startsWithIgnoreCase(final String string, final String prefix)
Definition: StringUtil.java:50