Skip to content

Commit 8c86411

Browse files
authored
fix(fcm): Added toString() in TopicManagementResponse for logging (#469)
* Added toString() in TopicManagementResponse for logging (#343) * Used MoreObjects.toStringHelper() * removed .DS_Store & added it to .gitignore * unit test case for TopicManagementResponse toString() functionality added for logging * fixed checkStyle issue of line should not greater than 100 char
1 parent 3564eeb commit 8c86411

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ target/
1010
release.properties
1111
integration_cert.json
1212
integration_apikey.txt
13+
.DS_Store

Diff for: src/main/java/com/google/firebase/messaging/TopicManagementResponse.java

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.common.base.Preconditions.checkState;
2121

2222
import com.google.api.client.json.GenericJson;
23+
import com.google.common.base.MoreObjects;
2324
import com.google.common.collect.ImmutableList;
2425
import com.google.common.collect.ImmutableMap;
2526
import com.google.firebase.internal.NonNull;
@@ -122,5 +123,13 @@ public int getIndex() {
122123
public String getReason() {
123124
return reason;
124125
}
126+
127+
@Override
128+
public String toString() {
129+
return MoreObjects.toStringHelper(this)
130+
.add("index", index)
131+
.add("reason", reason)
132+
.toString();
133+
}
125134
}
126135
}

Diff for: src/test/java/com/google/firebase/messaging/InstanceIdClientImplTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,17 @@ public void testTopicManagementResponseWithEmptyList() {
340340
new TopicManagementResponse(ImmutableList.<GenericJson>of());
341341
}
342342

343+
@Test
344+
public void testTopicManagementResponseErrorToString() {
345+
GenericJson json = new GenericJson().set("error", "test error");
346+
ImmutableList<GenericJson> jsonList = ImmutableList.of(json);
347+
348+
TopicManagementResponse topicManagementResponse = new TopicManagementResponse(jsonList);
349+
350+
String expected = "[Error{index=0, reason=unknown-error}]";
351+
assertEquals(expected, topicManagementResponse.getErrors().toString());
352+
}
353+
343354
private static InstanceIdClientImpl initInstanceIdClient(
344355
final MockLowLevelHttpResponse mockResponse,
345356
final HttpResponseInterceptor interceptor) {

0 commit comments

Comments
 (0)