-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle missing error code (0 as default)
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/com/contentstack/sdk/CSHttpConnectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.contentstack.sdk; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CSHttpConnectionTest { | ||
|
||
static class MockIRequestModelHTTP implements IRequestModelHTTP { | ||
public JSONObject error; | ||
public int statusCode; | ||
|
||
@Override | ||
public void sendRequest() { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public void onRequestFailed(JSONObject error, int statusCode, ResultCallBack callBackObject) { | ||
this.error = error; | ||
this.statusCode = statusCode; | ||
} | ||
|
||
@Override | ||
public void onRequestFinished(CSHttpConnection request) { | ||
// Do nothing | ||
} | ||
}; | ||
|
||
@Test | ||
void setError() { | ||
MockIRequestModelHTTP csConnectionRequest = new MockIRequestModelHTTP(); | ||
|
||
CSHttpConnection connection = new CSHttpConnection("https://www.example.com", csConnectionRequest); | ||
connection.setError("Something bad"); | ||
|
||
assertEquals("Something bad", csConnectionRequest.error.getString("error_message")); | ||
assertEquals(0, csConnectionRequest.statusCode); | ||
} | ||
} |