FizzBuzzTest.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 FizzBuzzTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class FizzBuzzTest
  12. {
  13. /**
  14. * Default constructor for test class FizzBuzzTest
  15. */
  16. public FizzBuzzTest()
  17. {
  18. }
  19. private FizzBuzz fizzBuzz;
  20. /**
  21. * Sets up the test fixture.
  22. *
  23. * Called before every test case method.
  24. */
  25. @Before
  26. public void setup() {
  27. fizzBuzz = new FizzBuzz();
  28. }
  29. @Test
  30. public void fizzTest1() {
  31. //given
  32. String expected = "Fizz";
  33. //when
  34. String actual = fizzBuzz.result(3);
  35. //then
  36. assertEquals(expected, actual);
  37. }
  38. @Test
  39. public void fizzTest2() {
  40. //given
  41. String expected = "Fizz";
  42. //when
  43. String actual = fizzBuzz.result(9);
  44. //then
  45. assertEquals(expected, actual);
  46. }
  47. @Test
  48. public void buzzTest1() {
  49. //given
  50. String expected = "Buzz";
  51. //when
  52. String actual = fizzBuzz.result(5);
  53. //then
  54. assertEquals(expected, actual);
  55. }
  56. @Test
  57. public void buzzTest2() {
  58. //given
  59. String expected = "Buzz";
  60. //when
  61. String actual = fizzBuzz.result(20);
  62. //then
  63. assertEquals(expected, actual);
  64. }
  65. @Test
  66. public void fizzBuzzTest1() {
  67. //given
  68. String expected = "FizzBuzz";
  69. //when
  70. String actual = fizzBuzz.result(15);
  71. //then
  72. assertEquals(expected, actual);
  73. }
  74. @Test
  75. public void fizzBuzzTest2() {
  76. //given
  77. String expected = "FizzBuzz";
  78. //when
  79. String actual = fizzBuzz.result(30);
  80. //then
  81. assertEquals(expected, actual);
  82. }
  83. @Test
  84. public void numberTest() {
  85. //given
  86. String expected = "11";
  87. //when
  88. String actual = fizzBuzz.result(11);
  89. //then
  90. assertEquals(expected, actual);
  91. }
  92. }