Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
ChatPaginatorTest.java
1 package org.bukkit;
2 
4 import org.junit.Test;
5 
6 import static org.hamcrest.CoreMatchers.is;
7 import static org.hamcrest.CoreMatchers.nullValue;
8 import static org.junit.Assert.assertThat;
9 
10 /**
11  */
12 public class ChatPaginatorTest {
13  @Test
14  public void testWordWrap1() {
15  String rawString = ChatColor.RED + "123456789 123456789 123456789";
16  String[] lines = ChatPaginator.wordWrap(rawString, 19);
17 
18  assertThat(lines.length, is(2));
19  assertThat(lines[0], is(ChatColor.RED + "123456789 123456789"));
20  assertThat(lines[1], is(ChatColor.RED.toString() + "123456789"));
21  }
22 
23  @Test
24  public void testWordWrap2() {
25  String rawString = "123456789 123456789 123456789";
26  String[] lines = ChatPaginator.wordWrap(rawString, 22);
27 
28  assertThat(lines.length, is(2));
29  assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789 123456789"));
30  assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
31  }
32 
33  @Test
34  public void testWordWrap3() {
35  String rawString = ChatColor.RED + "123456789 " + ChatColor.RED + ChatColor.RED + "123456789 " + ChatColor.RED + "123456789";
36  String[] lines = ChatPaginator.wordWrap(rawString, 16);
37 
38  assertThat(lines.length, is(3));
39  assertThat(lines[0], is(ChatColor.RED + "123456789"));
40  assertThat(lines[1], is(ChatColor.RED.toString() + ChatColor.RED + "123456789"));
41  assertThat(lines[2], is(ChatColor.RED + "123456789"));
42  }
43 
44  @Test
45  public void testWordWrap4() {
46  String rawString = "123456789 123456789 123456789 12345";
47  String[] lines = ChatPaginator.wordWrap(rawString, 19);
48 
49  assertThat(lines.length, is(2));
50  assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789 123456789"));
51  assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789 12345"));
52  }
53 
54  @Test
55  public void testWordWrap5() {
56  String rawString = "123456789\n123456789 123456789";
57  String[] lines = ChatPaginator.wordWrap(rawString, 19);
58 
59  assertThat(lines.length, is(2));
60  assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789"));
61  assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789 123456789"));
62  }
63 
64  @Test
65  public void testWordWrap6() {
66  String rawString = "12345678 23456789 123456789";
67  String[] lines = ChatPaginator.wordWrap(rawString, 19);
68 
69  assertThat(lines.length, is(2));
70  assertThat(lines[0], is(ChatColor.WHITE.toString() + "12345678 23456789"));
71  assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
72  }
73 
74  @Test
75  public void testWordWrap7() {
76  String rawString = "12345678 23456789 123456789";
77  String[] lines = ChatPaginator.wordWrap(rawString, 19);
78 
79  assertThat(lines.length, is(2));
80  assertThat(lines[0], is(ChatColor.WHITE.toString() + "12345678 23456789"));
81  assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
82  }
83 
84  @Test
85  public void testWordWrap8() {
86  String rawString = "123456789 123456789 123456789";
87  String[] lines = ChatPaginator.wordWrap(rawString, 6);
88 
89  assertThat(lines.length, is(6));
90  assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456"));
91  assertThat(lines[1], is(ChatColor.WHITE.toString() + "789"));
92  assertThat(lines[2], is(ChatColor.WHITE.toString() + "123456"));
93  assertThat(lines[3], is(ChatColor.WHITE.toString() + "789"));
94  assertThat(lines[4], is(ChatColor.WHITE.toString() + "123456"));
95  assertThat(lines[5], is(ChatColor.WHITE.toString() + "789"));
96  }
97 
98  @Test
99  public void testWordWrap9() {
100  String rawString = "1234 123456789 123456789 123456789";
101  String[] lines = ChatPaginator.wordWrap(rawString, 6);
102 
103  assertThat(lines.length, is(7));
104  assertThat(lines[0], is(ChatColor.WHITE.toString() + "1234"));
105  assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456"));
106  assertThat(lines[2], is(ChatColor.WHITE.toString() + "789"));
107  assertThat(lines[3], is(ChatColor.WHITE.toString() + "123456"));
108  assertThat(lines[4], is(ChatColor.WHITE.toString() + "789"));
109  assertThat(lines[5], is(ChatColor.WHITE.toString() + "123456"));
110  assertThat(lines[6], is(ChatColor.WHITE.toString() + "789"));
111  }
112 
113  @Test
114  public void testWordWrap10() {
115  String rawString = "123456789\n123456789";
116  String[] lines = ChatPaginator.wordWrap(rawString, 19);
117 
118  assertThat(lines.length, is(2));
119  assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789"));
120  assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
121  }
122 
123  @Test
124  public void testWordWrap11() {
125  String rawString = ChatColor.RED + "a a a " + ChatColor.BLUE + "a a";
126  String[] lines = ChatPaginator.wordWrap(rawString, 9);
127 
128  assertThat(lines.length, is(1));
129  assertThat(lines[0], is(ChatColor.RED + "a a a " + ChatColor.BLUE + "a a"));
130  }
131 
132  @Test
133  public void testPaginate1() {
134  String rawString = "1234 123456789 123456789 123456789";
135  ChatPaginator.ChatPage page = ChatPaginator.paginate(rawString, 1, 6, 2);
136 
137  assertThat(page.getPageNumber(), is(1));
138  assertThat(page.getTotalPages(), is(4));
139  assertThat(page.getLines().length, is(2));
140  assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "1234"));
141  assertThat(page.getLines()[1], is(ChatColor.WHITE.toString() + "123456"));
142  }
143 
144  @Test
145  public void testPaginate2() {
146  String rawString = "1234 123456789 123456789 123456789";
147  ChatPaginator.ChatPage page = ChatPaginator.paginate(rawString, 2, 6, 2);
148 
149  assertThat(page.getPageNumber(), is(2));
150  assertThat(page.getTotalPages(), is(4));
151  assertThat(page.getLines().length, is(2));
152  assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "789"));
153  assertThat(page.getLines()[1], is(ChatColor.WHITE.toString() + "123456"));
154  }
155 
156  @Test
157  public void testPaginate3() {
158  String rawString = "1234 123456789 123456789 123456789";
159  ChatPaginator.ChatPage page = ChatPaginator.paginate(rawString, 4, 6, 2);
160 
161  assertThat(page.getPageNumber(), is(4));
162  assertThat(page.getTotalPages(), is(4));
163  assertThat(page.getLines().length, is(1));
164  assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "789"));
165  }
166 }
static String[] wordWrap(String rawString, int lineLength)
static ChatPage paginate(String unpaginatedString, int pageNumber)