Expand my Community achievements bar.

Exception while trying to run simple test with WCM

Avatar

Former Community Member

Hi! I'm trying to make a dumb test with wcm, but I get an exception and I have no clue what is wrong

 

public class ComponentFooterTest { @Rule public final AemContext context = new AemContext(); private ComponentFooter componentFooter; @Before public void setUp(){ PageContext pageContext = Mockito.mock(PageContext.class); this.componentFooter = new ComponentFooter(pageContext); } @Test public void testSomething() { assert 1 == 1; } }

 

This is the stacktrace I'm getting:

 

java.lang.ClassCastException: org.apache.sling.testing.mock.osgi.MockServiceReference cannot be cast to java.lang.Comparable at java.util.TreeMap.compare(TreeMap.java:1290) at java.util.TreeMap.put(TreeMap.java:538) at java.util.TreeSet.add(TreeSet.java:255) at org.apache.sling.testing.mock.osgi.MockBundleContext.getServiceReferences(MockBundleContext.java:279) at org.apache.sling.testing.mock.osgi.MockBundleContext.getServiceReference(MockBundleContext.java:256) at org.apache.sling.testing.mock.osgi.MockOsgi.getConfigAdmin(MockOsgi.java:288) at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:167) at org.apache.sling.testing.mock.osgi.MockOsgi.activate(MockOsgi.java:180) at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:154) at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:141) at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerDefaultServices(OsgiContextImpl.java:66) at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.setUp(OsgiContextImpl.java:47) at org.apache.sling.testing.mock.sling.context.SlingContextImpl.setUp(SlingContextImpl.java:121) at io.wcm.testing.mock.aem.context.AemContextImpl.setUp(AemContextImpl.java:74) at io.wcm.testing.mock.aem.junit.AemContext.access$100(AemContext.java:48) at io.wcm.testing.mock.aem.junit.AemContext$1.before(AemContext.java:156) at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:44) at org.junit.rules.RunRules.evaluate(RunRules.java:18) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)

 

 

Any clue?

 

Thanks.

1 Reply

Avatar

Level 10

Take a look at this community article - it may be helpful.

http://aempodcast.com/2015/testing/unit-testing-wcmuse-classes-using-mockito/#.WI-0xRsrJaQ

We are going to add testing. JUNIT testing, etc to our Ask the AEM Community Webinars series.