Level 1
Level 2
Sign in to Community
Learn more
Sign in to view all badges
Expand my Community achievements bar.
This conversation has been locked due to inactivity. Please create a new post.
I am trying to Mock SlingSettingsService with run modes in Junit5.
In my h.java file, in Activate method I have.
srun = slingSettingsService.getRunModes().contains("runMode");How do I mock this in my htest.java file? This is for Junit5.
Solved! Go to Solution.
@baw_gov,
you can do something like this:
@ExtendWith(AemContextExtension.class) public class ExampleTest { private final AemContext context = new AemContext(); Set<String> mockRunModes = new TreeSet<String>(); @Mock private SlingSettingsService slingSettingsService; @Before public void before() { when(slingSettingsService.getRunModes()).thenReturn(mockRunModes); } @Test public void testSomething() { mockRunModes.add("publish"); Resource resource = context.resourceResolver().getResource("/content/sample/en"); Page page = resource.adaptTo(MyClass.class); // further testing } }
View solution in original post
Please check below articles:
https://exadel.com/news/aem-tip-junit-aemcontext-integration-with-an-aem-repository/
https://aem4beginner.blogspot.com/aem-mocks
Views
Likes
Replies