Просмотр исходного кода

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

FridaTveit 9 лет назад
Родитель
Сommit
675ca677d7

+ 0
- 1
exercises/grade-school/build.gradle Просмотреть файл

@@ -8,7 +8,6 @@ repositories {
8 8
 
9 9
 dependencies {
10 10
   testCompile "junit:junit:4.12"
11
-  testCompile "org.assertj:assertj-core:3.2.0"
12 11
 }
13 12
 test {
14 13
   testLogging {

+ 17
- 13
exercises/grade-school/src/test/java/SchoolTest.java Просмотреть файл

@@ -1,27 +1,28 @@
1
-import static org.assertj.core.api.Assertions.assertThat;
2
-
3
-import org.junit.Test;
4 1
 import org.junit.Ignore;
2
+import org.junit.Test;
5 3
 
6 4
 import java.util.Arrays;
7 5
 import java.util.HashMap;
8 6
 import java.util.List;
9 7
 import java.util.Map;
10 8
 
9
+import static org.hamcrest.CoreMatchers.*;
10
+import static org.junit.Assert.*;
11
+
11 12
 public class SchoolTest {
12 13
   private final School school = new School();
13 14
 
14 15
 
15 16
   @Test
16 17
   public void startsWithNoStudents() {
17
-    assertThat(school.db()).isEmpty();
18
+    assertTrue(school.db().isEmpty());
18 19
   }
19 20
 
20 21
   @Ignore
21 22
   @Test
22 23
   public void addsStudents() {
23 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 28
   @Ignore
@@ -32,7 +33,8 @@ public class SchoolTest {
32 33
     school.add("Blair", grade);
33 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 40
   @Ignore
@@ -41,9 +43,11 @@ public class SchoolTest {
41 43
     school.add("Chelsea", 3);
42 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 53
   @Ignore
@@ -52,13 +56,14 @@ public class SchoolTest {
52 56
     school.add("Franklin", 5);
53 57
     school.add("Bradley", 5);
54 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 63
   @Ignore
59 64
   @Test
60 65
   public void getsStudentsInEmptyGrade() {
61
-    assertThat(school.grade(1)).isEmpty();
66
+    assertTrue(school.grade(1).isEmpty());
62 67
   }
63 68
 
64 69
   @Ignore
@@ -72,7 +77,6 @@ public class SchoolTest {
72 77
     sortedStudents.put(6, Arrays.asList("Kareem"));
73 78
     sortedStudents.put(4, Arrays.asList("Christopher", "Jennifer"));
74 79
     sortedStudents.put(3, Arrays.asList("Kyle"));
75
-
76
-    assertThat(school.sort()).isEqualTo(sortedStudents);
80
+    assertEquals(school.sort(), sortedStudents);
77 81
   }
78 82
 }