123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package QuizWeek1;
  2. import static org.junit.Assert.*;
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. public class StringUtilitiesTest {
  7. private StringUtilities utilities;
  8. @Before
  9. public void setUp() {
  10. utilities = new StringUtilities();
  11. }
  12. @Test
  13. public void testGetMiddleCharacter_ForOddWord(){
  14. //Given
  15. String word = "bokeh";
  16. char expected = 'k';
  17. //When
  18. char actual = utilities.getMiddleCharacter(word);
  19. //Then
  20. assertEquals(expected, actual);
  21. }
  22. @Test
  23. public void testGetMiddleCharacter_ForLongOddWord(){
  24. //Given
  25. String word = "disinformations";
  26. char expected = 'r';
  27. //When
  28. char actual = utilities.getMiddleCharacter(word);
  29. //Then
  30. assertEquals(expected, actual);
  31. }
  32. @Test
  33. public void testGetMiddleCharacter_ForEvenWord(){
  34. //Given
  35. String word = "dogs";
  36. char expected = 'g';
  37. //When
  38. char actual = utilities.getMiddleCharacter(word);
  39. //Then
  40. assertEquals(expected, actual);
  41. }
  42. @Test
  43. public void testRemoveCharacter(){
  44. // Given
  45. String word = "taradiddle";
  46. String expected = "taraile";
  47. //When
  48. String actual = utilities.removeCharacter(word, 'd');
  49. //Then
  50. assertEquals(expected, actual);
  51. }
  52. @Test
  53. public void testRemoveCharacter_atTheEnd(){
  54. // Given
  55. String word = "taradiddle";
  56. String expected = "taradiddl";
  57. //When
  58. String actual = utilities.removeCharacter(word, 'e');
  59. //Then
  60. assertEquals(expected, actual);
  61. }
  62. @Test
  63. public void testRemoveCharacter_thatIsNotInTheString(){
  64. // Given
  65. String word = "taradiddle";
  66. String expected = "taradiddle";
  67. //When
  68. String actual = utilities.removeCharacter(word, 'x');
  69. //Then
  70. assertEquals(expected, actual);
  71. }
  72. @Test
  73. public void testGetLastWord(){
  74. // Given
  75. String sentence = "I'm sorry for what I said when I was hungry";
  76. String expected = "hungry";
  77. // When
  78. String actual = utilities.getLastWord(sentence);
  79. // Then
  80. assertEquals(expected, actual);
  81. }
  82. }