Monday 15 February 2010

java - Mocking ResourceLoading with JMockit -


My application uses a singleton consisting of config settings .getResourceAsStream ( "application.properties")

  Personal PropertiesSingleton () throws exceptions {InputStream appstream = this.getClass () getClassLoader () ;: This is the code. Sahara = new property (); Try {props.load (epstream); } Hold (IOE EXPRESS E) {logger.log (log.fatt, "application can not be found in classpath.", E); Throw e }}   

Normally my application runs inside the container. I have to apply for my single. Properties are available for loading. I tried to do this:

  @ throws an exception in the first public zero init (final file inputstream instream = new file intstream ("../ path / copy / config / app. Properties "); New Non-Street Expectations (Classloader. Class) {{String.class.getClassLoader (). GetResourceAsStream ("application.properties"); Result = instream; }}; }   

trial begins but will print the stacktrace:

  sun.instrument.InstrumentationImpl.redefineClasses0 (Native Method). De.lpm.ejb.archiving.ArchiveHandlerBeanTest $ 2. on VerifyError & lt; Init & gt; sun.reflect.NativeMethodAccessorImpl.invoke0 on (ArchiveHandlerBeanTest.java:50) on de.lpm.ejb.archiving.ArchiveHandlerBeanTest.init (ArchiveHandlerBeanTest.java:50) (java.lang.reflect.Method.invoke (Method.java:597 on org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference on java.lang.reflect.Method.invoke (Method.java:597) Basic Law on sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method))). Run at org.eclipse.jdt.internal.junit.runner.TestExecution.run (TestExecution.java:38) (JUnit4TestReference.java:46) at org.eclipse. jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:467) org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:683) on org.eclipse.jdt.internal. junit.runner.RemoteTes on tRunner.run org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (RemoteTestRunner.java:390) (RemoteTestRunner.java:197)    

I believe that this class is not a fake copy of the loader because it is the first one. You can not do the luggage before the class loader comes into existence. So try copying the collars, not the square loader.

No comments:

Post a Comment