Mocking the UIInput Class for Tests

I am trying to make fun of the javax.faces.component.UIInput class.

My class is lower

public class MyBean{ private UIInput someInput; //setters and getters } 

Test case

 UIInput mockedVale = Mockito.mock(UIInput.class); MyBean myBean = new MyBean(); myBean.setSomeInput(mockedVale); 

Can someone help me fix this

 java.lang.ExceptionInInitializerError at sun.reflect.GeneratedSerializationConstructorAccessor3.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:45) at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73) at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:142) at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:61) at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:52) at org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:24) at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:32) at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59) at org.mockito.Mockito.mock(Mockito.java:1258) at org.mockito.Mockito.mock(Mockito.java:1135) at se.telenor.ocfd.web.facade.MyBean.<init>(MyBean.java:28) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.util.MissingResourceException: Can't find javax.faces.LogStrings bundle at java.util.logging.Logger.setupResourceInfo(Logger.java:1945) at java.util.logging.Logger.<init>(Logger.java:380) at java.util.logging.LogManager.demandLogger(LogManager.java:554) at java.util.logging.Logger.demandLogger(Logger.java:455) at java.util.logging.Logger.getLogger(Logger.java:553) at javax.faces.component.UIComponent.<clinit>(UIComponent.java:116) ... 35 more 
+5
source share
3 answers

In the UIComponent class (which uses your test) there is a static line to initialize Logger :

 private static Logger LOGGER = Logger.getLogger("javax.faces.component", "javax.faces.LogStrings"); 

This means that the class is looking for a resource package named LogStrings in the javax.faces package. In javax.faces-2.2.11.jar there is the javax directory and subdirectory and inside it is the LogStrings.properties file. Therefore, your class is also looking for this file.

Is face-jar inside your classpath?

+3
source

As stated in the Niklas P. answer , the cause of the problem is the initialization of Logger on the UIComponent .

To solve the problem, jsf-api-xxx.jar should be included in your project. As described here about using jsf-api-xxx.jar or javax.faces-xxx.jar (portability considerations):

You can actually use both. But the recommended way is to include jsf-api-xxx.jar only in the compilation class path.

In Maven, you just need to add the following dependency to your pom.xml :

 <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.2.8-18</version><!-- the version you are using --> <scope>provided</scope> </dependency> 
+2
source

I used this additional Maven dependency on the test area ( pom.xml ):

  <dependency> <groupId>javax.faces</groupId> <artifactId>javax.faces-api</artifactId> <version>2.2</version> <scope>test</scope> </dependency> 
0
source

All Articles