Spock framework throwing error while mocking a #component - spring

I am using Spock with Spring and I am getting error while mocking one of my component class.
Please find the below stack trace.
It has nothing more than this and I thus I am not able to proceed.
Versions:
cglib-nodep : 3.2.0
cglib : 3.2.0
spock-core : 1.0-groovy-2.4
spring-test : 4.1.4.RELEASE
java.lang.NoClassDefFoundError: Could not initialize class org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory$ConstructorFriendlyEnhancer
at org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory.createMock(ProxyBasedMockFactory.java:80)
at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:49)
at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:51)
at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:45)
at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:281)
at org.spockframework.lang.SpecInternals.MockImpl(SpecInternals.java:99)
at TermsAndConditionsControllerAPISpec.setup(TermsAndConditionsControllerAPISpec.groovy:19)

Not sure why this happened but I just removed cglib and it just worked.
So final dependency list was :
cglib-nodep : 3.2.0
spock-core : 1.0-groovy-2.4
spring-test : 4.1.4.RELEASE
I am still not sure why this worked by removing cglib. In case someone has a detailed reason for this please share.

Related

Spring boot testing : NoClassDefFound exception

I'm using the latest version of Spring boot and an old test fails.
I'm having
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class
Caused by: java.lang.NoClassDefFoundError: MyClass
My config is
spring boot 2.7.2
gradle 7.5
a structure using idiomatic gradle (multiproject and composite build)
The subproject failing is the spring-boot-application. The class not found exists inside the src/main/java
The test failing is under src/test/java, annotated with
#SpringJUnitConfig(classes = ApplicationServiceAspectTestConfigSuccessListener.class) because it is using #Inject fields.
I understand it is not perfect (unit testing depending on injection ; prefer integration test)
When I debug this test, the classloader tries to use a JarLoader and searches inside the spring-boot-application-default.jar. The jar structure is BOOT-INF / META-INF / org... The class not found is inside the BOOT-INF/classes/org/xxxx. The jar loader failed :/
My question is : why searching inside the jar and not the build/classes/org/xxx ? and why is the JarLoader not finding the class ?
Update 1
I think I have a lead. I created a gradle precompiles quality plugins which uses java-text-fixtures. When enable the java-text-fixtures produces two jars and the problem comes from here.
I don't really understand why for the moment (why 2 jars and not only the text-fixtures one).
Update 2
Ok seems I ran across https://github.com/gradle/gradle/issues/11696

Mockito issue w.r.t spring boot upgrade

We are facing an issue with Mockito post spring boot version upgrade
Following is the configuration
Mockito-all : 1.10.19
PowerMockito : 1.6.2
SpringBootVersion : 2.6.3
Junit : 4.12
Hamcrest-all : 1.3
Reported exception:
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at com.example.Sample(sample.java:109)
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod();
I tried changing versions of mockito from 1.1 to 1.10.19 and even with powermockito as well but it doesnt help. error keeps coming.

Spring core compatibilty issues with security and aop

Is there a specific version of spring core that is compatible with spring security and aop?
I tried these version but still getting error
org.springframework version : 4.0.3.RELEASE
org.springframework.security version : 3.2.0.RELEASE
error : missing CompositeUriComponentsContributor
org.springframework version : 4.0.3.RELEASE
org.springframework.security version : 4.0.3.RELEASE
error : missing AnnotationConfigRegistry
org.springframework version : 4.2.2.RELEASE
org.springframework.security version : 4.0.1.RELEASE
error : missing CorsProcessor
Reference documentation of Spring Security 4.0.4 states:
Spring Security builds against Spring Framework 4.2.5.RELEASE, but
should work with 4.0.x.
Releases of Spring Security are not aligned with releases of Spring Framework.
However, dependencies spring-core and spring-aop (both belonging to Spring Framework) should always be the same version.

EnvironmentCapable Not available Spring 3.2.3

Am trying to integrate Spring 3.2.3 with JSF 2.2.1 and getting an error like Caused by: java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable The class is available in my classpath (spring-core-3.2.3.RELEASE.jar) but not sure why this error occurs.
It worked fine when I removed the project from the server, clean/build and restarted again. Thanks.

Grails 1.2.1 with Spring 3.0.0 dependency problem under Jetty

Just moved to Grails 1.2.1 (used 1.1.1 before). Changed application.properties, ran grails upgrade, fixed BuildConfig and Bootstrap - everything works just fine from grails console.
However, getting a problem when deploy packaged war under jetty 6.1.22:
1581 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.setParameterNameDiscoverer(Lorg/springframework/core/ParameterNameDiscoverer;)V
My project is built with maven2. I researched the war dependencies and see that both spring 2.5.6 and 3.0.0.RELEASE are used there.
I then tried to suppress use of spring 2.5.6 and got a problem with Acegi plugin (using version 0.5.1):
2010-03-10 21:06:56.440:WARN::Nested in org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId(Ljava/lang/String;)V
Any help would be greatly appreciated.
The problem is caused by the fact that in new version of Spring
ConfigurableWebApplicationContext is located in spring-web.jar, but the interface it inherits ConfigurableApplicationContext, which contains setId(String) method is in located in spring-context.jar.
If you have a library which has been compiled against older version of spring-context it will fail with NoMethodFound exception.
The solution is to locate and recompile that library against latest Spring version.
If you are using Spring version below 3.0 you could try to put full Spring bundle Jar instead of separate packages.

Resources