BytecodeUtil { public static <A extends TraversalStrategy> Iterator<A> findStrategies(final Bytecode bytecode, final Class<A> clazz) { return IteratorUtils.map( IteratorUtils.filter(bytecode.getSourceInstructions().iterator(), s -> s.getOperator().equals(TraversalSource.Symbols.withStrategies) && clazz.isAssignableFrom(s.getArguments()[0].getClass())), os -> (A) os.getArguments()[0]); } private  BytecodeUtil(); static Iterator<A> findStrategies(final Bytecode bytecode, final Class<A> clazz);  }
@Test public void shouldFindStrategy() { final Iterator<OptionsStrategy> itty = BytecodeUtil.findStrategies(g.with("x").with("y", 100).V().asAdmin().getBytecode(), OptionsStrategy.class); int counter = 0; while(itty.hasNext()) { final OptionsStrategy strategy = itty.next(); if (strategy.getOptions().keySet().contains("x")) { assertThat(strategy.getOptions().get("x"), is(true)); counter++; } else if (strategy.getOptions().keySet().contains("y")) { assertEquals(100, strategy.getOptions().get("y")); counter++; } } assertEquals(2, counter); }
@Test public void shouldNotFindStrategy() { final Iterator<ReadOnlyStrategy> itty = BytecodeUtil.findStrategies(g.with("x").with("y", 100).V().asAdmin().getBytecode(), ReadOnlyStrategy.class); assertThat(itty.hasNext(), is(false)); }