spring - java.lang.ExceptionInInitializerError at UserDaoImpl.<clinit>(UserDaoImpl.java:71) -
it's testhelper:
@runwith(springjunit4classrunner.class) @contextconfiguration(locations = { "classpath*:web-inf/spring/appservlet/servlet-context.xml" }) public class testhelper { @mock private userdaoimpl userdaoimpl; @injectmocks private helper helper=new helper(); private mockmvc mockmvc; string msg = "success"; int status = 200; responsemessage message = new responsemessage(); @before public void setup() { mockitoannotations.initmocks(this); this.mockmvc = mockmvcbuilders.standalonesetup(helper).build(); } @test public void testcategories() throws exception { message = helper.getcategories(0); assertnotnull(message); assert.assertequals(status, message.getstatus()); assert.assertequals(msg, message.getmessage()); } }
it's helper class:
public class helper extends basehelper { @autowired private userdao userdao; private static final logger logger = loggerfactory .getlogger(helper.class); public responsemessage getcategories(int categoryid) { logger.info("**helper getcategories() entry*****"); responsemessage message; try { list<category> categories = userdao .getcategories(categoryid); string jsonconverted = utility .converttojsonstring(categories); com.fasterxml.jackson.databind.objectmapper mapper = new com.fasterxml.jackson.databind.objectmapper(); object obj = mapper .readvalue( jsonconverted, new typereference<list<category>>() { }); message = prepareresponse(obj, 200, "success"); } catch (exception e) { logger.error("****exception in helper getcategories() : " + e.getstacktrace()); message = prepareresponse( null, 500, e.getmessage()); } logger.info("***helper getcategories() exit****"); return message; } }
it's userdaoimpl class:
public class userdaoimpl implements userdao { private static properties applicationproperties; static { applicationproperties = utility.loadappproperties(); } public list<category> getcategories(int category_id) { session session = null; list<category> categories = null; try { session = sessionfactory.getcurrentsession(); logger.info("enter getcategories method's body"); transaction tx = session.begintransaction(); if (!utility.iszeroint(category_id)) { list list = session.createcriteria(category.class).add(restrictions.eq("category_id", category_id)) .setresulttransformer(criteria.distinct_root_entity).list(); categories = list; } else { list list = session.createcriteria(category.class).setresulttransformer(criteria.distinct_root_entity) .list(); categories = list; } tx.commit(); } catch (exception e) { throw new dataexception("unable categories. please try after time."); } logger.info("exit getcategories method's body"); return categories; } }
when test helper class got error on applicationproperties = utility.loadappproperties();
in userdaoimpl class. , error java.lang.exceptionininitializererror
. error generate @ time of load property file in userdaoimpl class.
this stack trace
java.lang.exceptionininitializererror @ com.zon.dao.userdaoimpl.<clinit>(userdaoimpl.java:71) @ sun.reflect.generatedserializationconstructoraccessor1.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ org.objenesis.instantiator.sun.sunreflectionfactoryinstantiator.newinstance(sunreflectionfactoryinstantiator.java:40) @ org.objenesis.objenesisbase.newinstance(objenesisbase.java:59) @ org.mockito.internal.creation.jmock.classimposterizer.createproxy(classimposterizer.java:111) @ org.mockito.internal.creation.jmock.classimposterizer.imposterise(classimposterizer.java:51) @ org.mockito.internal.util.mockutil.createmock(mockutil.java:54) @ org.mockito.internal.mockitocore.mock(mockitocore.java:44) @ org.mockito.mockito.mock(mockito.java:882) @ org.mockito.internal.configuration.defaultannotationengine.processannotationon(defaultannotationengine.java:59) @ org.mockito.internal.configuration.defaultannotationengine.createmockfor(defaultannotationengine.java:34) @ org.mockito.internal.configuration.defaultannotationengine.process(defaultannotationengine.java:84) @ org.mockito.internal.configuration.injectingannotationengine.process(injectingannotationengine.java:41) @ org.mockito.mockitoannotations.scan(mockitoannotations.java:110) @ org.mockito.mockitoannotations.initmocks(mockitoannotations.java:95) @ com.zon.testhelper.testhelper.setup(testhelper.java:64) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:44) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:15) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:41) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:27) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:76) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:50) @ org.junit.runners.parentrunner$3.run(parentrunner.java:193) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:52) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:191) @ org.junit.runners.parentrunner.access$000(parentrunner.java:42) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:184) @ org.junit.runners.parentrunner.run(parentrunner.java:236) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:86) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:459) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:675) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:382) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:192) caused by: java.lang.nullpointerexception @ java.util.properties$linereader.readline(unknown source) @ java.util.properties.load0(unknown source) @ java.util.properties.load(unknown source) @ com.zon.utils.utility.<clinit>(utility.java:27) ... 39 more
caused by: java.lang.nullpointerexception @ java.util.properties$linereader.readline(unknown source)
the above exception says not able find properties file.try put properties file @ root of classpath.
Comments
Post a Comment