BAEL-1308 DI related code removed and included original text file

This commit is contained in:
Ahmad Alsanie 2017-11-20 21:08:41 +02:00
parent cf7c96b469
commit dd91ef722b
5 changed files with 2 additions and 81 deletions

View File

@ -0,0 +1,2 @@
#Copy a File with Java (www.Baeldung.com)
Copying Files with Java is Fun!

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -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";
}
}

View File

@ -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());
}
}