### Question:
Capsule implements Runnable, InvocationHandler { static List<String> expandArgs(List<String> args0, List<String> args) { final List<String> args1 = new ArrayList<String>(); boolean expanded = false; for (String a : args0) { if (a.startsWith("$")) { if (a.equals("$*")) { args1.addAll(args); expanded = true; continue; } else { try { final int i = Integer.parseInt(a.substring(1)); args1.add(args.get(i - 1)); expanded = true; continue; } catch (NumberFormatException e) { } } } args1.add(a); } if (!expanded) args1.addAll(args); return args1; } @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) protected  Capsule(Path jarFile); @SuppressWarnings("LeakingThisInConstructor") protected  Capsule(Capsule pred); static final void main(String[] args); @SuppressWarnings({"BroadCatchBlock", "UnusedAssignment"}) static int main0(String[] args0); static void premain(String agentArgs, Instrumentation inst); static Object getCapsule(String capletClassName); boolean isAgent(); @Override final void run(); @Override Object invoke(Object proxy, Method method, Object[] args); @Override final int hashCode(); @Override final boolean equals(Object obj); @Override String toString(); static final String VERSION; }### Answer:
@Test public void testExpandArgs() throws Exception { assertEquals(list("x", "y", "z"), Capsule.expandArgs(list("x", "y", "z"), CapsuleTest.<String>list())); assertEquals(list("a", "b", "c"), Capsule.expandArgs(CapsuleTest.<String>list(), list("a", "b", "c"))); assertEquals(list("x", "y", "z", "a", "b", "c"), Capsule.expandArgs(list("x", "y", "z"), list("a", "b", "c"))); assertEquals(list("x", "a", "b", "c", "z"), Capsule.expandArgs(list("x", "$*", "z"), list("a", "b", "c"))); assertEquals(list("b", "a", "c"), Capsule.expandArgs(list("$2", "$1", "$3"), list("a", "b", "c"))); }