Skip to content

Commit 5e9da20

Browse files
Fix ProxyTest
1 parent 664d444 commit 5e9da20

File tree

1 file changed

+20
-26
lines changed
  • archaius2-guice/src/test/java/com/netflix/archaius/guice

1 file changed

+20
-26
lines changed

archaius2-guice/src/test/java/com/netflix/archaius/guice/ProxyTest.java

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24+
import java.util.stream.Stream;
25+
2426
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertThrows;
2528
import static org.junit.jupiter.api.Assertions.assertTrue;
26-
import static org.junit.jupiter.api.Assertions.fail;
2729

2830
public class ProxyTest {
29-
public static interface MyConfig {
31+
public interface MyConfig {
3032
@DefaultValue("0")
3133
int getInteger();
3234

@@ -43,15 +45,7 @@ public interface MySubConfig {
4345
@DefaultValue("0")
4446
int getInteger();
4547
}
46-
47-
@Configuration(prefix="foo")
48-
public interface MyConfigWithPrefix {
49-
@DefaultValue("0")
50-
int getInteger();
51-
52-
String getString();
53-
}
54-
48+
5549
@Test
5650
public void testConfigWithNoPrefix() throws ConfigException {
5751
Injector injector = Guice.createInjector(
@@ -67,6 +61,7 @@ protected void configureArchaius() {
6761

6862
@Provides
6963
@Singleton
64+
@SuppressWarnings("unused")
7065
public MyConfig getMyConfig(ConfigProxyFactory factory) {
7166
return factory.newProxy(MyConfig.class);
7267
}
@@ -98,6 +93,7 @@ protected void configureArchaius() {
9893

9994
@Provides
10095
@Singleton
96+
@SuppressWarnings("unused")
10197
public MyConfig getMyConfig(ConfigProxyFactory factory) {
10298
return factory.newProxy(MyConfig.class, "prefix");
10399
}
@@ -121,6 +117,7 @@ public void confirmConfigurationSourceWorksWithProxy() {
121117
new ArchaiusModule() {
122118
@Provides
123119
@Singleton
120+
@SuppressWarnings("unused")
124121
public ModuleTestConfig getMyConfig(ConfigProxyFactory factory) {
125122
return factory.newProxy(ModuleTestConfig.class, "moduleTest");
126123
}
@@ -135,34 +132,31 @@ public ModuleTestConfig getMyConfig(ConfigProxyFactory factory) {
135132

136133
public interface DefaultMethodWithAnnotation {
137134
@DefaultValue("fromAnnotation")
135+
@SuppressWarnings("unused")
138136
default String getValue() {
139137
return "fromDefault";
140138
}
141139
}
142140

143141
@Test
144142
public void annotationAndDefaultImplementationNotAllowed() throws ConfigException {
145-
try {
146-
Injector injector = Guice.createInjector(
143+
Injector injector = Guice.createInjector(
147144
new ArchaiusModule() {
148-
@Override
149-
protected void configureArchaius() {
150-
}
151-
152145
@Provides
153146
@Singleton
147+
@SuppressWarnings("unused")
154148
public DefaultMethodWithAnnotation getMyConfig(ConfigProxyFactory factory) {
155149
return factory.newProxy(DefaultMethodWithAnnotation.class);
156150
}
157151
});
158-
159-
injector.getInstance(DefaultMethodWithAnnotation.class);
160-
fail("Exepcted ProvisionException");
161-
} catch (ProvisionException e) {
162-
e.printStackTrace();
163-
assertEquals(IllegalArgumentException.class, e.getCause().getCause().getClass());
164-
} catch (Exception e) {
165-
fail("Expected ProvisionException");
166-
}
152+
153+
ProvisionException pe = assertThrows(ProvisionException.class,
154+
() -> injector.getInstance(DefaultMethodWithAnnotation.class));
155+
156+
Stream.iterate((Throwable) pe, t -> t != null ? t.getCause() : null)
157+
.limit(10) // avoid infinite loop
158+
.filter(t -> t instanceof IllegalArgumentException)
159+
.findFirst()
160+
.orElseThrow(() -> new AssertionError("Expected an IllegalArgumentException in the cause chain", pe));
167161
}
168162
}

0 commit comments

Comments
 (0)