BenchmarkCreator { public Object createBenchmarkInstance() { Object instance; try { instance = benchmarkClassCtor.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new AssertionError(e); } catch (InvocationTargetException e) { Throwable userException = e.getCause(); throw new UserCodeException(userException); } for (Field field : benchmarkClass.getDeclaredFields()) { if (field.isAnnotationPresent(Param.class)) { try { field.setAccessible(true); Parser<?> parser = Parsers.conventionalParser(field.getType()); field.set(instance, parser.parse(parameters.get(field.getName()))); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (ParseException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new AssertionError("types have been checked"); } catch (IllegalAccessException e) { throw new AssertionError("already set access"); } } } return instance; } @Inject  BenchmarkCreator(
      @BenchmarkClass Class<?> benchmarkClass,
      @Benchmark ImmutableSortedMap<String, String> parameters); Object createBenchmarkInstance();  }
@Test public void publicDefaultConstructorNoParamBenchmark() { BenchmarkCreator creator = new BenchmarkCreator( PublicDefaultConstructorNoParamBenchmark.class, ImmutableSortedMap.<String, String>of()); Object benchmarkInstance = creator.createBenchmarkInstance(); assertTrue(benchmarkInstance instanceof PublicDefaultConstructorNoParamBenchmark); }
@Test public void publicDefaultConstructorWithParamBenchmark() { BenchmarkCreator creator = new BenchmarkCreator( PublicDefaultConstructorWithParamBenchmark.class, ImmutableSortedMap.of("byteField", "1", "intField", "2", "stringField", "string")); Object benchmarkInstance = creator.createBenchmarkInstance(); assertTrue(benchmarkInstance instanceof PublicDefaultConstructorWithParamBenchmark); PublicDefaultConstructorWithParamBenchmark benchmark = (PublicDefaultConstructorWithParamBenchmark) benchmarkInstance; assertEquals(1, benchmark.byteField); assertEquals(2, benchmark.intField); assertEquals("string", benchmark.stringField); }