|
39 | 39 | import static org.junit.Assert.fail;
|
40 | 40 |
|
41 | 41 | import java.util.Arrays;
|
| 42 | +import java.util.List; |
42 | 43 |
|
43 | 44 | import org.junit.Test;
|
44 | 45 | import org.scijava.plugin.Parameter;
|
@@ -190,6 +191,55 @@ public void testOptionalMissingTransitive() {
|
190 | 191 | }
|
191 | 192 | }
|
192 | 193 |
|
| 194 | + /** |
| 195 | + * Tests that missing {@link Service}s are handled properly in non-strict |
| 196 | + * mode; specifically, that {@link IllegalArgumentException} is <em>not</em> |
| 197 | + * thrown when attempting to create a {@link Context} requiring one directly. |
| 198 | + */ |
| 199 | + @Test |
| 200 | + public void testNonStrictMissingDirect() { |
| 201 | + final List<Class<? extends Service>> serviceClasses = |
| 202 | + Context.serviceClassList(MissingService.class); |
| 203 | + final Context context = new Context(serviceClasses, false); |
| 204 | + assertEquals(0, context.getServiceIndex().size()); |
| 205 | + } |
| 206 | + |
| 207 | + /** |
| 208 | + * Tests that missing {@link Service}s are handled properly in non-strict |
| 209 | + * mode; specifically, that {@link IllegalArgumentException} is <em>not</em> |
| 210 | + * thrown when attempting to create a {@link Context} requiring one |
| 211 | + * transitively. |
| 212 | + */ |
| 213 | + @Test |
| 214 | + public void testNonStrictMissingTransitive() { |
| 215 | + final List<Class<? extends Service>> serviceClasses = |
| 216 | + Context.serviceClassList(MissingService.class); |
| 217 | + final Context context = new Context(serviceClasses, false); |
| 218 | + assertEquals(0, context.getServiceIndex().size()); |
| 219 | + } |
| 220 | + |
| 221 | + /** |
| 222 | + * Tests that missing-but-optional {@link Service}s are handled properly in |
| 223 | + * non-strict mode; specifically, that {@link IllegalArgumentException} is |
| 224 | + * <em>not</em> thrown when attempting to create a {@link Context} requiring |
| 225 | + * one transitively. |
| 226 | + * <p> |
| 227 | + * A service marked {@link Optional}, but annotated without |
| 228 | + * {@code required = false} from a dependent service, is assumed to be |
| 229 | + * required for that dependent service. |
| 230 | + * </p> |
| 231 | + */ |
| 232 | + @Test |
| 233 | + public void testNonStrictOptionalMissingTransitive() { |
| 234 | + final List<Class<? extends Service>> serviceClasses = |
| 235 | + Context.serviceClassList(ServiceRequiringOptionalMissingService.class); |
| 236 | + final Context context = new Context(serviceClasses, false); |
| 237 | + final List<Service> services = context.getServiceIndex().getAll(); |
| 238 | + assertEquals(1, services.size()); |
| 239 | + assertSame(ServiceRequiringOptionalMissingService.class, services.get(0) |
| 240 | + .getClass()); |
| 241 | + } |
| 242 | + |
193 | 243 | /**
|
194 | 244 | * Verifies that the order plugins appear in the PluginIndex and Service list
|
195 | 245 | * does not affect which services are loaded.
|
|
0 commit comments