remove unnecessary sample files
This commit is contained in:
parent
20b8dbffc4
commit
91dedcc9cb
@ -1,40 +0,0 @@
|
||||
package com.baeldung.samplebeaninjectionypes;
|
||||
|
||||
public class AccountDetails {
|
||||
|
||||
private Long accountNumber;
|
||||
|
||||
private String accountType;
|
||||
|
||||
private String accountName;
|
||||
|
||||
public AccountDetails(Long accountNumber, String accountType, String accountName) {
|
||||
this.accountNumber = accountNumber;
|
||||
this.accountType = accountType;
|
||||
this.accountName = accountName;
|
||||
}
|
||||
|
||||
public Long getAccountNumber() {
|
||||
return accountNumber;
|
||||
}
|
||||
|
||||
public void setAccountNumber(Long accountNumber) {
|
||||
this.accountNumber = accountNumber;
|
||||
}
|
||||
|
||||
public String getAccountType() {
|
||||
return accountType;
|
||||
}
|
||||
|
||||
public void setAccountType(String accountType) {
|
||||
this.accountType = accountType;
|
||||
}
|
||||
|
||||
public String getAccountName() {
|
||||
return accountName;
|
||||
}
|
||||
|
||||
public void setAccountName(String accountName) {
|
||||
this.accountName = accountName;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.baeldung.samplebeaninjectionypes;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class BankAccountApplication {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("samplebeaninjectiontypes-context.xml");
|
||||
BankAccountWithSetterInjection bankAccountWithSetterInjection = (BankAccountWithSetterInjection) context.getBean("bankAccountWithSetterInjectionBean");
|
||||
|
||||
bankAccountWithSetterInjection.openAccount(12345L,"Savings","John Doe");
|
||||
|
||||
BankAccountWithConstructorInjection bankAccountWithConstructorInjection = (BankAccountWithConstructorInjection) context.getBean("bankAccountWithConstructorInjectionBean");
|
||||
bankAccountWithSetterInjection.openAccount(12345L,"Savings","John Doe");
|
||||
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.baeldung.samplebeaninjectionypes;
|
||||
|
||||
public class BankAccountService {
|
||||
|
||||
public AccountDetails openAccount(Long accountNumber, String accountType, String owner) {
|
||||
AccountDetails accountDetails = new AccountDetails(accountNumber,accountType,owner);
|
||||
return accountDetails;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.baeldung.samplebeaninjectionypes;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class BankAccountWithConstructorInjection {
|
||||
private BankAccountService bankAccountService;
|
||||
|
||||
@Autowired
|
||||
public BankAccountWithConstructorInjection(BankAccountService service) {
|
||||
this.bankAccountService = service;
|
||||
}
|
||||
|
||||
public AccountDetails openAccount(Long accountNumber, String accountType, String owner) {
|
||||
return bankAccountService.openAccount(accountNumber, accountType, owner);
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.baeldung.samplebeaninjectionypes;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
public class BankAccountWithSetterInjection {
|
||||
|
||||
private BankAccountService bankAccountService;
|
||||
|
||||
public BankAccountWithSetterInjection(BankAccountService service) {
|
||||
this.bankAccountService = service;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setBankAccountService(BankAccountService bankAccountService) {
|
||||
this.bankAccountService = bankAccountService;
|
||||
}
|
||||
|
||||
public AccountDetails openAccount(Long accountNumber, String accountType, String owner) {
|
||||
return bankAccountService.openAccount(accountNumber, accountType, owner);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.baeldung.samplebeaninjectiontypes;
|
||||
|
||||
import com.baeldung.dependencyinjectiontypes.ArticleWithSetterInjection;
|
||||
import com.baeldung.samplebeaninjectionypes.AccountDetails;
|
||||
import com.baeldung.samplebeaninjectionypes.BankAccountWithConstructorInjection;
|
||||
import com.baeldung.samplebeaninjectionypes.BankAccountWithSetterInjection;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SampleBeanInjectionTest {
|
||||
ApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
context = new ClassPathXmlApplicationContext("dependencyinjectiontypes-context.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAutowiredAnnotation_WhenSetOnSetter_ThenDependencyValid() {
|
||||
|
||||
BankAccountWithSetterInjection bankAccountWithSetterInjection = (BankAccountWithSetterInjection) context.getBean("bankAccountWithSetterInjection");
|
||||
|
||||
String owner = "John Doe";
|
||||
AccountDetails accountDetails = bankAccountWithSetterInjection.openAccount(12345L,"Savings",owner);
|
||||
|
||||
assertTrue(accountDetails.getAccountName().equals(owner));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAutowiredAnnotation_WhenSetOnConstructor_ThenDependencyValid() {
|
||||
|
||||
BankAccountWithConstructorInjection bankAccountWithConstructorInjection = (BankAccountWithConstructorInjection) context.getBean("bankAccountWithConstructorInjectionBean");
|
||||
|
||||
String owner = "John Doe";
|
||||
AccountDetails accountDetails = bankAccountWithConstructorInjection.openAccount(12345L,"Savings",owner);
|
||||
|
||||
assertTrue(accountDetails.getAccountName().equals(owner));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user