public static ResourceCalculatorProcessTree getResourceCalculatorProcessTree(
    String pid, Class<? extends ResourceCalculatorProcessTree> clazz, Configuration conf) {
    if (clazz != null) {
      try {
        Constructor <? extends ResourceCalculatorProcessTree> c = clazz.getConstructor(String.class);
        ResourceCalculatorProcessTree rctree = c.newInstance(pid);
        rctree.setConf(conf);
        rctree.initialize();
        return rctree;
      } catch(Exception e) {
        throw new RuntimeException(e);
      }
    }

    // No class given, try a os specific class
    if (ProcfsBasedProcessTree.isAvailable()) {
      return new ProcfsBasedProcessTree(pid);
    }
    if (WindowsBasedProcessTree.isAvailable()) {
      return new WindowsBasedProcessTree(pid);
    }

    // Not supported on this system.
    return null;
  }
@Test
  void testCreatedInstanceConfigured() {
    ResourceCalculatorProcessTree tree;
    Configuration conf = new Configuration();
    tree = ResourceCalculatorProcessTree.getResourceCalculatorProcessTree("1", EmptyProcessTree.class, conf);
    assertNotNull(tree);
    assertThat(tree.getConf(), sameInstance(conf));
  }