1717
1818import static org .assertj .core .api .Assertions .*;
1919
20- import java .net .UnknownHostException ;
20+ import com .mongodb .MongoSocketReadTimeoutException ;
21+ import com .mongodb .MongoSocketWriteException ;
2122
2223import org .bson .BsonDocument ;
2324import org .junit .jupiter .api .BeforeEach ;
4546 * @author Michal Vich
4647 * @author Oliver Gierke
4748 * @author Christoph Strobl
49+ * @author Brice Vandeputte
4850 */
4951public class MongoExceptionTranslatorUnitTests {
5052
53+ public static final String EXCEPTION_MESSAGE = "IOException" ;
5154 MongoExceptionTranslator translator ;
5255
5356 @ BeforeEach
@@ -68,13 +71,30 @@ public void translateDuplicateKey() {
6871 public void translateSocketException () {
6972
7073 expectExceptionWithCauseMessage (
71- translator .translateExceptionIfPossible (new MongoSocketException ("IOException" , new ServerAddress ())),
72- DataAccessResourceFailureException .class , "IOException" );
74+ translator .translateExceptionIfPossible (new MongoSocketException (EXCEPTION_MESSAGE , new ServerAddress ())),
75+ DataAccessResourceFailureException .class , EXCEPTION_MESSAGE );
76+
77+ }
78+
79+ @ Test // GH-3568
80+ public void translateSocketChildrenExceptions () {
81+
82+ expectExceptionWithCauseMessage (
83+ translator .translateExceptionIfPossible (
84+ new MongoSocketWriteException ("intermediate message" , new ServerAddress (), new Exception (EXCEPTION_MESSAGE ))
85+ ),
86+ DataAccessResourceFailureException .class , EXCEPTION_MESSAGE );
87+
88+ expectExceptionWithCauseMessage (
89+ translator .translateExceptionIfPossible (
90+ new MongoSocketReadTimeoutException ("intermediate message" , new ServerAddress (), new Exception (EXCEPTION_MESSAGE ))
91+ ),
92+ DataAccessResourceFailureException .class , EXCEPTION_MESSAGE );
7393
7494 }
7595
7696 @ Test
77- public void translateCursorNotFound () throws UnknownHostException {
97+ public void translateCursorNotFound () {
7898
7999 expectExceptionWithCauseMessage (
80100 translator .translateExceptionIfPossible (new MongoCursorNotFoundException (1L , new ServerAddress ())),
0 commit comments