@ -13,7 +13,7 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertNull ;
import static org.junit.Assert.assertSame ;
import static org.junit.Assert.fail ;
import static org.junit.Assert.assertThrows ;
import java.io.ByteArrayOutputStream ;
import java.io.IOException ;
@ -24,18 +24,8 @@ import org.junit.Test;
public class CommitBuilderTest {
private void assertGpgSignatureStringOutcome ( String signature ,
String expectedOutcome ) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ;
CommitBuilder . writeGpgSignatureString ( signature , out ) ;
String formatted_signature = new String ( out . toByteArray ( ) , US_ASCII ) ;
assertEquals ( expectedOutcome , formatted_signature ) ;
}
@Test
public void writeGpgSignatureString_1 ( ) throws Exception {
// @formatter:off
String signature = "-----BEGIN PGP SIGNATURE-----\n" +
private static final String SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n" +
"Version: BCPG v1.60\n" +
"\n" +
"iQEcBAABCAAGBQJb9cVhAAoJEKX+6Axg/6TZeFsH/0CY0WX/z7U8+7S5giFX4wH4\n" +
@ -46,7 +36,8 @@ public class CommitBuilderTest {
"IQEKkjnA+lhejjK1rv+ulq4kGZJFKGYWYYhRDwFg5PTkzhudhN2SGUq5Wxq1Eg4=\n" +
"=b9OI\n" +
"-----END PGP SIGNATURE-----" ;
String expectedOutcome = "-----BEGIN PGP SIGNATURE-----\n" +
private static final String EXPECTED = "-----BEGIN PGP SIGNATURE-----\n" +
" Version: BCPG v1.60\n" +
" \n" +
" iQEcBAABCAAGBQJb9cVhAAoJEKX+6Axg/6TZeFsH/0CY0WX/z7U8+7S5giFX4wH4\n" +
@ -58,23 +49,48 @@ public class CommitBuilderTest {
" =b9OI\n" +
" -----END PGP SIGNATURE-----" ;
// @formatter:on
assertGpgSignatureStringOutcome ( signature , expectedOutcome ) ;
private void assertGpgSignatureStringOutcome ( String signature ,
String expectedOutcome ) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ;
CommitBuilder . writeGpgSignatureString ( signature , out ) ;
String formatted_signature = new String ( out . toByteArray ( ) , US_ASCII ) ;
assertEquals ( expectedOutcome , formatted_signature ) ;
}
@Test
public void writeGpgSignatureString ( ) throws Exception {
assertGpgSignatureStringOutcome ( SIGNATURE , EXPECTED ) ;
}
@Test
public void writeGpgSignatureStringTrailingLF ( ) throws Exception {
assertGpgSignatureStringOutcome ( SIGNATURE + '\n' , EXPECTED ) ;
}
@Test
public void writeGpgSignatureStringCRLF ( ) throws Exception {
assertGpgSignatureStringOutcome ( SIGNATURE . replaceAll ( "\n" , "\r\n" ) ,
EXPECTED ) ;
}
@Test
public void writeGpgSignatureStringTrailingCRLF ( ) throws Exception {
assertGpgSignatureStringOutcome (
SIGNATURE . replaceAll ( "\n" , "\r\n" ) + "\r\n" , EXPECTED ) ;
}
@Test
public void writeGpgSignatureString_failsForNonAscii ( ) throws Exception {
String signature = "Ü Ä" ;
try {
CommitBuilder . writeGpgSignatureString ( signature ,
new ByteArrayOutputStream ( ) ) ;
fail ( "Exception expected" ) ;
} catch ( IllegalArgumentException e ) {
// good
IllegalArgumentException e = assertThrows (
IllegalArgumentException . class ,
( ) - > CommitBuilder . writeGpgSignatureString ( signature ,
new ByteArrayOutputStream ( ) ) ) ;
String message = MessageFormat . format ( JGitText . get ( ) . notASCIIString ,
signature ) ;
assertEquals ( message , e . getMessage ( ) ) ;
}
}
@Test
public void writeGpgSignatureString_oneLineNotModified ( ) throws Exception {