### Question:
VarExporter implements VariableHost { public void export(Object obj, String prefix) { checkTypeCompatibility(obj.getClass()); final boolean isNamespaceClassSet = namespaceClass != null; final Class c = isNamespaceClassSet ? namespaceClass : obj.getClass(); for (final Field field : (declaredFieldsOnly ? c.getDeclaredFields() : c.getFields())) { Export export = field.getAnnotation(Export.class); if (Modifier.isStatic(field.getModifiers())) { loadMemberVariable(field, export, c, true, prefix, null); } else { loadMemberVariable(field, export, obj, true, prefix, null); } } Set<Class<?>> classAndInterfaces = Sets.newHashSet(); getAllInterfaces(c, classAndInterfaces); classAndInterfaces.add(c); for (Class<?> cls : classAndInterfaces) { for (final Method method : (declaredFieldsOnly ? cls.getDeclaredMethods() : cls.getMethods())) { Export export = method.getAnnotation(Export.class); if (Modifier.isStatic(method.getModifiers())) { loadMemberVariable(method, export, c, true, prefix, null); } else { loadMemberVariable(method, export, obj, true, prefix, null); } } } } private  VarExporter(@Nullable final String namespace, @Nullable final Class namespaceClass, final boolean declaredFieldsOnly); boolean isDeclaredFieldsOnly(); Class<?> getNamespaceClass(); static synchronized VarExporter forNamespace(String namespace); static synchronized Optional<VarExporter> forNamespaceIfExists(@Nonnull final String namespace); static synchronized VarExporter forNamespace(@Nonnull final Class<?> clazz, final boolean declaredFieldsOnly); static synchronized List<String> getNamespaces(); static VarExporter global(); static void visitNamespaceVariables(String namespace, VariableVisitor visitor); static VariableHost withTag(final String tag); VarExporter includeInGlobal(); VarExporter setParentNamespace(VarExporter namespace); String getNamespace(); VarExporter getParentNamespace(); void export(Object obj, String prefix); void export(Class c, String prefix); void export(Object obj, Member member, String prefix, String name); void export(Class c, Member member, String prefix, String name); void export(LazilyManagedVariable lazilyManagedVariable); void export(ManagedVariable managedVariable); @SuppressWarnings("unchecked") T getValue(final String variableName); @Override @SuppressWarnings("unchecked") Variable<T> getVariable(final String variableName); @Override void visitVariables(VariableVisitor visitor); Iterable<Variable> getVariables(); void dump(final PrintWriter out, final boolean includeDoc); void dumpJson(final PrintWriter out); @SuppressWarnings("unchecked") @VisibleForTesting static void resetGlobal(); @SuppressWarnings("unchecked") @Deprecated void reset();  }### Answer:
@Test public void testWeakReference() { ExampleClass instance = new ExampleClass(); exporter.export(instance, ""); assertExportedNames(exporter, "ex1field", "ex1method", "static1field", "static1method", "myNameIsEarl"); instance = null; System.gc(); assertExportedNames(exporter, "myNameIsEarl", "static1field", "static1method"); }
@Test public void testExportSubclassInstance() { ExampleSubclass instance = new ExampleSubclass(); exporter.export(instance, ""); assertExportedNames(exporter, "ex1field", "ex1method", "static1field", "static1method", "subm1", "myNameIsEarl"); }
@Test public void testExportPrivateField() throws Exception { ExampleClass instance = new ExampleClass(); try { exporter.export(instance, ExampleClass.class.getField("prv"), "", "private"); Assert.fail("expected NoSuchFieldException"); } catch (NoSuchFieldException e) { } }