+54
-6
lines changedFilter options
+54
-6
lines changed Original file line number Diff line number Diff line change
@@ -452,7 +452,12 @@ public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int
452
452
453
453
@Override
454
454
public String toString() {
455
-
return TextFormat.printer().printToString(this);
455
+
TextFormat.Printer printer =
456
+
ProtobufToStringOutput.shouldOutputDebugFormat()
457
+
? TextFormat.debugFormatPrinter()
458
+
: TextFormat.printer();
459
+
return printer.printToString(
460
+
this, TextFormat.Printer.FieldReporterLevel.ABSTRACT_BUILDER_TO_STRING);
456
461
}
457
462
458
463
/** Construct an UninitializedMessageException reporting missing fields in the given message. */
Original file line number Diff line number Diff line change
@@ -159,8 +159,9 @@ static enum FieldReporterLevel {
159
159
DEBUG_MULTILINE(9),
160
160
DEBUG_SINGLE_LINE(10),
161
161
ABSTRACT_TO_STRING(11),
162
-
ABSTRACT_MUTABLE_TO_STRING(12),
163
-
REPORT_NONE(13);
162
+
ABSTRACT_BUILDER_TO_STRING(12),
163
+
ABSTRACT_MUTABLE_TO_STRING(13),
164
+
REPORT_NONE(14);
164
165
private final int index;
165
166
166
167
FieldReporterLevel(int index) {
Original file line number Diff line number Diff line change
@@ -12,17 +12,19 @@
12
12
13
13
@RunWith(JUnit4.class)
14
14
public final class ProtobufToStringOutputTest extends DebugFormatTest {
15
+
RedactedFields.Builder messageBuilder;
15
16
RedactedFields message;
16
17
17
18
@Before
18
19
public void setupTest() {
19
-
message =
20
+
messageBuilder =
20
21
RedactedFields.newBuilder()
21
22
.setOptionalUnredactedString("foo")
22
23
.setOptionalRedactedString("bar")
23
24
.setOptionalRedactedMessage(
24
-
TestNestedMessageRedaction.newBuilder().setOptionalUnredactedNestedString("foobar"))
25
-
.build();
25
+
TestNestedMessageRedaction.newBuilder()
26
+
.setOptionalUnredactedNestedString("foobar"));
27
+
message = messageBuilder.build();
26
28
}
27
29
28
30
@Test
@@ -100,4 +102,44 @@ public void toStringFormat_testProtoWrapperWithTextFormat() {
100
102
+ "\\]");
101
103
});
102
104
}
105
+
106
+
@Test
107
+
public void builderToStringFormat_defaultFormat() {
108
+
assertThat(messageBuilder.toString())
109
+
.matches(
110
+
"optional_redacted_string: \"bar\"\n"
111
+
+ "optional_unredacted_string: \"foo\"\n"
112
+
+ "optional_redacted_message \\{\n"
113
+
+ " optional_unredacted_nested_string: \"foobar\"\n"
114
+
+ "\\}\n");
115
+
}
116
+
117
+
@Test
118
+
public void builderToStringFormat_testDebugFormat() {
119
+
ProtobufToStringOutput.callWithDebugFormat(
120
+
() ->
121
+
assertThat(messageBuilder.toString())
122
+
.matches(
123
+
String.format(
124
+
"%soptional_redacted_string: %s\n"
125
+
+ "optional_unredacted_string: \"foo\"\n"
126
+
+ "optional_redacted_message \\{\n"
127
+
+ " %s\n"
128
+
+ "\\}\n",
129
+
UNSTABLE_PREFIX_MULTILINE, REDACTED_REGEX, REDACTED_REGEX)));
130
+
}
131
+
132
+
@Test
133
+
public void builderToStringFormat_testTextFormat() {
134
+
ProtobufToStringOutput.callWithTextFormat(
135
+
() -> {
136
+
assertThat(messageBuilder.toString())
137
+
.matches(
138
+
"optional_redacted_string: \"bar\"\n"
139
+
+ "optional_unredacted_string: \"foo\"\n"
140
+
+ "optional_redacted_message \\{\n"
141
+
+ " optional_unredacted_nested_string: \"foobar\"\n"
142
+
+ "\\}\n");
143
+
});
144
+
}
103
145
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4