Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JAVA-757: Reverting behavioral change to CommandResult.getException. …

…It now returns null, as before, if there is no exception, instead of throwing IllegalStateException.
  • Loading branch information...
commit 84532013ef3048e7d8d0dc42df10207d71254f08 1 parent 254eb70
Jeff Yemin jyemin authored
2  src/main/com/mongodb/CommandResult.java
View
@@ -78,7 +78,7 @@ public MongoException getException() {
}
}
- throw new IllegalStateException("This method should not be called if there is no exception");
+ return null;
}
/**
9 src/test/com/mongodb/CommandResultTest.java
View
@@ -23,9 +23,17 @@
public class CommandResultTest extends TestCase {
@Test
+ public void testOkCommandResult() throws UnknownHostException {
+ CommandResult commandResult = new CommandResult(new ServerAddress("localhost"));
+ commandResult.put("ok", 1);
+ assertNull(commandResult.getException());
+ }
+
+ @Test
public void testNullErrorCode() throws UnknownHostException {
CommandResult commandResult = new CommandResult(new ServerAddress("localhost"));
commandResult.put("ok", 0);
+ assertEquals(CommandFailureException.class, commandResult.getException().getClass());
try {
commandResult.throwOnError();
fail("Should throw");
@@ -40,6 +48,7 @@ public void testCommandFailure() throws UnknownHostException {
CommandResult commandResult = new CommandResult(new ServerAddress("localhost"));
final DBObject result = new BasicDBObject("ok", 0.0).append("errmsg", "no not found").append("code", 5000);
commandResult.putAll(result);
+ assertEquals(CommandFailureException.class, commandResult.getException().getClass());
try {
commandResult.throwOnError();
fail("Should throw");
Please sign in to comment.
Something went wrong with that request. Please try again.