Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
 - a test case around property resolution
  • Loading branch information
djr4488 authored and djr4488 committed Oct 17, 2018
1 parent 2975a67 commit 875829f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/djr/cdi/properties/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.djr.cdi.properties;

import org.djr.cdi.properties.decrypt.Decryptor;
import org.djr.cdi.properties.decrypt.DefaultDecryptor;

import javax.enterprise.util.Nonbinding;
Expand Down Expand Up @@ -42,5 +43,5 @@
@Nonbinding
boolean isEncrypted() default false;
@Nonbinding
Class<?> defaultDecryptor() default DefaultDecryptor.class;
Class<? extends Decryptor> defaultDecryptor() default DefaultDecryptor.class;
}
1 change: 0 additions & 1 deletion src/main/java/org/djr/cdi/properties/PropertyResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/org/djr/cdi/properties/PropertyResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import org.jboss.weld.junit5.auto.EnableAlternatives;
import org.jboss.weld.junit5.auto.EnableAutoWeld;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.mockito.Mock;

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;

import java.util.List;
Expand All @@ -37,7 +40,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@EnableAutoWeld
@AddBeanClasses({ PropertyResolver.class, Config.class, FilePropertiesLoader.class, EntityManagerProducer.class,
Expand All @@ -50,6 +56,9 @@ public class PropertyResolverTest {
@DatabasePropertyEM
private EntityManagerProducer entityManagerProducer;

@Inject
private PropertyResolver propertyResolver;

@Inject
@Config(defaultValue = "testDefaultPropertyValue")
private String testProperty;
Expand Down Expand Up @@ -154,6 +163,9 @@ public class PropertyResolverTest {
@Config(propertyName = "PropertyResolverTest_doubleVal", defaultValue = "1.2")
private Double doubleTest;

@Config(propertyName = "undefinedProperty")
private String undefinedProperty;

@Test
public void testPropertySetWhenInProperties() {
assertNotNull(testProperty);
Expand Down Expand Up @@ -207,4 +219,17 @@ public void testDefaultPropertyWhenNotInPropertyConfigs() {
assertEquals(1.1f, floatTest.floatValue());
assertEquals(1.2d, doubleTest.doubleValue());
}

@Test
public void propertyResolverWhenPropertyNotFound() {
final Executable executable = () -> {
InjectionPoint injectionPoint = mock(InjectionPoint.class);
Config config = this.getClass().getDeclaredField("undefinedProperty").getAnnotation(Config.class);
Annotated annotated = mock(Annotated.class);
when(injectionPoint.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(Config.class)).thenReturn(config);
propertyResolver.getProperty("undefinedProperty", injectionPoint);
};
assertThrows(PropertyLoadException.class, executable);
}
}

0 comments on commit 875829f

Please sign in to comment.