dimanche 25 juin 2017

java.lang.VerifyError:Constructor must call super() or this()

While creating test cases, I encountered with some unknown error as below :

java.lang.VerifyError: (class: com/day/cq/commons/ValueMapWrapper, method: <init> signature: (Lorg/apache/sling/api/resource/ValueMap;)V) Constructor must call super() or this()

Below is my test class :

    import com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap;
    import com.day.cq.commons.inherit.InheritanceValueMap;
    import com.day.cq.wcm.api.Page;
    import org.apache.sling.api.SlingHttpServletRequest;
    import org.apache.sling.api.resource.Resource;
    import org.apache.sling.api.resource.ResourceResolver;


    import org.apache.sling.api.resource.ValueMap;
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.mockito.InjectMocks;
    import org.mockito.Mock;
    import org.mockito.internal.util.reflection.Whitebox;
    import org.mockito.runners.MockitoJUnitRunner;
    import org.powermock.api.mockito.PowerMockito;


    import static org.hamcrest.MatcherAssert.assertThat;
    import static org.hamcrest.core.Is.is;
    import static org.mockito.Mockito.when;


    @RunWith(MockitoJUnitRunner.class)
    public class bannersTest {
        @Mock
        private Resource currentResource;
        @InjectMocks
        private Banners banners;
        @Mock
        private SlingHttpServletRequest request;
        @Mock
        private ResourceResolver resourceResolver;
        @Mock
        private Resource resource;
        @Mock
        private Page currentPage;
        @Mock
        private ValueMap valueMap;
        @Before
        public void setup() {
            Whitebox.setInternalState(banners, "widthOfbanner",
                    "75px");
            Whitebox.setInternalState(banners, "heightOfbanner",
                    "auto");
            Whitebox.setInternalState(banners, "request", request);
        }
        @Test
        public void testInit() {
            when(request.getResourceResolver()).thenReturn(resourceResolver);
            when(resource.getResourceResolver()).thenReturn(resourceResolver);
            when(currentPage.getPath()).thenReturn("/content/myApp/en/page1");
            when(resourceResolver.resolve(currentPage.getPath())).thenReturn(currentResource);
            when(currentResource.getValueMap()).thenReturn(valueMap);
            when(valueMap.get("bannerWidth")).thenReturn("75px");
            when(currentResource.getValueMap()).thenReturn(valueMap);
            HierarchyNodeInheritanceValueMap map = PowerMockito.spy(new HierarchyNodeInheritanceValueMap(currentResource));
            assertThat(map instanceof InheritanceValueMap, is(true));
            when(map.getInherited("bannerWidth" , "")).thenReturn("75px");
            banners.init();
        }
    }

public class Banners {
 //getter-setters for width
 @Override
    protected void init() {
        final String siteDefaultbannerWidth = StringUtils.defaultIfEmpty(getInheritedProperty("bannerWidth"), WCMConstants.DEFAULT_banner_WIDTH);
        widthOfbanner = StringUtils.defaultIfEmpty(currentPage.getProperties().get("bannerWidth", String.class), siteDefaultbannerWidth);
    }

Below is class I am trying to test:

    protected String getInheritedProperty(final String propName) {
        final ResourceResolver resolver = request.getResourceResolver();
        final Resource currentResource = resolver.resolve(currentPage.getPath());
        final InheritanceValueMap iProperties = new HierarchyNodeInheritanceValueMap(currentResource); // Test Case Breaks Here
        return iProperties.getInherited(propName, StringUtils.EMPTY);
    }
}

Any idea, how can I pass through the line

  final InheritanceValueMap iProperties = new HierarchyNodeInheritanceValueMap(currentResource);

where test case breaks.

Thanks,

Aucun commentaire:

Enregistrer un commentaire