Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: yyvess/Guice-configuration
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: node-mc/Guice-configuration
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 5 files changed
  • 1 contributor

Commits on Aug 19, 2019

  1. add boolean to support types

    node-mc committed Aug 19, 2019
    Copy the full SHA
    7a3d0aa View commit details
Original file line number Diff line number Diff line change
@@ -47,8 +47,8 @@ public class VirtualBeanFactory {

private static final String GET_METHOD_PATTERN = VirtualBean.GET_PREFIX + ".+";
private static final int GET_PREFIX_SIZE = VirtualBean.GET_PREFIX.length();
private static final List<Class> SUPPORTED_TYPES
= asList(int.class, Integer.class, double.class, Double.class, String.class, Map.class, List.class);
private static final List<Class> SUPPORTED_TYPES = asList(
int.class, Integer.class, double.class, Double.class, String.class, Map.class, List.class, Boolean.class, boolean.class);

private final BeanValidator beanValidator;

@@ -117,7 +117,7 @@ private Optional<Entry<String, Object>> mapCandidateChild(Class beanInterface, E
if (e.getValue() instanceof Map) {
return stream(beanInterface.getMethods())
.filter(method -> isCandidateMethod(e.getKey(), method))
.map(method -> buildChildEntry(e.getKey(), method, (Map) e.getValue()))
.<Map.Entry<String, Object>>map(method -> buildChildEntry(e.getKey(), method, (Map) e.getValue()))
.findFirst();
}
return Optional.empty();
Original file line number Diff line number Diff line change
@@ -100,6 +100,9 @@ public void super_class_match() {
public static class ConfiguredClass {
@InjectConfig
private Optional<String> p1;

@InjectConfig
private boolean p2;
}

private static class Extends extends ConfiguredClass {
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@ public class VirtualBeanFactoryTest {

private Integer field;

private Boolean aBoolean;

private InterfaceTypedForTest interfaceField;

private Optional<Integer> optional;
@@ -75,7 +77,24 @@ public void nominal() throws NoSuchFieldException {
assertThat(value, is(111));
}

@Test
// @Test
// public void nominal2() throws NoSuchFieldException {
// when(config.getAnyRef("test2")).thenReturn(true);
// Field field2 = this.getClass().getDeclaredField("aBoolean");
// VirtualBeanFactory virtualBeanFactory2 = new VirtualBeanFactory(beanValidator)
// .withConfig(config)
// .withField(field2)
// .withPath("test2")
// .withType(Boolean.class);
//
// Object value2 = virtualBeanFactory2.buildValue();
//
// assertThat(virtualBeanFactory2.getField(), is(field2));
// assertThat(value2, instanceOf(Boolean.class));
// assertThat(value2, is(true));
// }

@Test
public void optional() throws NoSuchFieldException {
VirtualBeanFactory virtualBeanFactory = new VirtualBeanFactory(beanValidator)
.withConfig(config)
Original file line number Diff line number Diff line change
@@ -51,6 +51,9 @@ public class ConfigFromConf {
@InjectConfig
private Optional<Integer> emptyInteger;

@InjectConfig
private boolean aBoolean;

@InjectConfig("complexEntries")
private ServiceConfiguration config;

@@ -67,6 +70,7 @@ public void test() {
assertThat(aInteger, is(44));
assertThat(aOptionalInteger, is(Optional.of(423)));
assertThat(emptyInteger, is(Optional.empty()));
assertThat(aBoolean, is(false));

assertThat(aIntList, notNullValue());
assertThat(aIntList.get(0), is(67));
Original file line number Diff line number Diff line change
@@ -14,5 +14,6 @@
"value1",
"value2"
]
}
},
"aBoolean": false
}