@Test public void testgetAllClass() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { DefaultContractsGenerator defaultContractsGenerator = new DefaultContractsGenerator(); Method method = defaultContractsGenerator.getClass() .getDeclaredMethod("getAllClass", ClassLoader.class); method.setAccessible(true); try { method.invoke(defaultContractsGenerator, new Object[] {null}); } catch (Exception e) { assertTrue(true); return; } fail("Run 'testgetAllClass' failed, expected to catch Exception but not"); }
private static Vector getAllClass(ClassLoader classLoader) { Field classesField; try { classesField = ClassLoader.class.getDeclaredField("classes"); classesField.setAccessible(true); if (classesField.get(classLoader) instanceof Vector) { return (Vector) classesField.get(classLoader); } } catch (Exception e) { throw new RuntimeException("Cannot get class from ClassLoader " + classLoader.getClass()); } return new Vector<>(); }
DefaultContractsGenerator implements ContractsGenerator { private static Vector getAllClass(ClassLoader classLoader) { Field classesField; try { classesField = ClassLoader.class.getDeclaredField("classes"); classesField.setAccessible(true); if (classesField.get(classLoader) instanceof Vector) { return (Vector) classesField.get(classLoader); } } catch (Exception e) { throw new RuntimeException("Cannot get class from ClassLoader " + classLoader.getClass()); } return new Vector<>(); } }
DefaultContractsGenerator implements ContractsGenerator { private static Vector getAllClass(ClassLoader classLoader) { Field classesField; try { classesField = ClassLoader.class.getDeclaredField("classes"); classesField.setAccessible(true); if (classesField.get(classLoader) instanceof Vector) { return (Vector) classesField.get(classLoader); } } catch (Exception e) { throw new RuntimeException("Cannot get class from ClassLoader " + classLoader.getClass()); } return new Vector<>(); }  }
DefaultContractsGenerator implements ContractsGenerator { private static Vector getAllClass(ClassLoader classLoader) { Field classesField; try { classesField = ClassLoader.class.getDeclaredField("classes"); classesField.setAccessible(true); if (classesField.get(classLoader) instanceof Vector) { return (Vector) classesField.get(classLoader); } } catch (Exception e) { throw new RuntimeException("Cannot get class from ClassLoader " + classLoader.getClass()); } return new Vector<>(); }  @Override boolean canProcess(String type); @SuppressWarnings("unchecked") @Override void configure(Map<String, Object> config); @SuppressWarnings("ResultOfMethodCallIgnored") @Override void generate(); }
DefaultContractsGenerator implements ContractsGenerator { private static Vector getAllClass(ClassLoader classLoader) { Field classesField; try { classesField = ClassLoader.class.getDeclaredField("classes"); classesField.setAccessible(true); if (classesField.get(classLoader) instanceof Vector) { return (Vector) classesField.get(classLoader); } } catch (Exception e) { throw new RuntimeException("Cannot get class from ClassLoader " + classLoader.getClass()); } return new Vector<>(); }  @Override boolean canProcess(String type); @SuppressWarnings("unchecked") @Override void configure(Map<String, Object> config); @SuppressWarnings("ResultOfMethodCallIgnored") @Override void generate();  }