BAEL-1308 DI related code removed and included original text file
This commit is contained in:
parent
cf7c96b469
commit
dd91ef722b
|
@ -0,0 +1,2 @@
|
|||
#Copy a File with Java (www.Baeldung.com)
|
||||
Copying Files with Java is Fun!
|
|
@ -1,14 +0,0 @@
|
|||
package com.baeldung.ditypes;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.baeldung.ditypes")
|
||||
public class RegisterarConfig {
|
||||
@Bean
|
||||
public User user() {
|
||||
return new User("Alice", 1);
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.baeldung.ditypes;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Registrar {
|
||||
private User user;
|
||||
|
||||
@Autowired
|
||||
public Registrar(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String register() {
|
||||
return user.register();
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.baeldung.ditypes;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class User {
|
||||
|
||||
private String name;
|
||||
private int id;
|
||||
|
||||
public User(String name, int id) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String register() {
|
||||
return "User" + id + ": " + name + " is registered";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.baeldung.ditypes;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = RegisterarConfig.class)
|
||||
public class RegisterarTest {
|
||||
|
||||
@Autowired
|
||||
private Registrar reg;
|
||||
|
||||
@Autowired
|
||||
private User user;
|
||||
|
||||
@Test
|
||||
public void givenAutowiredAnnotation_whenSetOnField_thenRegistrarIsInjected() {
|
||||
assertNotNull(reg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAutowiredAnnotation_whenSetOnField_thenUserIsInjected() {
|
||||
assertEquals("User1: Alice is registered", user.register());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue