Practice with string and loop

StringParserTest.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import org.junit.Test;
  2. import static org.junit.Assert.*;
  3. public class StringParserTest {
  4. @Test
  5. public void upperCaseString() {
  6. //Given
  7. String string1 = "test string";
  8. String expected = "TEST STRING";
  9. //When
  10. String actual = StringParser.upperCaseString(string1);
  11. //Expect
  12. assertEquals(expected, actual);
  13. }
  14. @Test
  15. public void lowerCaseString() {
  16. //Given
  17. String string1 = "TEST STRING";
  18. String expected = "test string";
  19. //When
  20. String actual = StringParser.lowerCaseString(string1);
  21. //Expect
  22. assertEquals(expected, actual);
  23. }
  24. @Test
  25. public void getFirstCharacter() {
  26. //Given
  27. String string1 = "test string";
  28. Character expected = 't';
  29. //When
  30. Character actual = StringParser.getFirstCharacter(string1);
  31. //Expect
  32. assertEquals(expected, actual);
  33. }
  34. @Test
  35. public void getNthCharacter() {
  36. //Given
  37. String string1 = "test string";
  38. Integer index = 2;
  39. Character expected = 's';
  40. //When
  41. Character actual = StringParser.getNthCharacter(string1, index);
  42. //Expect
  43. assertEquals(expected, actual);
  44. }
  45. @Test
  46. public void upperCaseFirstCharacter() {
  47. //Given
  48. String string1 = "test string";
  49. String expected = "Test string";
  50. //When
  51. String actual = StringParser.upperCaseFirstCharacter(string1);
  52. //Expect
  53. assertEquals(expected, actual);
  54. }
  55. @Test
  56. public void camelCaseString() {
  57. //Given
  58. String string1 = "tEsT sTrInG";
  59. String expected = "TestString";
  60. //When
  61. String actual = StringParser.camelCaseString(string1);
  62. //Expect
  63. assertEquals(expected, actual);
  64. }
  65. @Test
  66. public void snakeCaseString() {
  67. //Given
  68. String string1 = "tEST STring";
  69. String expected = "test_string";
  70. //When
  71. String actual = StringParser.snakeCaseString(string1);
  72. //Expect
  73. assertEquals(expected, actual);
  74. }
  75. @Test
  76. public void getLength() {
  77. //Given
  78. String string1 = "A different string";
  79. Integer expected1 = 18;
  80. String string2 = "test string";
  81. Integer expected2 = 11;
  82. //When
  83. Integer actual1 = StringParser.getLength(string1);
  84. Integer actual2 = StringParser.getLength(string2);
  85. //Expect
  86. assertEquals(expected1, actual1);
  87. assertEquals(expected2, actual2);
  88. }
  89. @Test
  90. public void isEqual() {
  91. //Given
  92. String string1 = "A different string";
  93. String compareString1 = "a Different string";
  94. Boolean expected1 = false;
  95. String string2 = "test string";
  96. String compareString2 = "test string";
  97. Boolean expected2 = true;
  98. //When
  99. Boolean actual1 = StringParser.isEqual(string1, compareString1);
  100. Boolean actual2 = StringParser.isEqual(string2, compareString2);
  101. //Expect
  102. assertEquals(expected1, actual1);
  103. assertEquals(expected2, actual2);
  104. }
  105. @Test
  106. public void isEqualIgnoreCase() {
  107. //Given
  108. String string1 = "A different string";
  109. String compareString1 = "a Different string";
  110. Boolean expected1 = true;
  111. String string2 = "test string";
  112. String compareString2 = "test string";
  113. Boolean expected2 = true;
  114. String string3 = "A different string";
  115. String compareString3 = "A different string!";
  116. Boolean expected3 = false;
  117. //When
  118. Boolean actual1 = StringParser.isEqualIgnoreCase(string1, compareString1);
  119. Boolean actual2 = StringParser.isEqualIgnoreCase(string2, compareString2);
  120. Boolean actual3 = StringParser.isEqualIgnoreCase(string3, compareString3);
  121. //Expect
  122. assertEquals(expected1, actual1);
  123. assertEquals(expected2, actual2);
  124. assertEquals(expected3, actual3);
  125. }
  126. }