Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.5 kB
1
Indexable
Never
package com.abbvie.pro.core.components.internal.models.v1;

import com.abbvie.pro.core.components.models.SocialShareModel;
import com.day.cq.wcm.api.Page;
import com.abbvie.pro.core.services.IFormatterService;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import org.apache.sling.api.SlingHttpServletRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import javax.inject.Inject;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

@ExtendWith({AemContextExtension.class, MockitoExtension.class})
class SocialShareModelImplTest {

    private final AemContext aemContext = new AemContext();

    @Mock
    private IFormatterService iFormatterService;

    @Mock
    private SlingHttpServletRequest req;

    @Mock
    private Page page;

    @InjectMocks
    SocialShareModelImpl socialShareModel;


    @BeforeEach
    void setUp() {
        aemContext.addModelsForClasses(SocialShareModelImpl.class);
        aemContext.load().json("/com/abbvie/pro/core/components/socialShareModel.json", "/page");
        aemContext.registerService(IFormatterService.class,iFormatterService);
        aemContext.currentResource("/page/component_page");
        //when(socialShareModel.getPageUrl()).thenReturn("/localhost");


    }

/*    @Test
    void getListItems() {

        socialShareModel = aemContext.request().adaptTo(SocialShareModel.class);
        assertEquals(3, socialShareModel.getListItems().size());
    }*/

    @Test
    void getPageUrl(){
        //socialShareModel = aemContext.request().adaptTo(SocialShareModel.class);
        when(page.getPath()).thenReturn("/localhost");
        when(iFormatterService.getFormattedLink(anyString(), any(SlingHttpServletRequest.class))).thenReturn("/localhost");
        final String expected = "/localhost";
        assertEquals(expected, socialShareModel.getPageUrl());
    }

/*    @Test
    void getShareTitle() {
        socialShareModel = aemContext.request().adaptTo(SocialShareModel.class);
        final String expected = "Share Now:";
        String actual = socialShareModel.getShareTitle();
        assertEquals(expected, actual);
    }*/
}