### Question:
RuntimeInstrument extends Instrument { @Override public Instrumentation createInstrumentation(Method benchmarkMethod) throws InvalidBenchmarkException { checkNotNull(benchmarkMethod); checkArgument(isBenchmarkMethod(benchmarkMethod)); if (isStatic(benchmarkMethod)) { throw new InvalidBenchmarkException("Benchmark methods must not be static: %s", benchmarkMethod.getName()); } try { switch (BenchmarkMethods.Type.of(benchmarkMethod)) { case MACRO: return new MacrobenchmarkInstrumentation(benchmarkMethod); case MICRO: return new MicrobenchmarkInstrumentation(benchmarkMethod); case PICO: return new PicobenchmarkInstrumentation(benchmarkMethod); default: throw new AssertionError("unknown type"); } } catch (IllegalArgumentException e) { throw new InvalidBenchmarkException("Benchmark methods must have no arguments or accept " + "a single int or long parameter: %s", benchmarkMethod.getName()); } } @Inject  RuntimeInstrument(@NanoTimeGranularity ShortDuration nanoTimeGranularity,
      @Stdout PrintWriter stdout, @Stderr PrintWriter stderr); @Override boolean isBenchmarkMethod(Method method); @Override Instrumentation createInstrumentation(Method benchmarkMethod);  }### Answer:
@Test public void createInstrumentation_macrobenchmark() throws Exception { Method benchmarkMethod = RuntimeBenchmark.class.getDeclaredMethod("macrobenchmark"); Instrumentation instrumentation = instrument.createInstrumentation(benchmarkMethod); assertEquals(benchmarkMethod, instrumentation.benchmarkMethod()); assertEquals(instrument, instrumentation.instrument()); assertEquals(MacrobenchmarkWorker.class, instrumentation.workerClass()); }
@Test public void createInstrumentation_microbenchmark() throws Exception { Method benchmarkMethod = RuntimeBenchmark.class.getDeclaredMethod("microbenchmark", int.class); Instrumentation instrumentation = instrument.createInstrumentation(benchmarkMethod); assertEquals(benchmarkMethod, instrumentation.benchmarkMethod()); assertEquals(instrument, instrumentation.instrument()); assertEquals(RuntimeWorker.Micro.class, instrumentation.workerClass()); }
@Test public void createInstrumentation_picobenchmark() throws Exception { Method benchmarkMethod = RuntimeBenchmark.class.getDeclaredMethod("picobenchmark", long.class); Instrumentation instrumentation = instrument.createInstrumentation(benchmarkMethod); assertEquals(benchmarkMethod, instrumentation.benchmarkMethod()); assertEquals(instrument, instrumentation.instrument()); assertEquals(RuntimeWorker.Pico.class, instrumentation.workerClass()); }
@Test public void createInstrumentation_badParam() throws Exception { Method benchmarkMethod = RuntimeBenchmark.class.getDeclaredMethod("integerParam", Integer.class); try { instrument.createInstrumentation(benchmarkMethod); fail(); } catch (InvalidBenchmarkException expected) {} }
@Test public void createInstrumentation_notAMacrobenchmark() throws Exception { Method benchmarkMethod = RuntimeBenchmark.class.getDeclaredMethod("notAMacrobenchmark"); try { instrument.createInstrumentation(benchmarkMethod); fail(); } catch (IllegalArgumentException expected) {} }
@Test public void createInstrumentationnotAMicrobenchmark() throws Exception { Method benchmarkMethod = RuntimeBenchmark.class.getDeclaredMethod("notAMicrobenchmark", int.class); try { instrument.createInstrumentation(benchmarkMethod); fail(); } catch (IllegalArgumentException expected) {} }
@Test public void createInstrumentation_notAPicobenchmark() throws Exception { Method benchmarkMethod = RuntimeBenchmark.class.getDeclaredMethod("notAPicobenchmark", long.class); try { instrument.createInstrumentation(benchmarkMethod); fail(); } catch (IllegalArgumentException expected) {} }