implement a whole bunch of simple methods.

StringUtilitiesTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class StringUtilitiesTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class StringUtilitiesTest
  12. {
  13. /**
  14. * Default constructor for test class StringUtilitiesTest
  15. */
  16. public StringUtilitiesTest()
  17. {
  18. }
  19. /**
  20. * Sets up the test fixture.
  21. *
  22. * Called before every test case method.
  23. */
  24. @Before
  25. public void setUp()
  26. {
  27. }
  28. /**
  29. * Tears down the test fixture.
  30. *
  31. * Called after every test case method.
  32. */
  33. @After
  34. public void tearDown()
  35. {
  36. }
  37. @Test
  38. public void getHelloWorldTest() {
  39. // : Given
  40. String expected = "Hello World";
  41. // : When
  42. String actual = StringUtilities.getHelloWorld();
  43. // : Then
  44. assertEquals(expected, actual);
  45. }
  46. @Test
  47. public void concatenationStringTest(){
  48. // : Given
  49. String one = "Hello";
  50. String two = " Java";
  51. String expected = "Hello Java";
  52. // : When
  53. String actual = StringUtilities.concatenation(one,two);
  54. // : Then
  55. assertEquals(expected, actual);
  56. }
  57. @Test
  58. public void concatenationStringAndIntegerTest(){
  59. // : Given
  60. int one = 1;
  61. String two = " Java";
  62. String expected = "1 Java";
  63. // : When
  64. String actual = StringUtilities.concatenation(one,two);
  65. // : Then
  66. assertEquals(expected, actual);
  67. }
  68. @Test
  69. public void substringBeginTest(){
  70. // : Given
  71. String input = "Hello";
  72. String expected = "Hel";
  73. // : When
  74. String actual = StringUtilities.getPrefix(input);
  75. // : Then
  76. assertEquals(expected, actual);
  77. }
  78. @Test
  79. public void substringEndTest(){
  80. // : Given
  81. String input = "Hello";
  82. String expected = "llo";
  83. // : When
  84. String actual = StringUtilities.getSuffix("Hello");
  85. // : Then
  86. assertEquals(expected, actual);
  87. }
  88. @Test
  89. public void compareToTestEquals(){
  90. // : Given
  91. String inputValue = "Zipcode";
  92. String comparableValue = "Zipcode";
  93. // : When
  94. boolean actual = StringUtilities.compareTwoStrings(inputValue, comparableValue);
  95. // : Then
  96. assertTrue(actual);
  97. }
  98. @Test
  99. public void compareToTestNotEquals(){
  100. // : Given
  101. String inputValue = "Zipcode";
  102. String comparableValue = "Zipcodee";
  103. // : When
  104. boolean actual = StringUtilities.compareTwoStrings(inputValue, comparableValue);
  105. // : Then
  106. assertFalse(actual);
  107. }
  108. @Test
  109. public void getTheMiddleChar1(){
  110. // : Given
  111. String input = "Zipcode";
  112. Character expected = 'c';
  113. // : When
  114. Character actual = StringUtilities.getMiddleCharacter(input);
  115. // : Then
  116. assertEquals(expected.toString(), actual.toString());
  117. }
  118. @Test
  119. public void getTheMiddleChar2(){
  120. // : Given
  121. String input = "Zipcoder";
  122. Character expected = 'c';
  123. // : When
  124. Character actual = StringUtilities.getMiddleCharacter(input);
  125. // : Then
  126. assertEquals(expected.toString(), actual.toString());
  127. }
  128. @Test
  129. public void getTheFirstWord(){
  130. // : Given
  131. String input = "Zipcode Wilmington";
  132. String expected = "Zipcode";
  133. // : When
  134. String actual = StringUtilities.getFirstWord(input);
  135. // : Then
  136. assertEquals(expected, actual);
  137. }
  138. @Test
  139. public void getTheSecondWord(){
  140. // : Given
  141. String input = "Zipcode Wilmington";
  142. String expected = "Wilmington";
  143. // : When
  144. String actual = StringUtilities.getSecondWord(input);
  145. // : Then
  146. assertEquals(expected, actual);
  147. }
  148. @Test
  149. public void reverseThem(){
  150. // : Given
  151. String input = "Zipcode Wilmington";
  152. String expected = "notgnimliW edocpiZ";
  153. // : When
  154. String actual = StringUtilities.reverse(input);
  155. // : Then
  156. assertEquals(expected, actual);
  157. }
  158. }