-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ToBuilder to incrementally add additional types to a marshaller (#15
- Loading branch information
1 parent
9de2628
commit 00f88f6
Showing
3 changed files
with
129 additions
and
20 deletions.
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
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
33 changes: 33 additions & 0 deletions
33
src/test/java/org/curioswitch/common/protobuf/json/MessageMarshallerIncrementalTest.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,33 @@ | ||
/* | ||
* Copyright (c) Choko (choko@curioswitch.org) | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package org.curioswitch.common.protobuf.json; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import com.google.protobuf.util.JsonTestProto; | ||
import org.curioswitch.common.protobuf.json.test.GithubApi; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MessageMarshallerIncrementalTest { | ||
|
||
@Test | ||
void incrementalMarshaller() throws Exception { | ||
MessageMarshaller marshaller = | ||
MessageMarshaller.builder().register(GithubApi.SearchResponse.getDefaultInstance()).build(); | ||
GithubApi.SearchResponse response = | ||
GithubApi.SearchResponse.newBuilder().setTotalCount(10).build(); | ||
JsonTestProto.TestAllTypes allTypes = JsonTestUtil.testAllTypesAllFields(); | ||
assertThat(marshaller.writeValueAsString(response)).isNotEmpty(); | ||
assertThatThrownBy(() -> marshaller.writeValueAsString(allTypes)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
|
||
MessageMarshaller marshaller2 = | ||
marshaller.toBuilder().register(JsonTestProto.TestAllTypes.getDefaultInstance()).build(); | ||
assertThat(marshaller2.writeValueAsString(response)).isNotEmpty(); | ||
assertThat(marshaller2.writeValueAsString(allTypes)).isNotEmpty(); | ||
} | ||
} |