@Lookup annotation Code (#3900)

* Updated

* Changed Test Names

* Updated code for method injection section 3.2

* Added Grader bean and changes for it
This commit is contained in:
Gangadharan Khoteeswarun
2018-04-16 22:17:39 +08:00
committed by Josh Cummings
parent c1a6b5b553
commit 6f887d29c6
7 changed files with 168 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package com.baeldung.methodinjections;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class StudentTest {
@Test
public void whenLookupMethodCalled_thenNewInstanceReturned() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
Student student1 = context.getBean("studentBean", Student.class);
Student student2 = context.getBean("studentBean", Student.class);
Assert.assertEquals(student1, student2);
Assert.assertNotEquals(student1.getNotification("Alex"), student2.getNotification("Bethany"));
context.close();
}
@Test
public void whenAbstractGetterMethodInjects_thenNewInstanceReturned() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
StudentServices services = context.getBean("studentServices", StudentServices.class);
Assert.assertEquals("PASS", services.appendMark("Alex", 76));
Assert.assertEquals("FAIL", services.appendMark("Bethany", 44));
Assert.assertEquals("PASS", services.appendMark("Claire", 96));
context.close();
}
}