From 3def35e3eb1a6a90d0bff7d06b3365d539c1c418 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 11 Jun 2017 10:53:01 +0200 Subject: [PATCH] Remove bean injection code (#2043) --- .../BeanInjectionApplication.java | 12 ----- .../config/StorageProperties.java | 30 ------------ .../service/FileSystemStorageService.java | 29 ------------ .../service/NetworkStorageService.java | 31 ------------ .../BeanInjectionApplicationTests.java | 17 ------- .../beaninjection/BeanInjectionUnitTests.java | 47 ------------------- 6 files changed, 166 deletions(-) delete mode 100644 spring-aop/src/main/java/com/baeldung/beaninjection/BeanInjectionApplication.java delete mode 100644 spring-aop/src/main/java/com/baeldung/beaninjection/config/StorageProperties.java delete mode 100644 spring-aop/src/main/java/com/baeldung/beaninjection/service/FileSystemStorageService.java delete mode 100644 spring-aop/src/main/java/com/baeldung/beaninjection/service/NetworkStorageService.java delete mode 100644 spring-aop/src/test/java/com/baeldung/beaninjection/BeanInjectionApplicationTests.java delete mode 100644 spring-aop/src/test/java/com/baeldung/beaninjection/BeanInjectionUnitTests.java diff --git a/spring-aop/src/main/java/com/baeldung/beaninjection/BeanInjectionApplication.java b/spring-aop/src/main/java/com/baeldung/beaninjection/BeanInjectionApplication.java deleted file mode 100644 index c8e228c6f2..0000000000 --- a/spring-aop/src/main/java/com/baeldung/beaninjection/BeanInjectionApplication.java +++ /dev/null @@ -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); - } -} diff --git a/spring-aop/src/main/java/com/baeldung/beaninjection/config/StorageProperties.java b/spring-aop/src/main/java/com/baeldung/beaninjection/config/StorageProperties.java deleted file mode 100644 index 18f7d36378..0000000000 --- a/spring-aop/src/main/java/com/baeldung/beaninjection/config/StorageProperties.java +++ /dev/null @@ -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; - } - - -} diff --git a/spring-aop/src/main/java/com/baeldung/beaninjection/service/FileSystemStorageService.java b/spring-aop/src/main/java/com/baeldung/beaninjection/service/FileSystemStorageService.java deleted file mode 100644 index d2530d5a2d..0000000000 --- a/spring-aop/src/main/java/com/baeldung/beaninjection/service/FileSystemStorageService.java +++ /dev/null @@ -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(); - } -} diff --git a/spring-aop/src/main/java/com/baeldung/beaninjection/service/NetworkStorageService.java b/spring-aop/src/main/java/com/baeldung/beaninjection/service/NetworkStorageService.java deleted file mode 100644 index 0720ba153e..0000000000 --- a/spring-aop/src/main/java/com/baeldung/beaninjection/service/NetworkStorageService.java +++ /dev/null @@ -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(); - } - -} diff --git a/spring-aop/src/test/java/com/baeldung/beaninjection/BeanInjectionApplicationTests.java b/spring-aop/src/test/java/com/baeldung/beaninjection/BeanInjectionApplicationTests.java deleted file mode 100644 index d508975481..0000000000 --- a/spring-aop/src/test/java/com/baeldung/beaninjection/BeanInjectionApplicationTests.java +++ /dev/null @@ -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() { - } - - -} diff --git a/spring-aop/src/test/java/com/baeldung/beaninjection/BeanInjectionUnitTests.java b/spring-aop/src/test/java/com/baeldung/beaninjection/BeanInjectionUnitTests.java deleted file mode 100644 index fe1d224bc4..0000000000 --- a/spring-aop/src/test/java/com/baeldung/beaninjection/BeanInjectionUnitTests.java +++ /dev/null @@ -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()); - } - -}