Open xanaxan opened 1 month ago
Thanks for using the very latest to verify; I think the problem is with the unexpected LoggerProducerTest.this.injectionPoint
, but would have to check.
Yes, you're right. Can't really understand why someone writes it like that. After i fixed that in all the tests i stumbled upon the next problem. A Method inside the Expectations block:
// EXPECTATIONS
new Expectations() { //replaced StrictExpectations
{
EntityResolver.valueOf(entityManager,
TestFixtures.processingContext1());
this.result = entityResolver;
for (int count = PersistenceConfig.JDBC_BATCH_SIZE; 0 < count; count--) {
this.entityResolver();
entityManager.persist(this.any);
}
entityManager.flush();
entityManager.clear();
this.entityResolver();
entityManager.persist(this.any);
entityManager.flush();
entityManager.clear();
}
private void entityResolver() {
entityResolver.enrich(TestFixtures.tenant_Mvb_MbgmClearing());
this.result = entityResolver;
entityResolver.retrieveState(this.withAny(DialogState.nullValue()));
this.result = state;
entityResolver.retrieveEnumeration(this.withAny(Datum.EINLANGE_DAT));
this.result = enumeration;
this.times = 3;
entityResolver.retrieveEnumeration(this.withAny(Referenz.CLEARING_OBJEKT_TRAEGER_REFERENZ));
this.result = enumeration;
this.times = 2;
}
}
Here the ClassCastException happens because the Recipe expects a J.Block but gets a MethodInvocation w/ 'private void entityResolver()'. I never used JMockit, so i can't tell if that's usual procedure.
Is there any way to have a recipe run through ALL files and just continue with the next file if it fails with one?
When I've seen these types of errors, unfortunately I just delete the file temporarily and rerun. But, yes, it would be great if the framework could keep running for files if see any exception - maybe a flag if don't want to default this? @sambsnyd @timtebeek fyi
In any case, this is a bug if it is generate the exception. The code is unusual however, and with the private method internal to the block, it doesn't seem to follow the expected structure of a Jmockit Expectations block: https://www.javadoc.io/doc/org.jmockit/jmockit/latest/mockit/Expectations.html
Was able to replicate it:
` @Test
void whenMethodInsideBlock() {
rewriteRun(
java(
"""
import mockit.Expectations;
import mockit.Mocked;
import mockit.integration.junit5.JMockitExtension;
import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith(JMockitExtension.class)
class MyTest {
@Mocked
Object myObject;
void test() {
new Expectations() {{
}
private void test() {
myObject.wait(anyLong);
}
};
myObject.wait(1L);
}
}
""",
"""
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class MyTest {
@Mock
Object myObject;
void test() {
new Expectations() {{
}
private void test() {
myObject.wait(anyLong);
}
};
myObject.wait(1L);
}
}
"""
)
);
}
Caused by: java.lang.ClassCastException: class org.openrewrite.java.tree.J$MethodDeclaration cannot be cast to class org.openrewrite.java.tree.J$Block (org.openrewrite.java.tree.J$MethodDeclaration and org.openrewrite.java.tree.J$Block are in unnamed module of loader 'app') at org.openrewrite.java.testing.jmockit.SetupStatementsRewriter.rewriteMethodBody(SetupStatementsRewriter.java:68) at org.openrewrite.java.testing.jmockit.JMockitBlockToMockito$RewriteJMockitBlockVisitor.visitMethodDeclaration(JMockitBlockToMockito.java:69) at org.openrewrite.java.testing.jmockit.JMockitBlockToMockito$RewriteJMockitBlockVisitor.visitMethodDeclaration(JMockitBlockToMockito.java:59) at org.openrewrite.java.tree.J$MethodDeclaration.acceptJava(J.java:3651) at org.openrewrite.java.tree.J.accept(J.java:59) at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250) ... 49 more
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a multi-module project.
What is the smallest, simplest way to reproduce the problem?
What did you see instead?
Caused by: java.lang.ClassCastException: class org.openrewrite.java.tree.J$FieldAccess cannot be cast to class org.openrewrite.java.tree.J$Identifier (org.openrewrite.java.tree.J$FieldAccess and org.openrewrite.java.tree.J$Identifier are in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @201fd61a)
What is the full stack trace of any errors you encountered?
Are you interested in [contributing a fix to OpenRewrite]
don't know if i'm able