Skip to content

Commit 4b98e1c

Browse files
committed
Context: split list-maker to a utility method
This change will make it easier for unit tests to call the Context constructors that take a Collection instead of a varargs list.
1 parent 56264f8 commit 4b98e1c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/main/java/org/scijava/Context.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,8 @@ public Context(final boolean empty) {
122122
* @throws ClassCastException If any of the given arguments do not implement
123123
* the {@link Service} interface.
124124
*/
125-
@SuppressWarnings({ "rawtypes", "unchecked" })
126-
public Context(final Class... serviceClasses) {
127-
this(serviceClasses != null ? (Collection) Arrays.asList(serviceClasses)
128-
: Arrays.asList(Service.class));
125+
public Context(@SuppressWarnings("rawtypes") final Class... serviceClasses) {
126+
this(serviceClassList(serviceClasses));
129127
}
130128

131129
/**
@@ -379,6 +377,20 @@ public void dispose() {
379377
}
380378
}
381379

380+
// -- Utility methods --
381+
382+
/**
383+
* Utility method for converting a varargs list of service classes to a
384+
* {@link List} of those classes.
385+
*/
386+
@SuppressWarnings({ "rawtypes", "unchecked" })
387+
public static List<Class<? extends Service>> serviceClassList(
388+
final Class... serviceClasses)
389+
{
390+
return serviceClasses != null ? (List) Arrays.asList(serviceClasses)
391+
: Arrays.asList(Service.class);
392+
}
393+
382394
// -- Helper methods --
383395

384396
private String createMissingServiceMessage(

0 commit comments

Comments
 (0)