Created
December 8, 2016 21:10
-
-
Save yupadhyay/b73e8239f7dee0f2956cd93d338c9bc1 to your computer and use it in GitHub Desktop.
Class showing, how to activate a service with properties
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
//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