I have created a framework that uses LoadTimeWeaving. In some cases the classes that my framework are trying to weave have already been loaded. Thus these classes wont be handled by aspectj's LoadTimeWeaving.
My initial thought was to try and unload/reload the classes so that AspectJ could reload them during it's LoadTimeWeaving phase. But according to my findings that's impossible.
Some exampel code https://github.com/abrovinc/methodmock/blob/preloaded-class-test/example-projects/java-versions/java-1.6/src/test/java/com/example/ExampleTest.java
@Test
public void testExample() throws Exception {
new Example();
new LoadJavaAgent();
mockMethod("methodToBeMocked").returns("Mock works");
assertEquals("Mock works",Example.methodToBeMocked());
}
If Example is loaded before LoadJavaAgent is loaded the load time weaving that occurs once LoadJavaAgent is called wont affect Example class.
I would like an option to initiate a new object and have that object be handled by the LoadTimeWeaving
Regards