StringUtilitiesTest.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import org.junit.Assert;
  2. import org.junit.Test;
  3. import static org.junit.Assert.*;
  4. /**
  5. * Created by dan on 6/14/17.
  6. */
  7. public class StringUtilitiesTest {
  8. @Test
  9. public void getHelloWorldTest() {
  10. // : Given
  11. String expected = "Hello World";
  12. // : When
  13. String actual = StringUtilities.getHelloWorld();
  14. // : Then
  15. assertEquals(expected, actual);
  16. }
  17. @Test
  18. public void concatenationStringTest(){
  19. // : Given
  20. String one = "Hello";
  21. String two = " Java";
  22. String expected = "Hello Java";
  23. // : When
  24. String actual = StringUtilities.concatenation(one,two);
  25. // : Then
  26. assertEquals(expected, actual);
  27. }
  28. @Test
  29. public void concatenationStringAndIntegerTest(){
  30. // : Given
  31. int one = 1;
  32. String two = " Java";
  33. String expected = "1 Java";
  34. // : When
  35. String actual = StringUtilities.concatenation(one,two);
  36. // : Then
  37. assertEquals(expected, actual);
  38. }
  39. @Test
  40. public void substringBeginTest(){
  41. // : Given
  42. String input = "Hello";
  43. String expected = "Hel";
  44. // : When
  45. String actual = StringUtilities.getPrefix(input);
  46. // : Then
  47. assertEquals(expected, actual);
  48. }
  49. @Test
  50. public void substringEndTest(){
  51. // : Given
  52. String input = "Hello";
  53. String expected = "llo";
  54. // : When
  55. String actual = StringUtilities.getSuffix("Hello");
  56. // : Then
  57. assertEquals(expected, actual);
  58. }
  59. @Test
  60. public void compareToTestEquals(){
  61. // : Given
  62. String inputValue = "Zipcode";
  63. String comparableValue = "Zipcode";
  64. // : When
  65. boolean actual = StringUtilities.compareTwoStrings(inputValue, comparableValue);
  66. // : Then
  67. assertTrue(actual);
  68. }
  69. @Test
  70. public void compareToTestNotEquals(){
  71. // : Given
  72. String inputValue = "Zipcode";
  73. String comparableValue = "Zipcodee";
  74. // : When
  75. boolean actual = StringUtilities.compareTwoStrings(inputValue, comparableValue);
  76. // : Then
  77. assertFalse(actual);
  78. }
  79. @Test
  80. public void getTheMiddleChar1(){
  81. // : Given
  82. String input = "Zipcode";
  83. Character expected = 'c';
  84. // : When
  85. Character actual = StringUtilities.getMiddleCharacter(input);
  86. // : Then
  87. Assert.assertEquals(expected.toString(), actual.toString());
  88. }
  89. @Test
  90. public void getTheMiddleChar2(){
  91. // : Given
  92. String input = "Zipcoder";
  93. Character expected = 'c';
  94. // : When
  95. Character actual = StringUtilities.getMiddleCharacter(input);
  96. // : Then
  97. Assert.assertEquals(expected.toString(), actual.toString());
  98. }
  99. @Test
  100. public void getTheFirstWord(){
  101. // : Given
  102. String input = "Zipcode Wilmington";
  103. String expected = "Zipcode";
  104. // : When
  105. String actual = StringUtilities.getFirstWord(input);
  106. // : Then
  107. assertEquals(expected, actual);
  108. }
  109. @Test
  110. public void getTheSecondWord(){
  111. // : Given
  112. String input = "Zipcode Wilmington";
  113. String expected = "Wilmington";
  114. // : When
  115. String actual = StringUtilities.getSecondWord(input);
  116. // : Then
  117. assertEquals(expected, actual);
  118. }
  119. @Test
  120. public void reverseThem(){
  121. // : Given
  122. String input = "Zipcode Wilmington";
  123. String expected = "notgnimliW edocpiZ";
  124. // : When
  125. String actual = StringUtilities.reverse(input);
  126. // : Then
  127. assertEquals(expected, actual);
  128. }
  129. }