import org.jmock.Expectations; import org.jmock.integration.junit4.JUnitRuleMockery; import org.jmock.lib.legacy.ClassImposteriser; import org.junit.Rule; import org.junit.Test; public class UserServiceTest { @Rule public JUnitRuleMockery context = new JUnitRuleMockery() {{ setImposteriser(ClassImposteriser.INSTANCE); }}; @Test public void testSendEmail() { final EmailService emailService = context.mock(EmailService.class); context.checking(new Expectations() {{ oneOf(emailService).sendEmail("test@example.com", "Hello, JMock!"); }}); UserService userService = new UserService(emailService); userService.sendWelcomeEmail("test@example.com"); context.assertIsSatisfied(); } } <dependency> <groupId>org.jmock</groupId> <artifactId>jmock-junit4</artifactId> <version>2.8.3</version> <scope>test</scope> </dependency>


上一篇:
下一篇:
切换中文