BAEL-833: How to get last element of a Stream in Java? (#1930)
* Different Types of Bean Injection in Spring * Fixed code formatting and test names for "Different Types of Bean Injection in Spring" * BAEL-833: How to get last element of a Stream in Java? * BAEL-833: Updated based on review from editor
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
99c7a91587
commit
8c8c01ebbb
@@ -0,0 +1,24 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user