Source:
public void parseMetadataFromHeader ( ) { com.google.gerrit.server.mail.receive.MailMessage.Builder b = com.google.gerrit.server.mail.receive.MailMessage.builder ( ) ; b.id ( "" ) ; b.dateReceived ( java.time.Instant.now ( ) ) ; b.subject ( "" ) ; b.addAdditionalHeader ( ( ( com.google.gerrit.server.mail.MetadataName.toHeaderWithDelimiter ( MetadataName.CHANGE_NUMBER ) ) + "123" ) ) ; b.addAdditionalHeader ( ( ( com.google.gerrit.server.mail.MetadataName.toHeaderWithDelimiter ( MetadataName.PATCH_SET ) ) + "1" ) ) ; b.addAdditionalHeader ( ( ( com.google.gerrit.server.mail.MetadataName.toHeaderWithDelimiter ( MetadataName.MESSAGE_TYPE ) ) + "comment" ) ) ; b.addAdditionalHeader ( ( ( com.google.gerrit.server.mail.MetadataName.toHeaderWithDelimiter ( MetadataName.TIMESTAMP ) ) + "Tue, 25 Oct 2016 02:11:35 -0700" ) ) ; com.google.gerrit.server.mail.Address author = new com.google.gerrit.server.mail.Address ( "Diffy" , "test@gerritcodereview.com" ) ; b.from ( author ) ; com.google.gerrit.server.mail.receive.MailMetadata meta = com.google.gerrit.server.mail.receive.MetadataParser.parse ( b.build ( ) ) ; com.google.common.truth.Truth.assertThat ( meta.author ) . isEqualTo ( author.getEmail ( ) ) ; com.google.common.truth.Truth.assertThat ( meta.changeNumber ) . isEqualTo ( 123 ) ; com.google.common.truth.Truth.assertThat ( meta.patchSet ) . isEqualTo ( 1 ) ; com.google.common.truth.Truth.assertThat ( meta.messageType ) . isEqualTo ( "comment" ) ; com.google.common.truth.Truth.assertThat ( meta.timestamp.toInstant ( ) ) . isEqualTo ( java.time.LocalDateTime.of ( 2016 , java.time.Month.OCTOBER , 25 , 9 , 11 , 35 ) . atOffset ( java.time.ZoneOffset.UTC ) . toInstant ( ) ) ; }

Target:
public void parseMetadataFromHeader ( ) { com.google.gerrit.server.mail.receive.MailMessage.Builder b = com.google.gerrit.server.mail.receive.MailMessage.builder ( ) ; b.id ( "" ) ; b.dateReceived ( java.time.Instant.now ( ) ) ; b.subject ( "" ) ; b.addAdditionalHeader ( ( ( MailHeader.CHANGE_NUMBER.fieldWithDelimiter ( ) ) + "123" ) ) ; b.addAdditionalHeader ( ( ( MailHeader.PATCH_SET.fieldWithDelimiter ( ) ) + "1" ) ) ; b.addAdditionalHeader ( ( ( MailHeader.MESSAGE_TYPE.fieldWithDelimiter ( ) ) + "comment" ) ) ; b.addAdditionalHeader ( ( ( MailHeader.COMMENT_DATE.fieldWithDelimiter ( ) ) + "Tue, 25 Oct 2016 02:11:35 -0700" ) ) ; com.google.gerrit.server.mail.Address author = new com.google.gerrit.server.mail.Address ( "Diffy" , "test@gerritcodereview.com" ) ; b.from ( author ) ; com.google.gerrit.server.mail.receive.MailMetadata meta = com.google.gerrit.server.mail.receive.MailHeaderParser.parse ( b.build ( ) ) ; com.google.common.truth.Truth.assertThat ( meta.author ) . isEqualTo ( author.getEmail ( ) ) ; com.google.common.truth.Truth.assertThat ( meta.changeNumber ) . isEqualTo ( 123 ) ; com.google.common.truth.Truth.assertThat ( meta.patchSet ) . isEqualTo ( 1 ) ; com.google.common.truth.Truth.assertThat ( meta.messageType ) . isEqualTo ( "comment" ) ; com.google.common.truth.Truth.assertThat ( meta.timestamp.toInstant ( ) ) . isEqualTo ( java.time.LocalDateTime.of ( 2016 , java.time.Month.OCTOBER , 25 , 9 , 11 , 35 ) . atOffset ( java.time.ZoneOffset.UTC ) . toInstant ( ) ) ; }