Skip to content

Commit

Permalink
corrected code style
Browse files Browse the repository at this point in the history
  • Loading branch information
parviz-93 committed Nov 28, 2019
1 parent dbbbdf5 commit 6a1b36f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Expand Up @@ -184,7 +184,8 @@ else if (protobufFormatSupport != null) {
this.protobufFormatSupport.merge(
message, charset, contentType, this.extensionRegistry, builder);
}
} catch (IOException e) {
}
catch (IOException e) {
throw new MessageConversionException(message, "Could not read proto message" + e.getMessage(), e);
}

Expand All @@ -194,7 +195,6 @@ else if (protobufFormatSupport != null) {

@Override
protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {

final Message message = (Message) payload;

MimeType contentType = getMimeType(headers);
Expand All @@ -213,12 +213,14 @@ protected Object convertToInternal(Object payload, @Nullable MessageHeaders head
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
message.writeTo(byteArrayOutputStream);
payload = byteArrayOutputStream.toByteArray();
} else if (this.protobufFormatSupport != null) {
}
else if (this.protobufFormatSupport != null) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
this.protobufFormatSupport.print(message, outputStream, contentType, charset);
payload = new String(outputStream.toByteArray(), charset);
}
} catch (IOException e) {
}
catch (IOException e) {
throw new MessageConversionException("Could not write proto message" + e.getMessage(), e);

}
Expand All @@ -232,15 +234,14 @@ protected Object convertToInternal(Object payload, @Nullable MessageHeaders head
*/
private Message.Builder getMessageBuilder(Class<?> clazz) {
try {
assert supports(clazz);

Method method = methodCache.get(clazz);
if (method == null) {
method = clazz.getMethod("newBuilder");
methodCache.put(clazz, method);
}
return (Message.Builder) method.invoke(clazz);
} catch (Exception ex) {
}
catch (Exception ex) {
throw new MessageConversionException(
"Invalid Protobuf Message type: no invocable newBuilder() method on " + clazz, ex);
}
Expand Down
Expand Up @@ -79,7 +79,6 @@ public void extensionRegistryNull() {

@Test
public void canConvertFrom() {

assertThat(converter.canConvertFrom(message, Msg.class)).isTrue();
assertThat(converter.canConvertFrom(messageWithoutContentType, Msg.class)).isTrue();
assertThat(converter.canConvertFrom(messageJson, Msg.class)).isTrue();
Expand All @@ -102,7 +101,6 @@ public void convertFrom() throws IOException {
@Test
public void convertTo() throws IOException {
final Message<?> message = converter.toMessage(this.testMsg, this.message.getHeaders());

assertThat(message).isNotNull();
assertThat(message.getPayload()).isEqualTo(this.message.getPayload());
}
Expand Down Expand Up @@ -131,14 +129,12 @@ public void testJsonWithGoogleProtobuf() throws Exception {

//convertTo
final Message<?> message = this.converter.toMessage(this.testMsg, new MessageHeaders(headers));

assertThat(message).isNotNull();
assertThat(message.getHeaders().get(CONTENT_TYPE)).isEqualTo(APPLICATION_JSON);
assertThat(((String) message.getPayload()).length() > 0).isTrue();
assertThat(((String) message.getPayload()).isEmpty()).as("Body is empty").isFalse();
assertThat(((String) message.getPayload())).isEqualTo(this.messageJson.getPayload());


//convertFrom
final Msg msg = (Msg) converter.fromMessage(message, Msg.class);
assertThat(msg).isEqualTo(this.testMsg);
Expand Down

0 comments on commit 6a1b36f

Please sign in to comment.