Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
ChatColorTest.java
1 package org.bukkit;
2 
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.hamcrest.CoreMatchers.nullValue;
5 import static org.junit.Assert.assertThat;
6 
7 import org.junit.Test;
8 
9 public class ChatColorTest {
10 
11  @Test
12  public void getByChar() {
13  for (ChatColor color : ChatColor.values()) {
14  assertThat(ChatColor.getByChar(color.getChar()), is(color));
15  }
16  }
17 
18  @Test(expected = IllegalArgumentException.class)
19  public void getByStringWithNull() {
20  ChatColor.getByChar((String) null);
21  }
22 
23  @Test(expected = IllegalArgumentException.class)
24  public void getByStringWithEmpty() {
25  ChatColor.getByChar("");
26  }
27 
28  @Test
29  public void getByNull() {
30  assertThat(ChatColor.stripColor(null), is(nullValue()));
31  }
32 
33  @Test
34  public void getByString() {
35  for (ChatColor color : ChatColor.values()) {
36  assertThat(ChatColor.getByChar(String.valueOf(color.getChar())), is(color));
37  }
38  }
39 
40  @Test
41  public void stripColorOnNullString() {
42  assertThat(ChatColor.stripColor(null), is(nullValue()));
43  }
44 
45  @Test
46  public void stripColor() {
47  StringBuilder subject = new StringBuilder();
48  StringBuilder expected = new StringBuilder();
49 
50  final String filler = "test";
51  for (ChatColor color : ChatColor.values()) {
52  subject.append(color).append(filler);
53  expected.append(filler);
54  }
55 
56  assertThat(ChatColor.stripColor(subject.toString()), is(expected.toString()));
57  }
58 
59  @Test
60  public void toStringWorks() {
61  for (ChatColor color : ChatColor.values()) {
62  assertThat(String.format("%c%c", ChatColor.COLOR_CHAR, color.getChar()), is(color.toString()));
63  }
64  }
65 
66  @Test
67  public void translateAlternateColorCodes() {
68  String s = "&0&1&2&3&4&5&6&7&8&9&A&a&B&b&C&c&D&d&E&e&F&f&K&k & more";
69  String t = ChatColor.translateAlternateColorCodes('&', s);
71  assertThat(t, is(u));
72  }
73 
74  @Test
75  public void getChatColors() {
76  String s = String.format("%c%ctest%c%ctest%c", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.ITALIC.getChar(), ChatColor.COLOR_CHAR);
77  String expected = ChatColor.RED.toString() + ChatColor.ITALIC;
78  assertThat(ChatColor.getLastColors(s), is(expected));
79 
80  s = String.format("%c%ctest%c%ctest", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.BLUE.getChar());
81  assertThat(ChatColor.getLastColors(s), is(ChatColor.BLUE.toString()));
82  }
83 }
static ChatColor getByChar(char code)
Definition: ChatColor.java:163
static String getLastColors(String input)
Definition: ChatColor.java:222
static String stripColor(final String input)
Definition: ChatColor.java:187
static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
Definition: ChatColor.java:205
staticfinal char COLOR_CHAR
Definition: ChatColor.java:107