-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFizzBuzzTest.java
More file actions
72 lines (65 loc) · 2.17 KB
/
FizzBuzzTest.java
File metadata and controls
72 lines (65 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* This is a small program that implements unit tests with JUnit
* Based on https://medium.com/@pelensky/java-tdd-with-junit-without-using-an-ide-cd24d38adff
* Requires JUnit JAR file on same directory
* Compile and run accordingly to the JUnit version
* Compile with javac -cp .:junit-4.10.jar FizzBuzzTest.java
* Run with java -cp .:junit-4.10.jar org.junit.runner.JUnitCore FizzBuzzTest
* Remember TDD: Test first, then code a little, test again, code more...
*
* Does not require to compile tested classes, only this
*/
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class FizzBuzzTest {
String dec = "\n*************************************************\n";
/*
* This method tests if FizzBuzz's getResult returns "1" given a 1
*/
@Test
public void testGetResult_returnOneIfGivenOne() {
FizzBuzz fb = new FizzBuzz();
String result = fb.getResult(1);
assertEquals(dec+"IT SHOULD RETURN \"1\"!!"+dec,"1",result);
}
/*
* This method tests if FizzBuzz's getResult returns "2" when given a 2
*/
@Test
public void testGetResult_returnTwoIfGivenTwo() {
FizzBuzz fb = new FizzBuzz();
String result = fb.getResult(2);
assertEquals(dec+"IT SHOULD RETURN \"2\"!!"+dec,"2",result);
}
/*
* This method tests if FizzBuzz's getResult returns "Fizz" when given a
* multiple of 3
*/
@Test
public void testGetResult_returnFizzIfGivenMultipleOfThree() {
FizzBuzz fb = new FizzBuzz();
String result = fb.getResult(3);
assertEquals(dec+"IT SHOULD RETURN \"Fizz\"!!"+dec,"Fizz",result);
}
/*
* This method tests if FizzBuzz's getResult returns "Buzz" when given a
* multiple of 5
*/
@Test
public void testGetResult_returnBuzzIfGivenMultipleOfFive() {
FizzBuzz fb = new FizzBuzz();
String result = fb.getResult(5);
assertEquals(dec+"IT SHOULD RETURN \"Buzz\"!!"+dec,"Buzz",result);
}
/*
* This method tests if FizzBuzz's getResult returns "FizzBuzz" when given a
* multiple of both 3 and 5
*/
@Test
public void testGetResult_returnBuzzIfGivenMultipleOfThreeAndFive() {
FizzBuzz fb = new FizzBuzz();
String result = fb.getResult(15);
assertEquals(dec+"IT SHOULD RETURN \"FizzBuzz\"!!"+dec,"FizzBuzz",
result);
}
}