如何编写基于Mockito的JUnit方法来测试此方法adduser()?我尝试写一个,但它失败了一条错误消息,说不处理异常.显示错误:
when(service.addUser("nginx")).thenReturn("apache");
Run Code Online (Sandbox Code Playgroud)
假设addUser()业务类中的方法永远不会捕获任何异常,并且不会重新抛出.
class Business {
public User addUser() throws ServiceException{
User user = service.addUser("nginx");
return user;
}
}
Run Code Online (Sandbox Code Playgroud)
测试案例方法:
在测试类中,我使用@Mock属性模拟服务层类并注入它.
@Mock
Service service;
@InjectMocks
Business business = new Business();
@Test
public void testAddUser() {
when(service.addUser("nginx")).thenReturn("apache");
User user = business.addUser("nginx");
assertNotNull(user);
}
Run Code Online (Sandbox Code Playgroud)
请告诉我如何处理测试用例中的异常情况.
我在服务层有一个方法,它对数据库执行更新功能.
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void update(final Object obj){
// some code here
}
Run Code Online (Sandbox Code Playgroud)
现在我想知道Spring框架设置的这个方法的隔离级别是什么?
我是Spring的新手,只是想让自己适应交易.
请分享一些最佳实践和方法来设置隔离级别以避免死锁,从而防止同一用户尝试从不同的浏览器更新其记录.
我使用以下设置在JBoss EAP服务器中部署了Spring应用程序:
<bean:bean id="userDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<bean:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<bean:property name="url" value="jdbc:oracle:thin:@10.8.1.5:1521:DB"/>
<bean:property name="username" value="WEBDB"/>
<bean:property name="password" value="WEBDB"/>
</bean:bean>
Run Code Online (Sandbox Code Playgroud)
如何配置连接池的最小和最大大小?
BasicDataSource的任何参考或任何最佳实践都将有很大帮助.
spring database-connection connection-pooling apache-commons-dbcp