Browse Source

Person

Learner
Student
Teacher
Instructor
People
Students
Instructors
Classroom
StudentConfig - noParam Constructors Used
- Added toString to People to run SpringBootApp
InstructorsConfig
ClassroomConfig
-- Test --
 StudentConfig
 InstructorsConfig
 ClassroomConfig
Nick Satinover 6 years ago
parent
commit
a2ba560465

+ 4
- 1
demo/src/main/java/com/example/demo/ClassroomConfig.java View File

@@ -1,8 +1,11 @@
1 1
 package com.example.demo;
2 2
 
3 3
 import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
4 5
 import org.springframework.context.annotation.DependsOn;
5 6
 
7
+@Configuration
8
+@DependsOn({"students", "previousStudents", "tcUsaInstructors", "tcUkInstructors", "instructors"})
6 9
 public class ClassroomConfig {
7 10
 
8 11
     @Bean(name = "currentCohort")
@@ -12,7 +15,7 @@ public class ClassroomConfig {
12 15
     }
13 16
 
14 17
     @Bean(name = "previousCohort")
15
-    @DependsOn({"previousInstructors", "previousStudents"})
18
+    @DependsOn({"instructors", "previousStudents"})
16 19
     public Classroom previousCohort(Instructors previousInstructors, Students previousStudents){
17 20
         return new Classroom(previousInstructors, previousStudents);
18 21
     }

+ 3
- 3
demo/src/main/java/com/example/demo/DemoApplication.java View File

@@ -4,6 +4,7 @@ import org.apache.catalina.core.ApplicationContext;
4 4
 import org.springframework.boot.SpringApplication;
5 5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
6 6
 import org.springframework.context.ConfigurableApplicationContext;
7
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
7 8
 import org.springframework.context.support.ClassPathXmlApplicationContext;
8 9
 
9 10
 
@@ -13,9 +14,8 @@ public class DemoApplication {
13 14
 	public static void main(String[] args) {
14 15
 		ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
15 16
 		// SpringApplication.run(DemoApplication.class, args);
16
-
17
-//        Students students = new Students();
18
-//        System.out.println(students.toString());
17
+        //        Students students = new Students();
18
+        //        System.out.println(students.toString());
19 19
 
20 20
 
21 21
 

+ 3
- 6
demo/src/main/java/com/example/demo/InstructorsConfig.java View File

@@ -3,6 +3,7 @@ package com.example.demo;
3 3
 import org.springframework.beans.factory.annotation.Qualifier;
4 4
 import org.springframework.context.annotation.Bean;
5 5
 import org.springframework.context.annotation.Configuration;
6
+import org.springframework.context.annotation.DependsOn;
6 7
 import org.springframework.context.annotation.Primary;
7 8
 import org.springframework.stereotype.Component;
8 9
 import java.util.ArrayList;
@@ -35,14 +36,10 @@ public class InstructorsConfig {
35 36
     }
36 37
 
37 38
     @Bean(name = "instructors")
39
+    @DependsOn({"tcUsaInstructors", "tcUkInstructors"})
38 40
     @Primary
39 41
     public Instructors instructors(){
40
-        Instructors allInstructors = new Instructors();
41
-
42
-        allInstructors.addAll(tcUsaInstructors());
43
-        allInstructors.addAll(tcUkInstructors());
44
-
45
-        return allInstructors;
42
+        return new Instructors();
46 43
     }
47 44
 
48 45
 

demo/src/main/java/com/example/demo/StudentConfig.java → demo/src/main/java/com/example/demo/StudentsConfig.java View File

@@ -9,11 +9,11 @@ import org.springframework.stereotype.Component;
9 9
 import java.util.ArrayList;
10 10
 
11 11
 @Configuration
12
-public class StudentConfig {
12
+public class StudentsConfig {
13 13
 
14 14
     @Bean(name = "students")
15
-    //@Qualifier("currentStudents")
16
-    public Students currentStudents(){
15
+    //@Qualifier("tudents")
16
+    public Students students(){
17 17
         ArrayList<Student> currentStudents = new ArrayList<>();
18 18
         
19 19
         currentStudents.add(new Student(1, "Ned Redmond"));

+ 56
- 0
demo/src/test/java/com/example/demo/TestClassroomConfig.java View File

@@ -0,0 +1,56 @@
1
+package com.example.demo;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import org.junit.runner.RunWith;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.boot.test.context.SpringBootTest;
9
+import org.springframework.test.context.junit4.SpringRunner;
10
+
11
+@RunWith(SpringRunner.class)
12
+@SpringBootTest
13
+public class TestClassroomConfig {
14
+    private Classroom currentCohort;
15
+    private Classroom previousCohort;
16
+
17
+    @Autowired
18
+    private ClassroomConfig classroomConfig;
19
+    @Autowired
20
+    private StudentsConfig studentsConfig;
21
+    @Autowired
22
+    private InstructorsConfig instructorsConfig;
23
+
24
+    @Before
25
+    public void setUp() {
26
+        currentCohort = classroomConfig.currentCohort(
27
+                    instructorsConfig.instructors(),
28
+                    studentsConfig.students()
29
+        );
30
+        previousCohort = classroomConfig.previousCohort(
31
+                instructorsConfig.instructors(),
32
+                studentsConfig.previousStudents()
33
+        );
34
+    }
35
+
36
+    @Test
37
+    public void testCurrentCohort() {
38
+        Assert.assertEquals(currentCohort, classroomConfig.currentCohort(
39
+                instructorsConfig.instructors(), studentsConfig.students()
40
+        ));
41
+        Assert.assertNotEquals(currentCohort, classroomConfig.previousCohort(
42
+                instructorsConfig.instructors(), studentsConfig.previousStudents()
43
+        ));
44
+    }
45
+
46
+    @Test
47
+    public void testPreviousCohort() {
48
+        Assert.assertEquals(previousCohort, classroomConfig.previousCohort(
49
+                instructorsConfig.instructors(), studentsConfig.previousStudents()
50
+        ));
51
+        Assert.assertNotEquals(previousCohort, classroomConfig.currentCohort(
52
+                instructorsConfig.instructors(), studentsConfig.students()
53
+        ));
54
+    }
55
+
56
+}

+ 48
- 0
demo/src/test/java/com/example/demo/TestInstructorConfig.java View File

@@ -0,0 +1,48 @@
1
+package com.example.demo;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import org.junit.runner.RunWith;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.boot.test.context.SpringBootTest;
9
+import org.springframework.test.context.junit4.SpringRunner;
10
+
11
+@RunWith(SpringRunner.class)
12
+@SpringBootTest
13
+public class TestInstructorConfig {
14
+    private Instructors tcUsaInstructors;
15
+    private Instructors tcUkInstructors;
16
+    private Instructors instructors;
17
+
18
+    @Autowired
19
+    private InstructorsConfig instructorsConfig;
20
+
21
+    @Before
22
+    public void setUp(){
23
+        tcUsaInstructors = instructorsConfig.tcUsaInstructors();
24
+        tcUkInstructors = instructorsConfig.tcUkInstructors();
25
+        instructors = instructorsConfig.instructors();
26
+    }
27
+
28
+    @Test
29
+    public void testGetTcUsaInstructors() {
30
+        Assert.assertEquals(tcUsaInstructors, instructorsConfig.tcUsaInstructors());
31
+        Assert.assertNotEquals(tcUsaInstructors, instructorsConfig.tcUkInstructors());
32
+        Assert.assertNotEquals(tcUsaInstructors, instructorsConfig.instructors());
33
+    }
34
+
35
+    @Test
36
+    public void testGetTcUkInstructors() {
37
+        Assert.assertEquals(tcUkInstructors, instructorsConfig.tcUkInstructors());
38
+        Assert.assertNotEquals(tcUkInstructors, instructorsConfig.tcUsaInstructors());
39
+        Assert.assertNotEquals(tcUkInstructors, instructorsConfig.instructors());
40
+    }
41
+
42
+    @Test
43
+    public void testGetInstructors() {
44
+        Assert.assertEquals(instructors, instructorsConfig.instructors());
45
+        Assert.assertNotEquals(instructors, instructorsConfig.tcUsaInstructors());
46
+        Assert.assertNotEquals(instructors, instructorsConfig.tcUkInstructors());
47
+    }
48
+}

+ 38
- 0
demo/src/test/java/com/example/demo/TestStudentsConfig.java View File

@@ -0,0 +1,38 @@
1
+package com.example.demo;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import org.junit.runner.RunWith;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.boot.test.context.SpringBootTest;
9
+import org.springframework.test.context.junit4.SpringRunner;
10
+
11
+@RunWith(SpringRunner.class)
12
+@SpringBootTest
13
+public class TestStudentsConfig {
14
+    private Students students;
15
+    private Students previousStudents;
16
+
17
+    @Autowired
18
+    private StudentsConfig studentsConfig;
19
+
20
+    @Before
21
+    public void setUp() {
22
+      students = studentsConfig.students();
23
+      previousStudents = studentsConfig.previousStudents();
24
+    }
25
+
26
+    @Test
27
+    public void testStudents(){
28
+        Assert.assertEquals(students, studentsConfig.students());
29
+        Assert.assertNotEquals(students, studentsConfig.previousStudents());
30
+    }
31
+
32
+    @Test
33
+    public void testPreviousStudents(){
34
+        Assert.assertEquals(previousStudents, studentsConfig.previousStudents());
35
+        Assert.assertNotEquals(previousStudents, studentsConfig.students());
36
+    }
37
+
38
+}