Created
October 8, 2018 17:56
-
-
Save davidjgonzalez/313d8f8cbadb5dc8af2d5e2dc8195401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.adobe.aem.guides.wknd.core.components.impl; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertFalse; | |
import static org.junit.Assert.assertNull; | |
import static org.junit.Assert.assertTrue; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.when; | |
import static org.mockito.Mockito.doReturn; | |
import static org.mockito.ArgumentMatchers.*; | |
import org.apache.sling.models.factory.ModelFactory; | |
import org.junit.Before; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.InjectMocks; | |
import org.mockito.Mock; | |
import org.mockito.junit.MockitoJUnitRunner; | |
import com.adobe.aem.guides.wknd.core.components.Card; | |
import com.adobe.cq.wcm.core.components.models.Image; | |
import io.wcm.testing.mock.aem.junit.AemContext; | |
@RunWith(MockitoJUnitRunner.class) | |
public class CardImplTest { | |
@Rule | |
public AemContext ctx = new AemContext(); | |
@Mock | |
ModelFactory modelFactory; | |
@Before | |
public void setUp() throws Exception { | |
ctx.addModelsForPackage(Card.class.getPackage().getName(), | |
Image.class.getPackage().getName()); | |
ctx.load().json("/components/card.json", "/content"); | |
} | |
@Test | |
public void testGetLinkPath() { | |
String expected = "/content/article-page"; | |
ctx.currentResource("/content/card"); | |
Card card = ctx.request().adaptTo(Card.class); | |
assertEquals(expected, card.getLinkPath()); | |
} | |
@Test | |
public void testGetImageSrc() { | |
final String expected = "/content/article-page/jcr:content/root/image.img.png"; | |
ctx.currentResource("/content/card"); | |
Image image = mock(Image.class); | |
doReturn(expected).when(image).getSrc(); | |
doReturn(image).when(modelFactory).getModelFromWrappedRequest(ctx.request(), | |
ctx.resourceResolver().getResource("/content/article-page/jcr:content/root/image"), | |
Image.class); | |
ctx.registerService(ModelFactory.class, modelFactory); | |
card = ctx.request().adaptTo(Card.class); | |
String actual = card.getImageSrc(); | |
assertEquals(expected, actual); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment