Skip to content

Instantly share code, notes, and snippets.

@yupadhyay
Created December 8, 2016 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yupadhyay/b73e8239f7dee0f2956cd93d338c9bc1 to your computer and use it in GitHub Desktop.
Save yupadhyay/b73e8239f7dee0f2956cd93d338c9bc1 to your computer and use it in GitHub Desktop.
Class showing, how to activate a service with properties
//Method 1, By using Inject Mock
@RunWith(PowerMockRunner.class)
@PrepareForTest(MyServiceImpl.class)
public class MyServiceImplTest {
@InjectMocks
MyServiceImpl _myService;
@Before
public void setUp() throws Exception {
_config = new HashMap<Object, Object>();
_config.put("test1", "test1");
_config.put("test2", "test3");
}
@Test
public void someTest() {
myService.activate(_config);
assertEquals("test", something.yourMethod());
}
}
//Method 2 using AEM context
public class MyServiceImplTest {
MyServiceImpl _myService;
@Rule
public final AemContext aemContext = new AemContext();
@Before
public void setUp() throws Exception {
_config = new HashMap<Object, Object>();
_config.put("test1", "test1");
_config.put("test2", "test3");
_myService = aemContext.registerInjectActivateService(new MyServiceImpl(), _config);
}
@Test
public void someTest() {
assertEquals("test", _myService.yourMethod());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment