forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into BAEL-2527
- Loading branch information
Showing
68 changed files
with
539 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
### Relevant articles | ||
|
||
- [Introduction to Apache Spark](http://www.baeldung.com/apache-spark) | ||
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ | |
<guice.version>4.1.0</guice.version> | ||
</properties> | ||
|
||
</project> | ||
</project> |
24 changes: 24 additions & 0 deletions
24
guice/src/main/java/com/baeldung/examples/common/Account.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public class Account { | ||
|
||
private String accountNumber; | ||
private String type; | ||
|
||
public String getAccountNumber() { | ||
return accountNumber; | ||
} | ||
|
||
public void setAccountNumber(String accountNumber) { | ||
this.accountNumber = accountNumber; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/AccountService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public interface AccountService { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/AccountServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public class AccountServiceImpl implements AccountService { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/AudioBookService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public interface AudioBookService { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/AudioBookServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public class AudioBookServiceImpl implements AudioBookService { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/AuthorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public interface AuthorService { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/AuthorServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public class AuthorServiceImpl implements AuthorService { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/BookService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public interface BookService { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
guice/src/main/java/com/baeldung/examples/common/BookServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public class BookServiceImpl implements BookService { | ||
|
||
private AuthorService authorService; | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/PersonDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public interface PersonDao { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
guice/src/main/java/com/baeldung/examples/common/PersonDaoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.baeldung.examples.common; | ||
|
||
public class PersonDaoImpl implements PersonDao { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.baeldung.examples.guice; | ||
|
||
public class Foo { | ||
} |
9 changes: 9 additions & 0 deletions
9
guice/src/main/java/com/baeldung/examples/guice/FooProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.baeldung.examples.guice; | ||
|
||
import com.google.inject.Inject; | ||
|
||
public class FooProcessor { | ||
|
||
@Inject | ||
private Foo foo; | ||
} |
19 changes: 19 additions & 0 deletions
19
guice/src/main/java/com/baeldung/examples/guice/GuicePersonService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.baeldung.examples.guice; | ||
|
||
import com.baeldung.examples.common.PersonDao; | ||
import com.google.inject.Inject; | ||
|
||
public class GuicePersonService { | ||
|
||
@Inject | ||
private PersonDao personDao; | ||
|
||
public PersonDao getPersonDao() { | ||
return personDao; | ||
} | ||
|
||
public void setPersonDao(PersonDao personDao) { | ||
this.personDao = personDao; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
guice/src/main/java/com/baeldung/examples/guice/GuiceUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.baeldung.examples.guice; | ||
|
||
import com.baeldung.examples.common.AccountService; | ||
import com.google.inject.Inject; | ||
|
||
public class GuiceUserService { | ||
|
||
@Inject | ||
private AccountService accountService; | ||
|
||
public AccountService getAccountService() { | ||
return accountService; | ||
} | ||
|
||
public void setAccountService(AccountService accountService) { | ||
this.accountService = accountService; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
guice/src/main/java/com/baeldung/examples/guice/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.baeldung.examples.guice; | ||
|
||
public class Person { | ||
private String firstName; | ||
|
||
private String lastName; | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
guice/src/main/java/com/baeldung/examples/guice/modules/GuiceModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.baeldung.examples.guice.modules; | ||
|
||
import com.baeldung.examples.common.AccountService; | ||
import com.baeldung.examples.common.AccountServiceImpl; | ||
import com.baeldung.examples.common.BookService; | ||
import com.baeldung.examples.common.BookServiceImpl; | ||
import com.baeldung.examples.common.PersonDao; | ||
import com.baeldung.examples.common.PersonDaoImpl; | ||
import com.baeldung.examples.guice.Foo; | ||
import com.baeldung.examples.guice.Person; | ||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Provider; | ||
import com.google.inject.Provides; | ||
|
||
public class GuiceModule extends AbstractModule { | ||
|
||
@Override | ||
protected void configure() { | ||
try { | ||
bind(AccountService.class).to(AccountServiceImpl.class); | ||
bind(Person.class).toConstructor(Person.class.getConstructor()); | ||
// bind(Person.class).toProvider(new Provider<Person>() { | ||
// public Person get() { | ||
// Person p = new Person(); | ||
// return p; | ||
// } | ||
// }); | ||
bind(Foo.class).toProvider(new Provider<Foo>() { | ||
public Foo get() { | ||
return new Foo(); | ||
} | ||
}); | ||
bind(PersonDao.class).to(PersonDaoImpl.class); | ||
|
||
} catch (NoSuchMethodException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (SecurityException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
@Provides | ||
public BookService bookServiceGenerator() { | ||
return new BookServiceImpl(); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
guice/src/test/java/com/baeldung/examples/GuiceUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.baeldung.examples; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.junit.Test; | ||
|
||
import com.baeldung.examples.common.BookService; | ||
import com.baeldung.examples.guice.FooProcessor; | ||
import com.baeldung.examples.guice.GuicePersonService; | ||
import com.baeldung.examples.guice.GuiceUserService; | ||
import com.baeldung.examples.guice.Person; | ||
import com.baeldung.examples.guice.modules.GuiceModule; | ||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
|
||
public class GuiceUnitTest { | ||
|
||
@Test | ||
public void givenAccountServiceInjectedInGuiceUserService_WhenGetAccountServiceInvoked_ThenReturnValueIsNotNull() { | ||
Injector injector = Guice.createInjector(new GuiceModule()); | ||
GuiceUserService guiceUserService = injector.getInstance(GuiceUserService.class); | ||
assertNotNull(guiceUserService.getAccountService()); | ||
} | ||
|
||
@Test | ||
public void givenBookServiceIsRegisteredInModule_WhenBookServiceIsInjected_ThenReturnValueIsNotNull() { | ||
Injector injector = Guice.createInjector(new GuiceModule()); | ||
BookService bookService = injector.getInstance(BookService.class); | ||
assertNotNull(bookService); | ||
} | ||
|
||
@Test | ||
public void givenMultipleBindingsForPerson_WhenPersonIsInjected_ThenTestFailsByProvisionException() { | ||
Injector injector = Guice.createInjector(new GuiceModule()); | ||
Person person = injector.getInstance(Person.class); | ||
assertNotNull(person); | ||
} | ||
|
||
@Test | ||
public void givenFooInjectedToFooProcessorAsOptionalDependency_WhenFooProcessorIsRetrievedFromContext_ThenCreationExceptionIsNotThrown() { | ||
Injector injector = Guice.createInjector(new GuiceModule()); | ||
FooProcessor fooProcessor = injector.getInstance(FooProcessor.class); | ||
assertNotNull(fooProcessor); | ||
} | ||
|
||
@Test | ||
public void givenGuicePersonServiceConstructorAnnotatedByInject_WhenGuicePersonServiceIsInjected_ThenInstanceWillBeCreatedFromTheConstructor() { | ||
Injector injector = Guice.createInjector(new GuiceModule()); | ||
GuicePersonService personService = injector.getInstance(GuicePersonService.class); | ||
assertNotNull(personService); | ||
} | ||
|
||
@Test | ||
public void givenPersonDaoInjectedToGuicePersonServiceBySetterInjection_WhenGuicePersonServiceIsInjected_ThenPersonDaoInitializedByTheSetter() { | ||
Injector injector = Guice.createInjector(new GuiceModule()); | ||
GuicePersonService personService = injector.getInstance(GuicePersonService.class); | ||
assertNotNull(personService); | ||
assertNotNull(personService.getPersonDao()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.