Stream API: last Stream element example refactor (#1943)

* Refactor

* Delete ApplicationContextTestBeanInjectionTypes.java

* Delete BeanInjectionJavaConfigIntegrationTest.java

* Delete BeanInjectionXMLConfigIntegrationTest.java
This commit is contained in:
Grzegorz Piwowarek
2017-06-03 20:49:56 +02:00
committed by GitHub
parent b840f15629
commit a5d5460a9f
22 changed files with 11 additions and 531 deletions
@@ -1,24 +0,0 @@
package com.baeldung.beaninjection;
import static org.junit.Assert.assertNotNull;
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;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = ReaderApplicationConfig.class)
public class FileReaderTest {
@Autowired
private ApplicationContext context;
@Test
public void testAutowiredAnnotation_WhenField_ThenInjected() {
FileReader service = context.getBean(FileReader.class);
assertNotNull(service.getLocation());
}
}
@@ -1,25 +0,0 @@
package com.baeldung.beaninjection;
import static org.junit.Assert.assertNotNull;
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;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:injectiontypes.xml")
public class FtpReaderTest {
@Autowired
private ApplicationContext context;
@Test
public void testXMLBeanConfig_WhenConstructorArguments_ThenInjected() {
FtpReader service = context.getBean(FtpReader.class);
assertNotNull(service.getFtpHost());
assertNotNull(service.getFtpPort());
}
}
@@ -1,25 +0,0 @@
package com.baeldung.beaninjection;
import static org.junit.Assert.assertNotNull;
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;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = ReaderApplicationConfig.class)
public class ReaderManagerTest {
@Autowired
private ApplicationContext context;
@Test
public void testAutowiredAnnotation_WhenConstructorAndSetter_ThenInjected() {
ReaderManager service = context.getBean(ReaderManager.class);
assertNotNull(service.getFtpReader());
assertNotNull(service.getFileReader());
}
}
@@ -1,24 +0,0 @@
package com.baeldung.beaninjection;
import static org.junit.Assert.assertNotNull;
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;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:injectiontypes.xml")
public class ReaderServiceTest {
@Autowired
private ApplicationContext context;
@Test
public void testXMLBeanConfig_WhenSetter_ThenInjected() {
ReaderService service = context.getBean(ReaderService.class);
assertNotNull(service.getFtpReader());
}
}
@@ -1,50 +0,0 @@
package com.baeldung.test.beaninjection;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.beaninjection.AnotherSampleDAOBean;
import com.baeldung.beaninjection.ExampleDAOBean;
import com.baeldung.beaninjection.ExampleServiceBean;
import com.baeldung.configuration.ApplicationContextTestBeanInjectionTypes;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = ApplicationContextTestBeanInjectionTypes.class)
public class BeanInjectionJavaConfigIntegrationTest implements ApplicationContextAware {
private ApplicationContext beanInjectedContext;
@Test
public void testDAOInjectionByJava() {
ExampleServiceBean serviceBean = beanInjectedContext.getBean(ExampleServiceBean.class);
assertNotNull("Failed: Constructor Injection,Bean Reference Injection,Java Config, ExampleServiceBean", serviceBean.getExampleDAO());
assertNotNull("Failed: Constructor Injection,Bean Reference Injection,Java Config, ExampleServiceBean", serviceBean.getAnotherSampleDAO());
assertTrue("Failed: Constructor Injection,String Property , Java Config", serviceBean.getPropertyX()
.equals("Some Service Property X"));
}
@Test
public void testPropertyInjectioninDAOByJava() {
ExampleDAOBean daoBean = beanInjectedContext.getBean(ExampleDAOBean.class);
assertTrue("Failed: Constructor Injection,String Property , Java Config", daoBean.getPropertyX()
.equals("Mandatory DAO Property X"));
AnotherSampleDAOBean anotherDAOBean = beanInjectedContext.getBean(AnotherSampleDAOBean.class);
assertTrue("Failed: Constructor Injection,String Property , XML Config", anotherDAOBean.getPropertyY()
.equals("Mandatory DAO Property Y"));
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
// TODO Auto-generated method stub
this.beanInjectedContext = applicationContext;
}
}
@@ -1,49 +0,0 @@
package com.baeldung.test.beaninjection;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.beaninjection.AnotherSampleDAOBean;
import com.baeldung.beaninjection.ExampleDAOBean;
import com.baeldung.beaninjection.ExampleServiceBean;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:beaninjectiontypes-context.xml")
public class BeanInjectionXMLConfigIntegrationTest implements ApplicationContextAware {
private ApplicationContext beanInjectedContext;
@Test
public void testDAOInjectionByXML() {
ExampleServiceBean serviceBean = beanInjectedContext.getBean(ExampleServiceBean.class);
assertNotNull("Failed: Constructor Injection,Bean Reference Injection,XML Config, ExampleServiceBean", serviceBean.getExampleDAO());
assertNotNull("Failed: Constructor Injection,Bean Reference Injection,XML Config, ExampleServiceBean", serviceBean.getAnotherSampleDAO());
assertTrue("Failed: Constructor Injection,String Property , XML Config", serviceBean.getPropertyX()
.equals("Some Service Property X"));
}
@Test
public void testPropertyInjectioninDAOByXML() {
ExampleDAOBean daoBean = beanInjectedContext.getBean(ExampleDAOBean.class);
assertTrue("Failed: Constructor Injection,String Property , XML Config", daoBean.getPropertyX()
.equals("Mandatory DAO Property X"));
AnotherSampleDAOBean anotherDAOBean = beanInjectedContext.getBean(AnotherSampleDAOBean.class);
assertTrue("Failed: Constructor Injection,String Property , XML Config", anotherDAOBean.getPropertyY()
.equals("Mandatory DAO Property Y"));
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
// TODO Auto-generated method stub
this.beanInjectedContext = applicationContext;
}
}