Remove bean injection code (#2043)
This commit is contained in:
parent
dc43aec4d3
commit
3def35e3eb
|
@ -1,12 +0,0 @@
|
|||
package com.baeldung.beaninjection;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class BeanInjectionApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BeanInjectionApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.baeldung.beaninjection.config;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Created by smatt on 12/05/2017.
|
||||
*/
|
||||
@Configuration
|
||||
public class StorageProperties {
|
||||
/**
|
||||
* Folder location for storing files
|
||||
*/
|
||||
|
||||
Logger logger = Logger.getLogger(StorageProperties.class);
|
||||
|
||||
private String location = "upload-dir";
|
||||
|
||||
public StorageProperties() {}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.baeldung.beaninjection.service;
|
||||
|
||||
import com.baeldung.beaninjection.config.StorageProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Created by smatt on 12/05/2017.
|
||||
*/
|
||||
@Service
|
||||
public class FileSystemStorageService {
|
||||
|
||||
StorageProperties storageProperties;
|
||||
|
||||
@Autowired
|
||||
public FileSystemStorageService(StorageProperties storageProperties) {
|
||||
this.storageProperties = storageProperties;
|
||||
}
|
||||
|
||||
//this is for test purpose
|
||||
public StorageProperties getStorageProperties() {
|
||||
return storageProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FileSystemStorageService: Storage Location = " + storageProperties.getLocation();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package com.baeldung.beaninjection.service;
|
||||
|
||||
import com.baeldung.beaninjection.config.StorageProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Created by smatt on 12/05/2017.
|
||||
*/
|
||||
@Service
|
||||
public class NetworkStorageService {
|
||||
|
||||
StorageProperties storageProperties;
|
||||
|
||||
public NetworkStorageService() {}
|
||||
|
||||
@Autowired
|
||||
public void setStorageProperties(StorageProperties storageProperties) {
|
||||
this.storageProperties = storageProperties;
|
||||
}
|
||||
|
||||
public StorageProperties getStorageProperties() {
|
||||
return storageProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NetworkStorageService: Storage Location = " + storageProperties.getLocation();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.baeldung.beaninjection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class BeanInjectionApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package com.baeldung.beaninjection;
|
||||
|
||||
import com.baeldung.beaninjection.service.FileSystemStorageService;
|
||||
import com.baeldung.beaninjection.service.NetworkStorageService;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Created by smatt on 13/05/2017.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class BeanInjectionUnitTests {
|
||||
|
||||
@Autowired
|
||||
NetworkStorageService networkStorageService;
|
||||
|
||||
@Autowired
|
||||
FileSystemStorageService fileSystemStorageService;
|
||||
|
||||
Logger logger = Logger.getLogger(BeanInjectionApplicationTests.class);
|
||||
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAutowiredOnClassConstructor_whenInstantiatingAndCallingGetter_thenDependencyShouldResolve() {
|
||||
Assert.assertNotNull("FileSystemStorageService not autowired in test class", fileSystemStorageService);
|
||||
Assert.assertNotNull("StorageProperties not autowired in FileSystemStorageService", fileSystemStorageService.getStorageProperties());
|
||||
logger.info(fileSystemStorageService.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAutowiredOnClassSetter_whenInstantiatingAndCallingGetter_thenDependencyShouldResolve() {
|
||||
Assert.assertNotNull("NetworkStorageService not autowired in test class", networkStorageService);
|
||||
Assert.assertNotNull("StorageProperties not autowired in NetworkStorageService", networkStorageService.getStorageProperties());
|
||||
logger.info(networkStorageService.toString());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue