当前位置: 首页>>代码示例>>Java>>正文


Java DependencyManager类代码示例

本文整理汇总了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);
}
 
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:37,代码来源:MyServiceUserTest.java

示例2: getNumberOfPersons

import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
public int getNumberOfPersons() {
	MyService myService = DependencyManager.getInstance().getMyService();
	Set<Person> allPersons = myService.getAllPersons();
	return allPersons.size();
}
 
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:6,代码来源:MyServiceUser.java

示例3: setUp

import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
@Before
public void setUp() {
	tested = new MyServiceUser();
	dependencyManagerMock = createMock(DependencyManager.class);
	myServiceMock = createMock(MyService.class);
}
 
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:7,代码来源:MyServiceUserTest.java

示例4: replayAll

import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
public void replayAll() throws Exception {
	replay(DependencyManager.class, dependencyManagerMock, myServiceMock);
}
 
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:4,代码来源:MyServiceUserTest.java

示例5: verifyAll

import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
public void verifyAll() {
	verify(DependencyManager.class, dependencyManagerMock, myServiceMock);
}
 
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:4,代码来源:MyServiceUserTest.java

示例6: getNumberOfPersons

import powermock.examples.dependencymanagement.DependencyManager; //导入依赖的package包/类
public int getNumberOfPersons()
{
   MyService myService = DependencyManager.getInstance().getMyService();
   Set<Person> allPersons = myService.getAllPersons();
   return allPersons.size();
}
 
开发者ID:royosherove,项目名称:javatdddemo,代码行数:7,代码来源:MyServiceUser.java


注:本文中的powermock.examples.dependencymanagement.DependencyManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。