@ -13,7 +13,7 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertNull ;
import static org.junit.Assert.assertNull ;
import static org.junit.Assert.assertSame ;
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.ByteArrayOutputStream ;
import java.io.IOException ;
import java.io.IOException ;
@ -24,6 +24,32 @@ import org.junit.Test;
public class CommitBuilderTest {
public class CommitBuilderTest {
// @formatter:off
private static final String SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n" +
"Version: BCPG v1.60\n" +
"\n" +
"iQEcBAABCAAGBQJb9cVhAAoJEKX+6Axg/6TZeFsH/0CY0WX/z7U8+7S5giFX4wH4\n" +
"opvBwqyt6OX8lgNwTwBGHFNt8LdmDCCmKoq/XwkNi3ARVjLhe3gBcKXNoavvPk2Z\n" +
"gIg5ChevGkU4afWCOMLVEYnkCBGw2+86XhrK1P7gTHEk1Rd+Yv1ZRDJBY+fFO7yz\n" +
"uSBuF5RpEY2sJiIvp27Gub/rY3B5NTR/feO/z+b9oiP/fMUhpRwG5KuWUsn9NPjw\n" +
"3tvbgawYpU/2UnS+xnavMY4t2fjRYjsoxndPLb2MUX8X7vC7FgWLBlmI/rquLZVM\n" +
"IQEKkjnA+lhejjK1rv+ulq4kGZJFKGYWYYhRDwFg5PTkzhudhN2SGUq5Wxq1Eg4=\n" +
"=b9OI\n" +
"-----END PGP SIGNATURE-----" ;
private static final String EXPECTED = "-----BEGIN PGP SIGNATURE-----\n" +
" Version: BCPG v1.60\n" +
" \n" +
" iQEcBAABCAAGBQJb9cVhAAoJEKX+6Axg/6TZeFsH/0CY0WX/z7U8+7S5giFX4wH4\n" +
" opvBwqyt6OX8lgNwTwBGHFNt8LdmDCCmKoq/XwkNi3ARVjLhe3gBcKXNoavvPk2Z\n" +
" gIg5ChevGkU4afWCOMLVEYnkCBGw2+86XhrK1P7gTHEk1Rd+Yv1ZRDJBY+fFO7yz\n" +
" uSBuF5RpEY2sJiIvp27Gub/rY3B5NTR/feO/z+b9oiP/fMUhpRwG5KuWUsn9NPjw\n" +
" 3tvbgawYpU/2UnS+xnavMY4t2fjRYjsoxndPLb2MUX8X7vC7FgWLBlmI/rquLZVM\n" +
" IQEKkjnA+lhejjK1rv+ulq4kGZJFKGYWYYhRDwFg5PTkzhudhN2SGUq5Wxq1Eg4=\n" +
" =b9OI\n" +
" -----END PGP SIGNATURE-----" ;
// @formatter:on
private void assertGpgSignatureStringOutcome ( String signature ,
private void assertGpgSignatureStringOutcome ( String signature ,
String expectedOutcome ) throws IOException {
String expectedOutcome ) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ;
ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ;
@ -33,47 +59,37 @@ public class CommitBuilderTest {
}
}
@Test
@Test
public void writeGpgSignatureString_1 ( ) throws Exception {
public void writeGpgSignatureString ( ) throws Exception {
// @formatter:off
assertGpgSignatureStringOutcome ( SIGNATURE , EXPECTED ) ;
String signature = "-----BEGIN PGP SIGNATURE-----\n" +
}
"Version: BCPG v1.60\n" +
"\n" +
@Test
"iQEcBAABCAAGBQJb9cVhAAoJEKX+6Axg/6TZeFsH/0CY0WX/z7U8+7S5giFX4wH4\n" +
public void writeGpgSignatureStringTrailingLF ( ) throws Exception {
"opvBwqyt6OX8lgNwTwBGHFNt8LdmDCCmKoq/XwkNi3ARVjLhe3gBcKXNoavvPk2Z\n" +
assertGpgSignatureStringOutcome ( SIGNATURE + '\n' , EXPECTED ) ;
"gIg5ChevGkU4afWCOMLVEYnkCBGw2+86XhrK1P7gTHEk1Rd+Yv1ZRDJBY+fFO7yz\n" +
}
"uSBuF5RpEY2sJiIvp27Gub/rY3B5NTR/feO/z+b9oiP/fMUhpRwG5KuWUsn9NPjw\n" +
"3tvbgawYpU/2UnS+xnavMY4t2fjRYjsoxndPLb2MUX8X7vC7FgWLBlmI/rquLZVM\n" +
@Test
"IQEKkjnA+lhejjK1rv+ulq4kGZJFKGYWYYhRDwFg5PTkzhudhN2SGUq5Wxq1Eg4=\n" +
public void writeGpgSignatureStringCRLF ( ) throws Exception {
"=b9OI\n" +
assertGpgSignatureStringOutcome ( SIGNATURE . replaceAll ( "\n" , "\r\n" ) ,
"-----END PGP SIGNATURE-----" ;
EXPECTED ) ;
String expectedOutcome = "-----BEGIN PGP SIGNATURE-----\n" +
}
" Version: BCPG v1.60\n" +
" \n" +
@Test
" iQEcBAABCAAGBQJb9cVhAAoJEKX+6Axg/6TZeFsH/0CY0WX/z7U8+7S5giFX4wH4\n" +
public void writeGpgSignatureStringTrailingCRLF ( ) throws Exception {
" opvBwqyt6OX8lgNwTwBGHFNt8LdmDCCmKoq/XwkNi3ARVjLhe3gBcKXNoavvPk2Z\n" +
assertGpgSignatureStringOutcome (
" gIg5ChevGkU4afWCOMLVEYnkCBGw2+86XhrK1P7gTHEk1Rd+Yv1ZRDJBY+fFO7yz\n" +
SIGNATURE . replaceAll ( "\n" , "\r\n" ) + "\r\n" , EXPECTED ) ;
" uSBuF5RpEY2sJiIvp27Gub/rY3B5NTR/feO/z+b9oiP/fMUhpRwG5KuWUsn9NPjw\n" +
" 3tvbgawYpU/2UnS+xnavMY4t2fjRYjsoxndPLb2MUX8X7vC7FgWLBlmI/rquLZVM\n" +
" IQEKkjnA+lhejjK1rv+ulq4kGZJFKGYWYYhRDwFg5PTkzhudhN2SGUq5Wxq1Eg4=\n" +
" =b9OI\n" +
" -----END PGP SIGNATURE-----" ;
// @formatter:on
assertGpgSignatureStringOutcome ( signature , expectedOutcome ) ;
}
}
@Test
@Test
public void writeGpgSignatureString_failsForNonAscii ( ) throws Exception {
public void writeGpgSignatureString_failsForNonAscii ( ) throws Exception {
String signature = "Ü Ä" ;
String signature = "Ü Ä" ;
try {
IllegalArgumentException e = assertThrows (
CommitBuilder . writeGpgSignatureString ( signature ,
IllegalArgumentException . class ,
new ByteArrayOutputStream ( ) ) ;
( ) - > CommitBuilder . writeGpgSignatureString ( signature ,
fail ( "Exception expected" ) ;
new ByteArrayOutputStream ( ) ) ) ;
} catch ( IllegalArgumentException e ) {
String message = MessageFormat . format ( JGitText . get ( ) . notASCIIString ,
// good
signature ) ;
String message = MessageFormat . format ( JGitText . get ( ) . notASCIIString ,
assertEquals ( message , e . getMessage ( ) ) ;
signature ) ;
assertEquals ( message , e . getMessage ( ) ) ;
}
}
}
@Test
@Test