Help with JUnit Test for AEM Sling Model
I'm trying to write unit tests for an AEM Sling Model, but my test is failing. Here's the test I tried:
@RunWith(MockitoJUnitRunner.class)
public class ArticleContentModelTest {
@Rule
public AemContext context = new AemContext();
private ArticleContentModel articleContentModel;
@Before
public void setUp() {
context.create().resource("/content/article", "title", "Sample Article", "body", "This is a sample article body.");
articleContentModel = context.request().adaptTo(ArticleContentModel.class);
}
@2785667
public void testGetTitle() {
assertEquals("Sample Article", articleContentModel.getTitle());
}
@2785667
public void testGetBody() {
assertEquals("This is a sample article body.", articleContentModel.getBody());
}
}
I am getting a NullPointerException when trying to assert the title and body in the tests. I have checked that the resource exists, and the ArticleContentModel should have been adapted correctly, but something is wrong.

