remove code from evaluation article
This commit is contained in:
parent
94fc522f7f
commit
e76cf9ca26
@ -1,21 +0,0 @@
|
|||||||
package com.baeldung.configuration;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import com.baeldung.model.College;
|
|
||||||
import com.baeldung.model.Student;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class ConstructorConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Student student() {
|
|
||||||
return new Student(1, "John", college());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public College college() {
|
|
||||||
return new College(1, "New York");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package com.baeldung.configuration;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import com.baeldung.model.College;
|
|
||||||
import com.baeldung.model.Student;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class SetterConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Student student() {
|
|
||||||
Student student = new Student();
|
|
||||||
student.setId(2);
|
|
||||||
student.setName("Tom");
|
|
||||||
student.setCollege(college());
|
|
||||||
return student;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public College college() {
|
|
||||||
College college = new College();
|
|
||||||
college.setId(2);
|
|
||||||
college.setName("Pittsburgh");
|
|
||||||
return college;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package com.baeldung.model;
|
|
||||||
|
|
||||||
public class College {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public College() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public College(int id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package com.baeldung.model;
|
|
||||||
|
|
||||||
public class Student {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private String name;
|
|
||||||
private College college;
|
|
||||||
|
|
||||||
public Student() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Student(int id, String name, College college) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.college = college;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public College getCollege() {
|
|
||||||
return college;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollege(College college) {
|
|
||||||
this.college = college;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void introduceMyself() {
|
|
||||||
System.out.println("My ID is " + id + " and my name is " + name + ". I am a student at " + college.getName() + " College.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package com.baeldung.configuration;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
|
|
||||||
import com.baeldung.model.Student;
|
|
||||||
|
|
||||||
public class ConstructorConfigTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenContextLoaded_thenDependencyInjected() {
|
|
||||||
ApplicationContext context = new AnnotationConfigApplicationContext(ConstructorConfig.class);
|
|
||||||
Student student = context.getBean(Student.class);
|
|
||||||
assertEquals(1, student.getId());
|
|
||||||
assertEquals("John", student.getName());
|
|
||||||
assertEquals(1, student.getCollege().getId());
|
|
||||||
assertEquals("New York", student.getCollege().getName());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package com.baeldung.configuration;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
|
|
||||||
import com.baeldung.model.Student;
|
|
||||||
|
|
||||||
public class SetterConfigTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenContextLoaded_thenDependencyInjected() {
|
|
||||||
ApplicationContext context = new AnnotationConfigApplicationContext(SetterConfig.class);
|
|
||||||
Student student = context.getBean(Student.class);
|
|
||||||
assertEquals(2, student.getId());
|
|
||||||
assertEquals("Tom", student.getName());
|
|
||||||
assertEquals(2, student.getCollege().getId());
|
|
||||||
assertEquals("Pittsburgh", student.getCollege().getName());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user