mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Fix two failing tests.
This commit is contained in:
@@ -46,7 +46,7 @@ public class TestGamePacketEncoder {
|
||||
|
||||
packet = new GamePacket(9, PacketType.VARIABLE_BYTE, payload.copy());
|
||||
out.clear();
|
||||
encoder.encode(null, null, out);
|
||||
encoder.encode(null, packet, out);
|
||||
buf = (ByteBuf) out.get(0);
|
||||
|
||||
assertEquals(7, buf.readableBytes());
|
||||
|
||||
@@ -19,22 +19,28 @@ public final class TextUtil {
|
||||
/**
|
||||
* Capitalizes the string correctly.
|
||||
*
|
||||
* @param str The input string.
|
||||
* @param string The input string.
|
||||
* @return The string with correct capitalization.
|
||||
*/
|
||||
public static String capitalize(String str) {
|
||||
public static String capitalize(String string) {
|
||||
boolean capitalize = true;
|
||||
StringBuilder bldr = new StringBuilder(str);
|
||||
for (int index = 0, length = str.length(); index < length; index++) {
|
||||
char character = bldr.charAt(index);
|
||||
StringBuilder builder = new StringBuilder(string);
|
||||
int length = string.length();
|
||||
|
||||
for (int index = 0; index < length; index++) {
|
||||
char character = builder.charAt(index);
|
||||
|
||||
if (character == '.' || character == '!' || character == '?') {
|
||||
capitalize = true;
|
||||
} else if (capitalize && !Character.isWhitespace(character)) {
|
||||
bldr.setCharAt(index, Character.toUpperCase(character));
|
||||
builder.setCharAt(index, Character.toUpperCase(character));
|
||||
capitalize = false;
|
||||
} else {
|
||||
builder.setCharAt(index, Character.toLowerCase(character));
|
||||
}
|
||||
}
|
||||
return bldr.toString();
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,4 +22,4 @@ public class TestLanguageUtil {
|
||||
assertEquals("a", LanguageUtil.getIndefiniteArticle("foot"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,11 @@ public class TestTextUtil {
|
||||
*/
|
||||
@Test
|
||||
public void testCapitalize() {
|
||||
String str = "tHiS is BAD capitAliZation. do You AGreE? YES!";
|
||||
String capitalized = "This is bad capitalization. Do you agree? Yes!";
|
||||
assertEquals(capitalized, TextUtil.capitalize(str));
|
||||
String incorrect = "tHiS is BAD capitAliZation. do You AGreE? YES!";
|
||||
String correct = "This is bad capitalization. Do you agree? Yes!";
|
||||
assertEquals(correct, TextUtil.capitalize(incorrect));
|
||||
|
||||
assertEquals("Test", TextUtil.capitalize("test"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user