0

When I debug the File as Junit then it will throw exception couldn't figure it out ...

package com.fort313.webexmd.test;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import com.fort313.webexmd.dao.base.AbstractBaseDAO;
import com.fort313.webexmd.daos.AdminDao;
import com.fort313.webexmd.entities.AdminEntity;
import com.fort313.webexmd.entities.ResultList;

@ContextConfiguration(locations = "classpath:/WEB-INF/testSpring/spring-web-config-test.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class TestAdminDao extends AbstractBaseDAO<AdminEntity, Long> {

     @Autowired
        private AdminDao adminDao;
       
     @Test
        @Transactional
        @Rollback(true)
        public void testGetAll() {
             @SuppressWarnings("unchecked")
               ResultList<AdminEntity> list =adminDao.getAll();
               System.out.println(list.getTotalRecords());
               Assert.assertNotNull(list);
               Assert.assertEquals(1,list.getTotalRecords());
             
        }
}
java.lang.NoSuchMethodError: org.springframework.util.Assert.notNull(Ljava/lang/Object;Ljava/util/function/Supplier;)V
        at org.springframework.test.context.support.ContextLoaderUtils.resolveContextConfigurationAttributes(ContextLoaderUtils.java:244)
        at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:295)
        at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:108)
        at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:137)
        at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:122)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:151)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:142)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
        at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
        at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
        at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
akuma8
  • 4,160
  • 5
  • 46
  • 82
Asad Malik
  • 1
  • 1
  • 2
  • Are all spring jars on your class path of the same version? – Serge Jul 10 '20 at 14:47
  • almost same version 4.3.3 but spring-integration-http :version:2.1.0.RELEASE ,spring-integration-core :version :4.1.4.RELEASE spring-test :version :5.2.7.RELEASE is different – Asad Malik Jul 10 '20 at 14:52
  • There seems to be an older version of spring core (before java 8) on the class path. It should be removed and/or replaced with the new spring core jar. – Serge Jul 10 '20 at 18:10
  • 1
    i have solved this problem by adding test-spring maven same version of spring-core and other spring maven dependency now they all are same version. but now this kind of exception occur ............................................................................... Unsatisfied dependency expressed through field 'adminDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean found for dependency [com.fort313.webexmd.daos.AdminDao]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: – Asad Malik Jul 13 '20 at 23:37
  • Is your AdminDao class defined as a bean in the spring test config file? – Serge Jul 14 '20 at 05:24
  • Now i don't use springconfig.xml but @ContextConfiguration(classes = {HibernateConfiguration.class}) ... in HibernateConfigiuration i use componentscan and use all packages of my project where adminDao package is included. but still problem is same – Asad Malik Jul 16 '20 at 23:43
  • You'll find the list of all initialized beans in the spring application context. Most likely, the component scan is not configured correctly, and AdminDao is not initialized. – Serge Jul 17 '20 at 20:40

0 Answers0