📄 mockedsessionbeanunittest.java
字号:
package com.ejb3unit.sessionbeantests;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.jmock.Expectations;
import com.bm.testsuite.mocked.MockedSessionBeanFixture;
import com.ejb3unit.AnnotatedFieldSessionBean;
import com.ejb3unit.IMySessionBean;
/**
* Testcase for testng session beans as mocked objects.
*
* @author Daniel Wiese
*
*/
public class MockedSessionBeanUnitTest extends
MockedSessionBeanFixture<AnnotatedFieldSessionBean> {
private static final class MockedDataSource implements DataSource {
public Connection getConnection() throws SQLException {
return null;
}
public Connection getConnection(String arg0, String arg1)
throws SQLException {
return null;
}
public PrintWriter getLogWriter() throws SQLException {
return null;
}
public void setLogWriter(PrintWriter arg0) throws SQLException {
}
public void setLoginTimeout(int arg0) throws SQLException {
}
public int getLoginTimeout() throws SQLException {
return 0;
}
public boolean isWrapperFor(Class<?> arg0) throws SQLException {
return false;
}
public <T> T unwrap(Class<T> arg0) throws SQLException {
return null;
}
}
/**
* Constructor.
*/
public MockedSessionBeanUnitTest() {
super(AnnotatedFieldSessionBean.class);
}
/**
* Testmethod.
*/
public void test_executeOperation() {
AnnotatedFieldSessionBean toTest = this.getBeanToTest();
assertNotNull(toTest);
final IMySessionBean mySessionBean = this.getMock(IMySessionBean.class);
assertNotNull(mySessionBean);
final DataSource ds = new MockedDataSource();
// instrument mock
this.context.checking(new Expectations() {
{
this.one(mySessionBean).getDs();
will(returnValue(ds));
}
});
// call the expected operation
toTest.executeOperation();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -