瀏覽代碼

Issue #195: Changed assertj assertions to junit and hamcrest assertions in grade-school. Removed assertj from grade-school gradle build file. (#211)

FridaTveit 9 年之前
父節點
當前提交
675ca677d7
共有 2 個檔案被更改,包括 17 行新增14 行删除
  1. 0
    1
      exercises/grade-school/build.gradle
  2. 17
    13
      exercises/grade-school/src/test/java/SchoolTest.java

+ 0
- 1
exercises/grade-school/build.gradle 查看文件

8
 
8
 
9
 dependencies {
9
 dependencies {
10
   testCompile "junit:junit:4.12"
10
   testCompile "junit:junit:4.12"
11
-  testCompile "org.assertj:assertj-core:3.2.0"
12
 }
11
 }
13
 test {
12
 test {
14
   testLogging {
13
   testLogging {

+ 17
- 13
exercises/grade-school/src/test/java/SchoolTest.java 查看文件

1
-import static org.assertj.core.api.Assertions.assertThat;
2
-
3
-import org.junit.Test;
4
 import org.junit.Ignore;
1
 import org.junit.Ignore;
2
+import org.junit.Test;
5
 
3
 
6
 import java.util.Arrays;
4
 import java.util.Arrays;
7
 import java.util.HashMap;
5
 import java.util.HashMap;
8
 import java.util.List;
6
 import java.util.List;
9
 import java.util.Map;
7
 import java.util.Map;
10
 
8
 
9
+import static org.hamcrest.CoreMatchers.*;
10
+import static org.junit.Assert.*;
11
+
11
 public class SchoolTest {
12
 public class SchoolTest {
12
   private final School school = new School();
13
   private final School school = new School();
13
 
14
 
14
 
15
 
15
   @Test
16
   @Test
16
   public void startsWithNoStudents() {
17
   public void startsWithNoStudents() {
17
-    assertThat(school.db()).isEmpty();
18
+    assertTrue(school.db().isEmpty());
18
   }
19
   }
19
 
20
 
20
   @Ignore
21
   @Ignore
21
   @Test
22
   @Test
22
   public void addsStudents() {
23
   public void addsStudents() {
23
     school.add("Aimee", 2);
24
     school.add("Aimee", 2);
24
-    assertThat(school.db().get(2)).contains("Aimee");
25
+    assertThat(school.db().get(2), hasItem("Aimee"));
25
   }
26
   }
26
 
27
 
27
   @Ignore
28
   @Ignore
32
     school.add("Blair", grade);
33
     school.add("Blair", grade);
33
     school.add("Paul", grade);
34
     school.add("Paul", grade);
34
 
35
 
35
-    assertThat(school.db().get(grade)).hasSize(3).contains("James", "Blair", "Paul");
36
+    assertThat(school.db().get(grade).size(), is(3));
37
+    assertThat(school.db().get(grade), allOf(hasItem("James"), hasItem("Blair"), hasItem("Paul")));
36
   }
38
   }
37
 
39
 
38
   @Ignore
40
   @Ignore
41
     school.add("Chelsea", 3);
43
     school.add("Chelsea", 3);
42
     school.add("Logan", 7);
44
     school.add("Logan", 7);
43
 
45
 
44
-    assertThat(school.db()).hasSize(2);
45
-    assertThat(school.db().get(3)).hasSize(1).contains("Chelsea");
46
-    assertThat(school.db().get(7)).hasSize(1).contains("Logan");
46
+    assertThat(school.db().size(), is(2));
47
+    assertThat(school.db().get(3).size(), is(1));
48
+    assertThat(school.db().get(3), hasItem("Chelsea"));
49
+    assertThat(school.db().get(7).size(), is(1));
50
+    assertThat(school.db().get(7), hasItem("Logan"));
47
   }
51
   }
48
 
52
 
49
   @Ignore
53
   @Ignore
52
     school.add("Franklin", 5);
56
     school.add("Franklin", 5);
53
     school.add("Bradley", 5);
57
     school.add("Bradley", 5);
54
     school.add("Jeff", 1);
58
     school.add("Jeff", 1);
55
-    assertThat(school.grade(5)).hasSize(2).contains("Franklin", "Bradley");
59
+    assertThat(school.grade(5).size(), is(2));
60
+    assertThat(school.grade(5), allOf(hasItem("Franklin"), hasItem("Bradley")));
56
   }
61
   }
57
 
62
 
58
   @Ignore
63
   @Ignore
59
   @Test
64
   @Test
60
   public void getsStudentsInEmptyGrade() {
65
   public void getsStudentsInEmptyGrade() {
61
-    assertThat(school.grade(1)).isEmpty();
66
+    assertTrue(school.grade(1).isEmpty());
62
   }
67
   }
63
 
68
 
64
   @Ignore
69
   @Ignore
72
     sortedStudents.put(6, Arrays.asList("Kareem"));
77
     sortedStudents.put(6, Arrays.asList("Kareem"));
73
     sortedStudents.put(4, Arrays.asList("Christopher", "Jennifer"));
78
     sortedStudents.put(4, Arrays.asList("Christopher", "Jennifer"));
74
     sortedStudents.put(3, Arrays.asList("Kyle"));
79
     sortedStudents.put(3, Arrays.asList("Kyle"));
75
-
76
-    assertThat(school.sort()).isEqualTo(sortedStudents);
80
+    assertEquals(school.sort(), sortedStudents);
77
   }
81
   }
78
 }
82
 }