Revert "evaluation article, different types of bean injection. (#3511)" (#3719)

This reverts commit 54bd8a5cdd.
This commit is contained in:
Grzegorz Piwowarek 2018-02-24 21:32:29 +01:00 committed by GitHub
parent c404d78081
commit a6d3ddd38f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 142 deletions

View File

@ -1,21 +0,0 @@
package com.baeldung.dependencyinjectiontypes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Student {
private TeacherFinder teacherFinder;
@Autowired
public Student(TeacherFinder teacherFinder) {
this.teacherFinder = teacherFinder;
}
public String getTeacher() {
return teacherFinder.getTeacherFinder();
}
// business logic that actually uses the injected teacherFinders is omitted...
}

View File

@ -1,20 +0,0 @@
package com.baeldung.dependencyinjectiontypes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Student2 {
private TeacherFinder teacherFinder;
@Autowired
public void setTeacherFinder(TeacherFinder teacherFinder) {
this.teacherFinder = teacherFinder;
}
public String getTeacher() {
return teacherFinder.getTeacherFinder();
}
}

View File

@ -1,16 +0,0 @@
package com.baeldung.dependencyinjectiontypes;
public class TeacherFinder {
private String teacherFinder;
public String getTeacherFinder() {
return teacherFinder;
}
public void setTeacherFinder(String teacherFinder) {
this.teacherFinder = teacherFinder;
}
}

View File

@ -4,9 +4,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import com.baeldung.dependencyinjectiontypes.Student;
import com.baeldung.dependencyinjectiontypes.Student2;
import com.baeldung.dependencyinjectiontypes.TeacherFinder;
import com.baeldung.setterdi.domain.Engine;
import com.baeldung.setterdi.domain.Trailer;
import com.baeldung.setterdi.domain.Transmission;
@ -35,24 +32,4 @@ public class Config {
Trailer trailer = new Trailer();
return trailer;
}
@Bean
public TeacherFinder teacherFinder(){
TeacherFinder teacherFinder =new TeacherFinder();
teacherFinder.setTeacherFinder("author");
return teacherFinder;
}
@Bean
public Student student() {
return new Student(teacherFinder());
}
@Bean
public Student2 student2() {
Student2 student2 = new Student2();
student2.setTeacherFinder(teacherFinder());
return student2;
}
}

View File

@ -2,25 +2,13 @@ package com.baeldung.dependencyinjectiontypes;
import static org.junit.Assert.assertTrue;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=com.baeldung.setterdi.Config.class, loader=AnnotationConfigContextLoader.class)
public class DependencyInjectionTest {
@Autowired
private ApplicationContext appContext;
Logger logger = Logger.getLogger(this.getClass());
/* @Test
@Test
public void givenAutowiredAnnotation_WhenSetOnSetter_ThenDependencyValid() {
ApplicationContext context = new ClassPathXmlApplicationContext("dependencyinjectiontypes-context.xml");
@ -42,20 +30,6 @@ public class DependencyInjectionTest {
String formattedArticle = article.format(originalText);
assertTrue(originalText.toUpperCase().equals(formattedArticle));
}*/
@Test
public void givenAutowiredAnnotation_OnSetter_ThenDependencyValid() {
Student student = (Student) appContext.getBean("student");
String teacherFound = student.getTeacher();
assertTrue(teacherFound.equals("author"));
}
@Test
public void givenAutowiredAnnotation_OnConstructor_ThenDependencyValid() {
Student2 student2 = (Student2) appContext.getBean("student2");
String teacherFound = student2.getTeacher();
assertTrue(teacherFound.equals("author"));
}
}