Radu/bael 1265 junit updates (#2965)
* Code for test article: Different Types of Bean Injection in Spring * Adding jUnits for test article: Different Types of Bean Injection in Spring * BAEL-1265: Adding jUnit for article * BAEL-1265: Closing ExecutorService in jUnit * BAEL-1265: Adding jUnit for CountDownLatch and example for ExecutorService.awaitTermination
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.dependencyinjectiontypes;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class ArticleFormatter {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("dependencyinjectiontypes-context.xml");
|
||||
ArticleWithSetterInjection article = (ArticleWithSetterInjection) context.getBean("articleWithSetterInjectionBean");
|
||||
String formattedArticle = article.format("This is a text !");
|
||||
|
||||
System.out.print(formattedArticle);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.dependencyinjectiontypes;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class ArticleWithConstructorInjection {
|
||||
|
||||
private TextFormatter formatter;
|
||||
|
||||
@Autowired
|
||||
public ArticleWithConstructorInjection(TextFormatter formatter) {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
public String format(String text) {
|
||||
return formatter.format(text);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.dependencyinjectiontypes;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class ArticleWithSetterInjection {
|
||||
|
||||
private TextFormatter formatter;
|
||||
|
||||
public ArticleWithSetterInjection(TextFormatter formatter) {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTextFormatter(TextFormatter formatter) {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
|
||||
public String format(String text) {
|
||||
return formatter.format(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.dependencyinjectiontypes;
|
||||
|
||||
public class TextFormatter {
|
||||
|
||||
public String format(String text) {
|
||||
return text.toUpperCase();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
<bean id="articleWithSetterInjectionBean"
|
||||
class="com.baeldung.dependencyinjectiontypes.ArticleWithSetterInjection">
|
||||
<constructor-arg ref="textFormatterBean" />
|
||||
</bean>
|
||||
|
||||
<bean id="articleWithConstructorInjectionBean"
|
||||
class="com.baeldung.dependencyinjectiontypes.ArticleWithConstructorInjection">
|
||||
<constructor-arg ref="textFormatterBean" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="textFormatterBean" class="com.baeldung.dependencyinjectiontypes.TextFormatter">
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user