Merge remote-tracking branch 'origin/BAEL-2399' into BAEL-2399

This commit is contained in:
emineoymak 2019-01-01 03:20:10 -05:00
commit 0c6058427c
1 changed files with 77 additions and 72 deletions

View File

@ -1,13 +1,12 @@
package com.baeldung.examples;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import com.baeldung.examples.common.BookService;
import com.baeldung.examples.guice.Employee;
import com.baeldung.examples.guice.FooGenerator;
import com.baeldung.examples.guice.GuicePersonService;
import com.baeldung.examples.guice.GuiceUser;
import com.baeldung.examples.guice.GuiceUserService;
import com.baeldung.examples.guice.Person;
@ -18,12 +17,20 @@ import com.google.inject.Injector;
public class GuiceUnitTest {
@Test
public void givenAccountFieldInjectedInGuiceUser_WhenGetAccountInvoked_ThenReturnValueIsNotNull() {
public void givenAccountInjectedInGuiceUser_WhenGetAccountInvoked_ThenReturnValueIsNotNull() {
Injector injector = Guice.createInjector(new GuiceModule());
GuiceUser guiceUser = injector.getInstance(GuiceUser.class);
assertNotNull(guiceUser.getAccount());
}
@Test
public void givenPersonDaoInjectedInGuicePersonService_WhenGetPersonDaoInvoked_ThenReturnValueIsNotNull() {
Injector injector = Guice.createInjector(new GuiceModule());
GuicePersonService personService = injector.getInstance(GuicePersonService.class);
assertNotNull(personService);
assertNotNull(personService.getPersonDao());
}
@Test
public void givenAccountServiceInjectedInGuiceUserService_WhenGetAccountServiceInvoked_ThenReturnValueIsNotNull() {
Injector injector = Guice.createInjector(new GuiceModule());
@ -53,20 +60,18 @@ public class GuiceUnitTest {
}
@Test
public void givenEmployeeConstructorAnnotatedByInject_WhenEmployeeIsInjected_ThenInstanceWillBeCreatedFromTheConstructor() {
public void givenGuicePersonServiceConstructorAnnotatedByInject_WhenGuicePersonServiceIsInjected_ThenInstanceWillBeCreatedFromTheConstructor() {
Injector injector = Guice.createInjector(new GuiceModule());
Employee employee = injector.getInstance(Employee.class);
assertNotNull(employee);
assertEquals("Default", employee.getLastName());
GuicePersonService personService = injector.getInstance(GuicePersonService.class);
assertNotNull(personService);
}
@Test
public void givenAddressAutowiredToGuiceUserBySetterInjection_WhenGuiceUserIsInjected_ThenAddressInitializedByTheSetter() {
public void givenPersonDaoInjectedToGuicePersonServiceBySetterInjection_WhenGuicePersonServiceIsInjected_ThenPersonDaoInitializedByTheSetter() {
Injector injector = Guice.createInjector(new GuiceModule());
GuiceUser guiceUser = injector.getInstance(GuiceUser.class);
assertNotNull(guiceUser);
assertNotNull(guiceUser.getAddress());
assertEquals("Default", guiceUser.getAddress().getCity());
GuicePersonService personService = injector.getInstance(GuicePersonService.class);
assertNotNull(personService);
assertNotNull(personService.getPersonDao());
}
}