Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacqu committed Jun 20, 2016
1 parent 6989e85 commit c56e3c5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/java/ch/jalu/injector/InjectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ch.jalu.injector.instantiation.Instantiation;
import ch.jalu.injector.instantiation.InstantiationFallback;

import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Provider;
import java.lang.reflect.Method;
Expand All @@ -26,6 +27,7 @@ private InjectionHelper() {
* @param <T> the class' type
* @return injection of the class or null if none detected
*/
@Nullable
public static <T> Instantiation<T> getInjection(Class<T> clazz) {
return firstNotNull(
ConstructorInjection.provide(clazz),
Expand All @@ -39,6 +41,7 @@ public static <T> Instantiation<T> getInjection(Class<T> clazz) {
* @param clazz the class to search
* @return post construct method, or null
*/
@Nullable
public static Method getAndValidatePostConstructMethod(Class<?> clazz) {
Method postConstructMethod = null;
for (Method method : clazz.getDeclaredMethods()) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/jalu/injector/InjectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ private void validatePackage(Class<?> clazz) {
*/
private static void executePostConstructMethod(Object object) {
Method postConstructMethod = InjectionHelper.getAndValidatePostConstructMethod(object.getClass());
ReflectionUtils.invokeMethod(postConstructMethod, object);
if (postConstructMethod != null) {
ReflectionUtils.invokeMethod(postConstructMethod, object);
}
}

private static void validateInstantiable(Class<?> clazz) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/ch/jalu/injector/InjectorImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void shouldThrowForStaticPostConstructMethod() {
@Test
public void shouldForwardExceptionFromPostConstruct() {
// given / when / then
expectInjectorException("Error executing @PostConstruct method");
expectInjectorException("Could not invoke method");
injector.getSingleton(InvalidPostConstruct.ThrowsException.class);
}

Expand Down

0 comments on commit c56e3c5

Please sign in to comment.