本文整理汇总了Java中powermock.examples.dependencymanagement.DependencyManager类的典型用法代码示例。如果您正苦于以下问题:Java DependencyManager类的具体用法?Java DependencyManager怎么用?Java DependencyManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DependencyManager类属于powermock.examples.dependencymanagement包,在下文中一共展示了DependencyManager类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetNumberOfPersons
import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
/**
* Unit test for the {@link MyServiceImpl#getAllPersons()} method. This
* tests demonstrate how to mock the static call to
* {@link DependencyManager#getInstance()} and returning a mock of the
* <code>DependencyManager</code> instead of the real instance.
*/
@Test
public void testGetNumberOfPersons() throws Exception {
/*
* This is how to tell PowerMock to prepare the DependencyManager class
* for static mocking.
*/
mockStatic(DependencyManager.class);
/*
* Expectations are performed the same for static methods as for
* instance methods.
*/
expect(DependencyManager.getInstance()).andReturn(dependencyManagerMock);
expect(dependencyManagerMock.getMyService()).andReturn(myServiceMock);
Set<Person> persons = new HashSet<Person>();
persons.add(new Person("Johan", "Haleby", "MockStreet"));
persons.add(new Person("Jan", "Kronquist", "MockStreet2"));
expect(myServiceMock.getAllPersons()).andReturn(persons);
replayAll();
int numberOfPersons = tested.getNumberOfPersons();
verifyAll();
assertEquals(2, numberOfPersons);
}
示例2: getNumberOfPersons
import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
public int getNumberOfPersons() {
MyService myService = DependencyManager.getInstance().getMyService();
Set<Person> allPersons = myService.getAllPersons();
return allPersons.size();
}
示例3: setUp
import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
@Before
public void setUp() {
tested = new MyServiceUser();
dependencyManagerMock = createMock(DependencyManager.class);
myServiceMock = createMock(MyService.class);
}
示例4: replayAll
import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
public void replayAll() throws Exception {
replay(DependencyManager.class, dependencyManagerMock, myServiceMock);
}
示例5: verifyAll
import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
public void verifyAll() {
verify(DependencyManager.class, dependencyManagerMock, myServiceMock);
}
示例6: getNumberOfPersons
import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
public int getNumberOfPersons()
{
MyService myService = DependencyManager.getInstance().getMyService();
Set<Person> allPersons = myService.getAllPersons();
return allPersons.size();
}