|
18 | 18 | */ |
19 | 19 | package org.jooby.test; |
20 | 20 |
|
| 21 | +import java.lang.reflect.Field; |
21 | 22 | import java.util.ArrayList; |
22 | 23 | import java.util.Arrays; |
23 | 24 | import java.util.List; |
|
31 | 32 | import org.junit.runners.model.Statement; |
32 | 33 |
|
33 | 34 | import com.google.inject.Binder; |
34 | | -import com.google.inject.Guice; |
35 | | -import com.google.inject.name.Names; |
36 | 35 | import com.typesafe.config.Config; |
37 | 36 | import com.typesafe.config.ConfigFactory; |
38 | 37 | import com.typesafe.config.ConfigValueFactory; |
@@ -146,14 +145,29 @@ public void evaluate() throws Throwable { |
146 | 145 | @Override |
147 | 146 | protected Object createTest() throws Exception { |
148 | 147 | Object test = super.createTest(); |
149 | | - Guice.createInjector(binder -> { |
150 | | - binder.bind(Integer.class).annotatedWith(Names.named("port")).toInstance(port); |
151 | | - binder.bind(Integer.class).annotatedWith(Names.named("securePort")).toInstance(securePort); |
152 | | - }).injectMembers(test); |
| 148 | + Class<? extends Object> c = test.getClass(); |
| 149 | + set(test, c, "port", port); |
| 150 | + set(test, c, "securePort", securePort); |
153 | 151 |
|
154 | 152 | return test; |
155 | 153 | } |
156 | 154 |
|
| 155 | + @SuppressWarnings("rawtypes") |
| 156 | + private void set(final Object test, final Class clazz, final String field, final Object value) |
| 157 | + throws Exception { |
| 158 | + try { |
| 159 | + Field f = clazz.getDeclaredField(field); |
| 160 | + f.setAccessible(true); |
| 161 | + f.set(test, value); |
| 162 | + } catch (NoSuchFieldException ex) { |
| 163 | + Class superclass = clazz.getSuperclass(); |
| 164 | + if (superclass != Object.class) { |
| 165 | + set(test, superclass, field, value); |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + } |
| 170 | + |
157 | 171 | @Override |
158 | 172 | protected Statement withAfterClasses(final Statement statement) { |
159 | 173 | Statement next = super.withAfterClasses(statement); |
|
0 commit comments