@ -23,6 +23,9 @@ import java.net.UnknownHostException;
import org.junit.Before ;
import org.junit.Before ;
import org.junit.Test ;
import org.junit.Test ;
import org.junit.runner.RunWith ;
import org.mockito.Mock ;
import org.mockito.runners.MockitoJUnitRunner ;
import org.springframework.core.NestedRuntimeException ;
import org.springframework.core.NestedRuntimeException ;
import org.springframework.dao.DataAccessException ;
import org.springframework.dao.DataAccessException ;
import org.springframework.dao.DataAccessResourceFailureException ;
import org.springframework.dao.DataAccessResourceFailureException ;
@ -43,10 +46,13 @@ import com.mongodb.ServerAddress;
* @author Michal Vich
* @author Michal Vich
* @author Oliver Gierke
* @author Oliver Gierke
* /
* /
@RunWith ( MockitoJUnitRunner . class )
public class MongoExceptionTranslatorUnitTests {
public class MongoExceptionTranslatorUnitTests {
MongoExceptionTranslator translator ;
MongoExceptionTranslator translator ;
@Mock DuplicateKey exception ;
@Before
@Before
public void setUp ( ) {
public void setUp ( ) {
translator = new MongoExceptionTranslator ( ) ;
translator = new MongoExceptionTranslator ( ) ;
@ -55,10 +61,8 @@ public class MongoExceptionTranslatorUnitTests {
@Test
@Test
public void translateDuplicateKey ( ) {
public void translateDuplicateKey ( ) {
DuplicateKey exception = new DuplicateKey ( 1 , "Duplicated key" ) ;
DataAccessException translatedException = translator . translateExceptionIfPossible ( exception ) ;
DataAccessException translatedException = translator . translateExceptionIfPossible ( exception ) ;
expectExceptionWithCauseMessage ( translatedException , DuplicateKeyException . class , null ) ;
expectExceptionWithCauseMessage ( translatedException , DuplicateKeyException . class , "Duplicated key" ) ;
}
}
@Test
@Test