Untitled

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

import com.abbvie.pro.core.components.models.SocialShareModel;
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.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

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

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

    private final AemContext aemContext = new AemContext();

    @Mock
    private IFormatterService iFormatterService;

    SocialShareModel 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");
    }

    @Test
    void getListItems() {

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

    @Test
    void  getPageUrl(){
        socialShareModel = aemContext.request().adaptTo(SocialShareModel.class);
        when(socialShareModel.getPageUrl()).thenReturn("/localhost");
        assertEquals("/localhost", socialShareModel.getPageUrl());
    }


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