Skip to content

Commit def5325

Browse files
committed
GraphErrorResponseCopy test
1 parent f2a66d9 commit def5325

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/main/java/com/microsoft/graph/http/GraphErrorResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public final AdditionalDataManager additionalDataManager() {
7777
* @param response The GraphErrorResponse we want to copy
7878
* @return The copy of the specified GraphErrorResponse
7979
*/
80-
public static GraphErrorResponse getErrorCopy(GraphErrorResponse response)
80+
public static GraphErrorResponse getErrorResponseCopy(GraphErrorResponse response)
8181
{
8282
GraphErrorResponse copy = new GraphErrorResponse();
8383
copy.additionalDataManager = response.additionalDataManager(); //We are okay with keeping the dataManager intact

src/main/java/com/microsoft/graph/http/GraphServiceException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public List<String> getResponseHeaders() {
212212
*/
213213
@Nullable
214214
public GraphErrorResponse getError() {
215-
return GraphErrorResponse.getErrorCopy(error);
215+
return GraphErrorResponse.getErrorResponseCopy(error);
216216
}
217217

218218
/**

src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.microsoft.graph.http;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
45
import static org.mockito.Mockito.mock;
56

67
import org.junit.jupiter.api.Test;
@@ -18,4 +19,44 @@ public void testSetRawObject() {
1819
assertEquals(expectedJson, errorResponse.rawObject);
1920
}
2021

22+
@Test
23+
public void testGraphErrorResponseCopy() {
24+
String expectedMessage0 = "test error message 0";
25+
String expectedErrorCode = "accessDenied";
26+
GraphError error = new GraphError();
27+
error.message = expectedMessage0;
28+
29+
String expectedMessage1 = "test error message 1";
30+
GraphInnerError innerError = new GraphInnerError();
31+
innerError.debugMessage = expectedMessage1;
32+
33+
String expectedMessage2 = "test error message 2";
34+
GraphInnerError innerError2 = new GraphInnerError();
35+
innerError2.debugMessage = expectedMessage2;
36+
37+
String expectedMessage3 = "test error message 3";
38+
GraphInnerError innerError3 = new GraphInnerError();
39+
innerError3.debugMessage = expectedMessage3;
40+
41+
//Set the errors in the following order
42+
//Error -> InnerError1 -> InnerError2 -> InnerError3
43+
innerError2.innererror = innerError3;
44+
innerError.innererror = innerError2;
45+
error.innererror = innerError;
46+
47+
JsonObject expectedJson = new JsonObject();
48+
GraphErrorResponse errorResponse = new GraphErrorResponse();
49+
errorResponse.setRawObject(mock(ISerializer.class),expectedJson);
50+
errorResponse.error = error;
51+
52+
//Copy the errorResponse and its subsequent innerErrors
53+
GraphErrorResponse errorResponseCopy = GraphErrorResponse.getErrorResponseCopy(errorResponse);
54+
//Ensure subsequent innerErrors have the expected messages in the expected order.
55+
assertEquals(errorResponseCopy.error.message, expectedMessage0);
56+
assertEquals(errorResponseCopy.error.innererror.debugMessage, expectedMessage1);
57+
assertEquals(errorResponseCopy.error.innererror.innererror.debugMessage, expectedMessage2);
58+
assertEquals(errorResponseCopy.error.innererror.innererror.innererror.debugMessage, expectedMessage3);
59+
60+
assertEquals(errorResponse.rawObject, errorResponseCopy.rawObject);
61+
}
2162
}

0 commit comments

Comments
 (0)