test_class_signature
stringlengths
21
105
function
stringlengths
268
12.2k
prompt_complete_with_comment
stringlengths
1.66k
9.91k
location
stringlengths
46
115
be_test_import_context
stringlengths
44
2.77k
be_test_class_function_signature_context
stringlengths
60
22.9k
end
int64
44
7.03k
function_name
stringlengths
8
51
prompt_chat_with_comment
stringlengths
1.56k
9.41k
start
int64
28
7.02k
prompt_complete
stringlengths
1.75k
10.3k
comment
stringlengths
128
2.81k
bug_id
int64
1
112
be_test_class_long_name
stringlengths
24
92
source_dir
stringclasses
4 values
prompt_chat
stringlengths
1.66k
9.83k
be_test_class_signature
stringlengths
17
234
test_import_context
stringlengths
39
2.03k
test_class_function_signature_context
stringlengths
169
69.8k
task_id
stringlengths
64
64
testmethods
sequence
be_test_class_field_context
stringlengths
0
8.55k
function_signature
stringlengths
23
151
test_class_field_context
stringlengths
0
4.05k
project
stringclasses
12 values
source
stringlengths
3.4k
445k
indent
stringclasses
2 values
classmethods
list
public class Base64Test
@Test public void testDecodeWithInnerPad() { final String content = "SGVsbG8gV29ybGQ=SGVsbG8gV29ybGQ="; final byte[] result = Base64.decodeBase64(content); final byte[] shouldBe = StringUtils.getBytesUtf8("Hello World"); assertTrue("decode should halt at pad (=)", Arrays.equals(result, shouldBe)); }
// public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe); // public boolean isUrlSafe(); // @Override // void encode(final byte[] in, int inPos, final int inAvail, final Context context); // @Override // void decode(final byte[] in, int inPos, final int inAvail, final Context context); // @Deprecated // public static boolean isArrayByteBase64(final byte[] arrayOctet); // public static boolean isBase64(final byte octet); // public static boolean isBase64(final String base64); // public static boolean isBase64(final byte[] arrayOctet); // public static byte[] encodeBase64(final byte[] binaryData); // public static String encodeBase64String(final byte[] binaryData); // public static byte[] encodeBase64URLSafe(final byte[] binaryData); // public static String encodeBase64URLSafeString(final byte[] binaryData); // public static byte[] encodeBase64Chunked(final byte[] binaryData); // public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked); // public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe); // public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, // final boolean urlSafe, final int maxResultSize); // public static byte[] decodeBase64(final String base64String); // public static byte[] decodeBase64(final byte[] base64Data); // public static BigInteger decodeInteger(final byte[] pArray); // public static byte[] encodeInteger(final BigInteger bigInt); // static byte[] toIntegerBytes(final BigInteger bigInt); // @Override // protected boolean isInAlphabet(final byte octet); // } // // // Abstract Java Test Class // package org.apache.commons.codec.binary; // // import static org.junit.Assert.assertEquals; // import static org.junit.Assert.assertFalse; // import static org.junit.Assert.assertNotNull; // import static org.junit.Assert.assertTrue; // import static org.junit.Assert.fail; // import java.math.BigInteger; // import java.nio.charset.Charset; // import java.util.Arrays; // import java.util.Random; // import org.apache.commons.codec.Charsets; // import org.apache.commons.codec.DecoderException; // import org.apache.commons.codec.EncoderException; // import org.apache.commons.lang3.ArrayUtils; // import org.junit.Ignore; // import org.junit.Test; // // // // public class Base64Test { // private static final Charset CHARSET_UTF8 = Charsets.UTF_8; // private final Random random = new Random(); // // public Random getRandom(); // @Test // public void testIsStringBase64(); // @Test // public void testBase64(); // @Test // public void testBase64AtBufferStart(); // @Test // public void testBase64AtBufferEnd(); // @Test // public void testBase64AtBufferMiddle(); // private void testBase64InBuffer(int startPasSize, int endPadSize); // @Test // public void testDecodeWithInnerPad(); // @Test // public void testChunkedEncodeMultipleOf76(); // @Test // public void testCodec68(); // @Test // public void testCodeInteger1(); // @Test // public void testCodeInteger2(); // @Test // public void testCodeInteger3(); // @Test // public void testCodeInteger4(); // @Test // public void testCodeIntegerEdgeCases(); // @Test // public void testCodeIntegerNull(); // @Test // public void testConstructors(); // @Test // public void testConstructor_Int_ByteArray_Boolean(); // @Test // public void testConstructor_Int_ByteArray_Boolean_UrlSafe(); // @Test // public void testDecodePadMarkerIndex2(); // @Test // public void testDecodePadMarkerIndex3(); // @Test // public void testDecodePadOnly(); // @Test // public void testDecodePadOnlyChunked(); // @Test // public void testDecodeWithWhitespace() throws Exception; // @Test // public void testEmptyBase64(); // @Test // public void testEncodeDecodeRandom(); // @Test // public void testEncodeDecodeSmall(); // @Test // public void testEncodeOverMaxSize() throws Exception; // @Test // public void testCodec112(); // private void testEncodeOverMaxSize(final int maxSize) throws Exception; // @Test // public void testIgnoringNonBase64InDecode() throws Exception; // @Test // public void testIsArrayByteBase64(); // @Test // public void testIsUrlSafe(); // @Test // public void testKnownDecodings(); // @Test // public void testKnownEncodings(); // @Test // public void testNonBase64Test() throws Exception; // @Test // public void testObjectDecodeWithInvalidParameter() throws Exception; // @Test // public void testObjectDecodeWithValidParameter() throws Exception; // @Test // public void testObjectEncodeWithInvalidParameter() throws Exception; // @Test // public void testObjectEncodeWithValidParameter() throws Exception; // @Test // public void testObjectEncode() throws Exception; // @Test // public void testPairs(); // @Test // public void testRfc2045Section2Dot1CrLfDefinition(); // @Test // public void testRfc2045Section6Dot8ChunkSizeDefinition(); // @Test // public void testRfc1421Section6Dot8ChunkSizeDefinition(); // @Test // public void testRfc4648Section10Decode(); // @Test // public void testRfc4648Section10DecodeWithCrLf(); // @Test // public void testRfc4648Section10Encode(); // @Test // public void testRfc4648Section10DecodeEncode(); // private void testDecodeEncode(final String encodedText); // @Test // public void testRfc4648Section10EncodeDecode(); // private void testEncodeDecode(final String plainText); // @Test // public void testSingletons(); // @Test // public void testSingletonsChunked(); // @Test // public void testTriplets(); // @Test // public void testTripletsChunked(); // @Test // public void testUrlSafe(); // @Test // public void testUUID() throws DecoderException; // @Test // public void testByteToStringVariations() throws DecoderException; // @Test // public void testStringToByteVariations() throws DecoderException; // private String toString(final byte[] data); // @Test // @Ignore // public void testHugeLineSeparator(); // } // You are a professional Java test case writer, please create a test case named `testDecodeWithInnerPad` for the `Base64` class, utilizing the provided abstract Java class context information and the following natural language annotations. /** * Test our decode with pad character in the middle. (Our current * implementation: halt decode and return what we've got so far). * * The point of this test is not to say * "this is the correct way to decode base64." The point is simply to keep * us aware of the current logic since 1.4 so we don't accidentally break it * without realizing. * * Note for historians. The 1.3 logic would decode to: * "Hello World\u0000Hello World" -- null in the middle --- and 1.4 * unwittingly changed it to current logic. */
src/test/java/org/apache/commons/codec/binary/Base64Test.java
package org.apache.commons.codec.binary; import java.math.BigInteger;
public Base64(); public Base64(final boolean urlSafe); public Base64(final int lineLength); public Base64(final int lineLength, final byte[] lineSeparator); public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe); public boolean isUrlSafe(); @Override void encode(final byte[] in, int inPos, final int inAvail, final Context context); @Override void decode(final byte[] in, int inPos, final int inAvail, final Context context); @Deprecated public static boolean isArrayByteBase64(final byte[] arrayOctet); public static boolean isBase64(final byte octet); public static boolean isBase64(final String base64); public static boolean isBase64(final byte[] arrayOctet); public static byte[] encodeBase64(final byte[] binaryData); public static String encodeBase64String(final byte[] binaryData); public static byte[] encodeBase64URLSafe(final byte[] binaryData); public static String encodeBase64URLSafeString(final byte[] binaryData); public static byte[] encodeBase64Chunked(final byte[] binaryData); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe, final int maxResultSize); public static byte[] decodeBase64(final String base64String); public static byte[] decodeBase64(final byte[] base64Data); public static BigInteger decodeInteger(final byte[] pArray); public static byte[] encodeInteger(final BigInteger bigInt); static byte[] toIntegerBytes(final BigInteger bigInt); @Override protected boolean isInAlphabet(final byte octet);
156
testDecodeWithInnerPad
```java public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe); public boolean isUrlSafe(); @Override void encode(final byte[] in, int inPos, final int inAvail, final Context context); @Override void decode(final byte[] in, int inPos, final int inAvail, final Context context); @Deprecated public static boolean isArrayByteBase64(final byte[] arrayOctet); public static boolean isBase64(final byte octet); public static boolean isBase64(final String base64); public static boolean isBase64(final byte[] arrayOctet); public static byte[] encodeBase64(final byte[] binaryData); public static String encodeBase64String(final byte[] binaryData); public static byte[] encodeBase64URLSafe(final byte[] binaryData); public static String encodeBase64URLSafeString(final byte[] binaryData); public static byte[] encodeBase64Chunked(final byte[] binaryData); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe, final int maxResultSize); public static byte[] decodeBase64(final String base64String); public static byte[] decodeBase64(final byte[] base64Data); public static BigInteger decodeInteger(final byte[] pArray); public static byte[] encodeInteger(final BigInteger bigInt); static byte[] toIntegerBytes(final BigInteger bigInt); @Override protected boolean isInAlphabet(final byte octet); } // Abstract Java Test Class package org.apache.commons.codec.binary; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.math.BigInteger; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Random; import org.apache.commons.codec.Charsets; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.EncoderException; import org.apache.commons.lang3.ArrayUtils; import org.junit.Ignore; import org.junit.Test; public class Base64Test { private static final Charset CHARSET_UTF8 = Charsets.UTF_8; private final Random random = new Random(); public Random getRandom(); @Test public void testIsStringBase64(); @Test public void testBase64(); @Test public void testBase64AtBufferStart(); @Test public void testBase64AtBufferEnd(); @Test public void testBase64AtBufferMiddle(); private void testBase64InBuffer(int startPasSize, int endPadSize); @Test public void testDecodeWithInnerPad(); @Test public void testChunkedEncodeMultipleOf76(); @Test public void testCodec68(); @Test public void testCodeInteger1(); @Test public void testCodeInteger2(); @Test public void testCodeInteger3(); @Test public void testCodeInteger4(); @Test public void testCodeIntegerEdgeCases(); @Test public void testCodeIntegerNull(); @Test public void testConstructors(); @Test public void testConstructor_Int_ByteArray_Boolean(); @Test public void testConstructor_Int_ByteArray_Boolean_UrlSafe(); @Test public void testDecodePadMarkerIndex2(); @Test public void testDecodePadMarkerIndex3(); @Test public void testDecodePadOnly(); @Test public void testDecodePadOnlyChunked(); @Test public void testDecodeWithWhitespace() throws Exception; @Test public void testEmptyBase64(); @Test public void testEncodeDecodeRandom(); @Test public void testEncodeDecodeSmall(); @Test public void testEncodeOverMaxSize() throws Exception; @Test public void testCodec112(); private void testEncodeOverMaxSize(final int maxSize) throws Exception; @Test public void testIgnoringNonBase64InDecode() throws Exception; @Test public void testIsArrayByteBase64(); @Test public void testIsUrlSafe(); @Test public void testKnownDecodings(); @Test public void testKnownEncodings(); @Test public void testNonBase64Test() throws Exception; @Test public void testObjectDecodeWithInvalidParameter() throws Exception; @Test public void testObjectDecodeWithValidParameter() throws Exception; @Test public void testObjectEncodeWithInvalidParameter() throws Exception; @Test public void testObjectEncodeWithValidParameter() throws Exception; @Test public void testObjectEncode() throws Exception; @Test public void testPairs(); @Test public void testRfc2045Section2Dot1CrLfDefinition(); @Test public void testRfc2045Section6Dot8ChunkSizeDefinition(); @Test public void testRfc1421Section6Dot8ChunkSizeDefinition(); @Test public void testRfc4648Section10Decode(); @Test public void testRfc4648Section10DecodeWithCrLf(); @Test public void testRfc4648Section10Encode(); @Test public void testRfc4648Section10DecodeEncode(); private void testDecodeEncode(final String encodedText); @Test public void testRfc4648Section10EncodeDecode(); private void testEncodeDecode(final String plainText); @Test public void testSingletons(); @Test public void testSingletonsChunked(); @Test public void testTriplets(); @Test public void testTripletsChunked(); @Test public void testUrlSafe(); @Test public void testUUID() throws DecoderException; @Test public void testByteToStringVariations() throws DecoderException; @Test public void testStringToByteVariations() throws DecoderException; private String toString(final byte[] data); @Test @Ignore public void testHugeLineSeparator(); } ``` You are a professional Java test case writer, please create a test case named `testDecodeWithInnerPad` for the `Base64` class, utilizing the provided abstract Java class context information and the following natural language annotations. ```java /** * Test our decode with pad character in the middle. (Our current * implementation: halt decode and return what we've got so far). * * The point of this test is not to say * "this is the correct way to decode base64." The point is simply to keep * us aware of the current logic since 1.4 so we don't accidentally break it * without realizing. * * Note for historians. The 1.3 logic would decode to: * "Hello World\u0000Hello World" -- null in the middle --- and 1.4 * unwittingly changed it to current logic. */
150
// public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe); // public boolean isUrlSafe(); // @Override // void encode(final byte[] in, int inPos, final int inAvail, final Context context); // @Override // void decode(final byte[] in, int inPos, final int inAvail, final Context context); // @Deprecated // public static boolean isArrayByteBase64(final byte[] arrayOctet); // public static boolean isBase64(final byte octet); // public static boolean isBase64(final String base64); // public static boolean isBase64(final byte[] arrayOctet); // public static byte[] encodeBase64(final byte[] binaryData); // public static String encodeBase64String(final byte[] binaryData); // public static byte[] encodeBase64URLSafe(final byte[] binaryData); // public static String encodeBase64URLSafeString(final byte[] binaryData); // public static byte[] encodeBase64Chunked(final byte[] binaryData); // public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked); // public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe); // public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, // final boolean urlSafe, final int maxResultSize); // public static byte[] decodeBase64(final String base64String); // public static byte[] decodeBase64(final byte[] base64Data); // public static BigInteger decodeInteger(final byte[] pArray); // public static byte[] encodeInteger(final BigInteger bigInt); // static byte[] toIntegerBytes(final BigInteger bigInt); // @Override // protected boolean isInAlphabet(final byte octet); // } // // // Abstract Java Test Class // package org.apache.commons.codec.binary; // // import static org.junit.Assert.assertEquals; // import static org.junit.Assert.assertFalse; // import static org.junit.Assert.assertNotNull; // import static org.junit.Assert.assertTrue; // import static org.junit.Assert.fail; // import java.math.BigInteger; // import java.nio.charset.Charset; // import java.util.Arrays; // import java.util.Random; // import org.apache.commons.codec.Charsets; // import org.apache.commons.codec.DecoderException; // import org.apache.commons.codec.EncoderException; // import org.apache.commons.lang3.ArrayUtils; // import org.junit.Ignore; // import org.junit.Test; // // // // public class Base64Test { // private static final Charset CHARSET_UTF8 = Charsets.UTF_8; // private final Random random = new Random(); // // public Random getRandom(); // @Test // public void testIsStringBase64(); // @Test // public void testBase64(); // @Test // public void testBase64AtBufferStart(); // @Test // public void testBase64AtBufferEnd(); // @Test // public void testBase64AtBufferMiddle(); // private void testBase64InBuffer(int startPasSize, int endPadSize); // @Test // public void testDecodeWithInnerPad(); // @Test // public void testChunkedEncodeMultipleOf76(); // @Test // public void testCodec68(); // @Test // public void testCodeInteger1(); // @Test // public void testCodeInteger2(); // @Test // public void testCodeInteger3(); // @Test // public void testCodeInteger4(); // @Test // public void testCodeIntegerEdgeCases(); // @Test // public void testCodeIntegerNull(); // @Test // public void testConstructors(); // @Test // public void testConstructor_Int_ByteArray_Boolean(); // @Test // public void testConstructor_Int_ByteArray_Boolean_UrlSafe(); // @Test // public void testDecodePadMarkerIndex2(); // @Test // public void testDecodePadMarkerIndex3(); // @Test // public void testDecodePadOnly(); // @Test // public void testDecodePadOnlyChunked(); // @Test // public void testDecodeWithWhitespace() throws Exception; // @Test // public void testEmptyBase64(); // @Test // public void testEncodeDecodeRandom(); // @Test // public void testEncodeDecodeSmall(); // @Test // public void testEncodeOverMaxSize() throws Exception; // @Test // public void testCodec112(); // private void testEncodeOverMaxSize(final int maxSize) throws Exception; // @Test // public void testIgnoringNonBase64InDecode() throws Exception; // @Test // public void testIsArrayByteBase64(); // @Test // public void testIsUrlSafe(); // @Test // public void testKnownDecodings(); // @Test // public void testKnownEncodings(); // @Test // public void testNonBase64Test() throws Exception; // @Test // public void testObjectDecodeWithInvalidParameter() throws Exception; // @Test // public void testObjectDecodeWithValidParameter() throws Exception; // @Test // public void testObjectEncodeWithInvalidParameter() throws Exception; // @Test // public void testObjectEncodeWithValidParameter() throws Exception; // @Test // public void testObjectEncode() throws Exception; // @Test // public void testPairs(); // @Test // public void testRfc2045Section2Dot1CrLfDefinition(); // @Test // public void testRfc2045Section6Dot8ChunkSizeDefinition(); // @Test // public void testRfc1421Section6Dot8ChunkSizeDefinition(); // @Test // public void testRfc4648Section10Decode(); // @Test // public void testRfc4648Section10DecodeWithCrLf(); // @Test // public void testRfc4648Section10Encode(); // @Test // public void testRfc4648Section10DecodeEncode(); // private void testDecodeEncode(final String encodedText); // @Test // public void testRfc4648Section10EncodeDecode(); // private void testEncodeDecode(final String plainText); // @Test // public void testSingletons(); // @Test // public void testSingletonsChunked(); // @Test // public void testTriplets(); // @Test // public void testTripletsChunked(); // @Test // public void testUrlSafe(); // @Test // public void testUUID() throws DecoderException; // @Test // public void testByteToStringVariations() throws DecoderException; // @Test // public void testStringToByteVariations() throws DecoderException; // private String toString(final byte[] data); // @Test // @Ignore // public void testHugeLineSeparator(); // } // You are a professional Java test case writer, please create a test case named `testDecodeWithInnerPad` for the `Base64` class, utilizing the provided abstract Java class context information and the following natural language annotations. /** * Test our decode with pad character in the middle. (Our current * implementation: halt decode and return what we've got so far). * * The point of this test is not to say * "this is the correct way to decode base64." The point is simply to keep * us aware of the current logic since 1.4 so we don't accidentally break it * without realizing. * * Note for historians. The 1.3 logic would decode to: * "Hello World\u0000Hello World" -- null in the middle --- and 1.4 * unwittingly changed it to current logic. */ @Test public void testDecodeWithInnerPad() {
/** * Test our decode with pad character in the middle. (Our current * implementation: halt decode and return what we've got so far). * * The point of this test is not to say * "this is the correct way to decode base64." The point is simply to keep * us aware of the current logic since 1.4 so we don't accidentally break it * without realizing. * * Note for historians. The 1.3 logic would decode to: * "Hello World\u0000Hello World" -- null in the middle --- and 1.4 * unwittingly changed it to current logic. */
18
org.apache.commons.codec.binary.Base64
src/test/java
```java public Base64(final int lineLength, final byte[] lineSeparator, final boolean urlSafe); public boolean isUrlSafe(); @Override void encode(final byte[] in, int inPos, final int inAvail, final Context context); @Override void decode(final byte[] in, int inPos, final int inAvail, final Context context); @Deprecated public static boolean isArrayByteBase64(final byte[] arrayOctet); public static boolean isBase64(final byte octet); public static boolean isBase64(final String base64); public static boolean isBase64(final byte[] arrayOctet); public static byte[] encodeBase64(final byte[] binaryData); public static String encodeBase64String(final byte[] binaryData); public static byte[] encodeBase64URLSafe(final byte[] binaryData); public static String encodeBase64URLSafeString(final byte[] binaryData); public static byte[] encodeBase64Chunked(final byte[] binaryData); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe); public static byte[] encodeBase64(final byte[] binaryData, final boolean isChunked, final boolean urlSafe, final int maxResultSize); public static byte[] decodeBase64(final String base64String); public static byte[] decodeBase64(final byte[] base64Data); public static BigInteger decodeInteger(final byte[] pArray); public static byte[] encodeInteger(final BigInteger bigInt); static byte[] toIntegerBytes(final BigInteger bigInt); @Override protected boolean isInAlphabet(final byte octet); } // Abstract Java Test Class package org.apache.commons.codec.binary; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.math.BigInteger; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Random; import org.apache.commons.codec.Charsets; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.EncoderException; import org.apache.commons.lang3.ArrayUtils; import org.junit.Ignore; import org.junit.Test; public class Base64Test { private static final Charset CHARSET_UTF8 = Charsets.UTF_8; private final Random random = new Random(); public Random getRandom(); @Test public void testIsStringBase64(); @Test public void testBase64(); @Test public void testBase64AtBufferStart(); @Test public void testBase64AtBufferEnd(); @Test public void testBase64AtBufferMiddle(); private void testBase64InBuffer(int startPasSize, int endPadSize); @Test public void testDecodeWithInnerPad(); @Test public void testChunkedEncodeMultipleOf76(); @Test public void testCodec68(); @Test public void testCodeInteger1(); @Test public void testCodeInteger2(); @Test public void testCodeInteger3(); @Test public void testCodeInteger4(); @Test public void testCodeIntegerEdgeCases(); @Test public void testCodeIntegerNull(); @Test public void testConstructors(); @Test public void testConstructor_Int_ByteArray_Boolean(); @Test public void testConstructor_Int_ByteArray_Boolean_UrlSafe(); @Test public void testDecodePadMarkerIndex2(); @Test public void testDecodePadMarkerIndex3(); @Test public void testDecodePadOnly(); @Test public void testDecodePadOnlyChunked(); @Test public void testDecodeWithWhitespace() throws Exception; @Test public void testEmptyBase64(); @Test public void testEncodeDecodeRandom(); @Test public void testEncodeDecodeSmall(); @Test public void testEncodeOverMaxSize() throws Exception; @Test public void testCodec112(); private void testEncodeOverMaxSize(final int maxSize) throws Exception; @Test public void testIgnoringNonBase64InDecode() throws Exception; @Test public void testIsArrayByteBase64(); @Test public void testIsUrlSafe(); @Test public void testKnownDecodings(); @Test public void testKnownEncodings(); @Test public void testNonBase64Test() throws Exception; @Test public void testObjectDecodeWithInvalidParameter() throws Exception; @Test public void testObjectDecodeWithValidParameter() throws Exception; @Test public void testObjectEncodeWithInvalidParameter() throws Exception; @Test public void testObjectEncodeWithValidParameter() throws Exception; @Test public void testObjectEncode() throws Exception; @Test public void testPairs(); @Test public void testRfc2045Section2Dot1CrLfDefinition(); @Test public void testRfc2045Section6Dot8ChunkSizeDefinition(); @Test public void testRfc1421Section6Dot8ChunkSizeDefinition(); @Test public void testRfc4648Section10Decode(); @Test public void testRfc4648Section10DecodeWithCrLf(); @Test public void testRfc4648Section10Encode(); @Test public void testRfc4648Section10DecodeEncode(); private void testDecodeEncode(final String encodedText); @Test public void testRfc4648Section10EncodeDecode(); private void testEncodeDecode(final String plainText); @Test public void testSingletons(); @Test public void testSingletonsChunked(); @Test public void testTriplets(); @Test public void testTripletsChunked(); @Test public void testUrlSafe(); @Test public void testUUID() throws DecoderException; @Test public void testByteToStringVariations() throws DecoderException; @Test public void testStringToByteVariations() throws DecoderException; private String toString(final byte[] data); @Test @Ignore public void testHugeLineSeparator(); } ``` You are a professional Java test case writer, please create a test case named `testDecodeWithInnerPad` for the `Base64` class, utilizing the provided abstract Java class context information and the following natural language annotations. ```java /** * Test our decode with pad character in the middle. (Our current * implementation: halt decode and return what we've got so far). * * The point of this test is not to say * "this is the correct way to decode base64." The point is simply to keep * us aware of the current logic since 1.4 so we don't accidentally break it * without realizing. * * Note for historians. The 1.3 logic would decode to: * "Hello World\u0000Hello World" -- null in the middle --- and 1.4 * unwittingly changed it to current logic. */ @Test public void testDecodeWithInnerPad() { ```
public class Base64 extends BaseNCodec
package org.apache.commons.codec.binary; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.math.BigInteger; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Random; import org.apache.commons.codec.Charsets; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.EncoderException; import org.apache.commons.lang3.ArrayUtils; import org.junit.Ignore; import org.junit.Test;
public Random getRandom(); @Test public void testIsStringBase64(); @Test public void testBase64(); @Test public void testBase64AtBufferStart(); @Test public void testBase64AtBufferEnd(); @Test public void testBase64AtBufferMiddle(); private void testBase64InBuffer(int startPasSize, int endPadSize); @Test public void testDecodeWithInnerPad(); @Test public void testChunkedEncodeMultipleOf76(); @Test public void testCodec68(); @Test public void testCodeInteger1(); @Test public void testCodeInteger2(); @Test public void testCodeInteger3(); @Test public void testCodeInteger4(); @Test public void testCodeIntegerEdgeCases(); @Test public void testCodeIntegerNull(); @Test public void testConstructors(); @Test public void testConstructor_Int_ByteArray_Boolean(); @Test public void testConstructor_Int_ByteArray_Boolean_UrlSafe(); @Test public void testDecodePadMarkerIndex2(); @Test public void testDecodePadMarkerIndex3(); @Test public void testDecodePadOnly(); @Test public void testDecodePadOnlyChunked(); @Test public void testDecodeWithWhitespace() throws Exception; @Test public void testEmptyBase64(); @Test public void testEncodeDecodeRandom(); @Test public void testEncodeDecodeSmall(); @Test public void testEncodeOverMaxSize() throws Exception; @Test public void testCodec112(); private void testEncodeOverMaxSize(final int maxSize) throws Exception; @Test public void testIgnoringNonBase64InDecode() throws Exception; @Test public void testIsArrayByteBase64(); @Test public void testIsUrlSafe(); @Test public void testKnownDecodings(); @Test public void testKnownEncodings(); @Test public void testNonBase64Test() throws Exception; @Test public void testObjectDecodeWithInvalidParameter() throws Exception; @Test public void testObjectDecodeWithValidParameter() throws Exception; @Test public void testObjectEncodeWithInvalidParameter() throws Exception; @Test public void testObjectEncodeWithValidParameter() throws Exception; @Test public void testObjectEncode() throws Exception; @Test public void testPairs(); @Test public void testRfc2045Section2Dot1CrLfDefinition(); @Test public void testRfc2045Section6Dot8ChunkSizeDefinition(); @Test public void testRfc1421Section6Dot8ChunkSizeDefinition(); @Test public void testRfc4648Section10Decode(); @Test public void testRfc4648Section10DecodeWithCrLf(); @Test public void testRfc4648Section10Encode(); @Test public void testRfc4648Section10DecodeEncode(); private void testDecodeEncode(final String encodedText); @Test public void testRfc4648Section10EncodeDecode(); private void testEncodeDecode(final String plainText); @Test public void testSingletons(); @Test public void testSingletonsChunked(); @Test public void testTriplets(); @Test public void testTripletsChunked(); @Test public void testUrlSafe(); @Test public void testUUID() throws DecoderException; @Test public void testByteToStringVariations() throws DecoderException; @Test public void testStringToByteVariations() throws DecoderException; private String toString(final byte[] data); @Test @Ignore public void testHugeLineSeparator();
0b0ae06d5d6d2ef79e2adc1c4cd60655cf9a3f9ac634e45f30d1c1c6faff2c22
[ "org.apache.commons.codec.binary.Base64Test::testDecodeWithInnerPad" ]
private static final int BITS_PER_ENCODED_BYTE = 6; private static final int BYTES_PER_UNENCODED_BLOCK = 3; private static final int BYTES_PER_ENCODED_BLOCK = 4; static final byte[] CHUNK_SEPARATOR = {'\r', '\n'}; private static final byte[] STANDARD_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; private static final byte[] URL_SAFE_ENCODE_TABLE = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' }; private static final byte[] DECODE_TABLE = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00-0f -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-1f -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, // 20-2f + - / 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 30-3f 0-9 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 40-4f A-O 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, // 50-5f P-Z _ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 60-6f a-o 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 // 70-7a p-z }; private static final int MASK_6BITS = 0x3f; private final byte[] encodeTable; private final byte[] decodeTable = DECODE_TABLE; private final byte[] lineSeparator; private final int decodeSize; private final int encodeSize;
@Test public void testDecodeWithInnerPad()
private static final Charset CHARSET_UTF8 = Charsets.UTF_8; private final Random random = new Random();
Codec
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.codec.binary; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.math.BigInteger; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Random; import org.apache.commons.codec.Charsets; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.EncoderException; import org.apache.commons.lang3.ArrayUtils; import org.junit.Ignore; import org.junit.Test; /** * Test cases for Base64 class. * * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a> * @version $Id$ */ public class Base64Test { private static final Charset CHARSET_UTF8 = Charsets.UTF_8; private final Random random = new Random(); /** * @return Returns the random. */ public Random getRandom() { return this.random; } /** * Test the isStringBase64 method. */ @Test public void testIsStringBase64() { final String nullString = null; final String emptyString = ""; final String validString = "abc===defg\n\r123456\r789\r\rABC\n\nDEF==GHI\r\nJKL=============="; final String invalidString = validString + (char) 0; // append null // character try { Base64.isBase64(nullString); fail("Base64.isStringBase64() should not be null-safe."); } catch (final NullPointerException npe) { assertNotNull("Base64.isStringBase64() should not be null-safe.", npe); } assertTrue("Base64.isStringBase64(empty-string) is true", Base64.isBase64(emptyString)); assertTrue("Base64.isStringBase64(valid-string) is true", Base64.isBase64(validString)); assertFalse("Base64.isStringBase64(invalid-string) is false", Base64.isBase64(invalidString)); } /** * Test the Base64 implementation */ @Test public void testBase64() { final String content = "Hello World"; String encodedContent; byte[] encodedBytes = Base64.encodeBase64(StringUtils.getBytesUtf8(content)); encodedContent = StringUtils.newStringUtf8(encodedBytes); assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent); Base64 b64 = new Base64(BaseNCodec.MIME_CHUNK_SIZE, null); // null // lineSeparator // same as // saying // no-chunking encodedBytes = b64.encode(StringUtils.getBytesUtf8(content)); encodedContent = StringUtils.newStringUtf8(encodedBytes); assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent); b64 = new Base64(0, null); // null lineSeparator same as saying // no-chunking encodedBytes = b64.encode(StringUtils.getBytesUtf8(content)); encodedContent = StringUtils.newStringUtf8(encodedBytes); assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent); // bogus characters to decode (to skip actually) {e-acute*6} final byte[] decode = b64.decode("SGVsbG{\u00e9\u00e9\u00e9\u00e9\u00e9\u00e9}8gV29ybGQ="); final String decodeString = StringUtils.newStringUtf8(decode); assertEquals("decode hello world", "Hello World", decodeString); } @Test public void testBase64AtBufferStart() { testBase64InBuffer(0, 100); } @Test public void testBase64AtBufferEnd() { testBase64InBuffer(100, 0); } @Test public void testBase64AtBufferMiddle() { testBase64InBuffer(100, 100); } private void testBase64InBuffer(int startPasSize, int endPadSize) { final String content = "Hello World"; String encodedContent; final byte[] bytesUtf8 = StringUtils.getBytesUtf8(content); byte[] buffer = ArrayUtils.addAll(bytesUtf8, new byte[endPadSize]); buffer = ArrayUtils.addAll(new byte[startPasSize], buffer); byte[] encodedBytes = new Base64().encode(buffer, startPasSize, bytesUtf8.length); encodedContent = StringUtils.newStringUtf8(encodedBytes); assertEquals("encoding hello world", "SGVsbG8gV29ybGQ=", encodedContent); } /** * Test our decode with pad character in the middle. (Our current * implementation: halt decode and return what we've got so far). * * The point of this test is not to say * "this is the correct way to decode base64." The point is simply to keep * us aware of the current logic since 1.4 so we don't accidentally break it * without realizing. * * Note for historians. The 1.3 logic would decode to: * "Hello World\u0000Hello World" -- null in the middle --- and 1.4 * unwittingly changed it to current logic. */ @Test public void testDecodeWithInnerPad() { final String content = "SGVsbG8gV29ybGQ=SGVsbG8gV29ybGQ="; final byte[] result = Base64.decodeBase64(content); final byte[] shouldBe = StringUtils.getBytesUtf8("Hello World"); assertTrue("decode should halt at pad (=)", Arrays.equals(result, shouldBe)); } /** * Tests Base64.encodeBase64(). */ @Test public void testChunkedEncodeMultipleOf76() { final byte[] expectedEncode = Base64.encodeBase64(Base64TestData.DECODED, true); // convert to "\r\n" so we're equal to the old openssl encoding test // stored // in Base64TestData.ENCODED_76_CHARS_PER_LINE: final String actualResult = Base64TestData.ENCODED_76_CHARS_PER_LINE.replaceAll("\n", "\r\n"); final byte[] actualEncode = StringUtils.getBytesUtf8(actualResult); assertTrue("chunkedEncodeMultipleOf76", Arrays.equals(expectedEncode, actualEncode)); } /** * CODEC-68: isBase64 throws ArrayIndexOutOfBoundsException on some * non-BASE64 bytes */ @Test public void testCodec68() { final byte[] x = new byte[] { 'n', 'A', '=', '=', (byte) 0x9c }; Base64.decodeBase64(x); } @Test public void testCodeInteger1() { final String encodedInt1 = "li7dzDacuo67Jg7mtqEm2TRuOMU="; final BigInteger bigInt1 = new BigInteger("85739377120809420210425962799" + "0318636601332086981"); assertEquals(encodedInt1, new String(Base64.encodeInteger(bigInt1))); assertEquals(bigInt1, Base64.decodeInteger(encodedInt1.getBytes(CHARSET_UTF8))); } @Test public void testCodeInteger2() { final String encodedInt2 = "9B5ypLY9pMOmtxCeTDHgwdNFeGs="; final BigInteger bigInt2 = new BigInteger("13936727572861167254666467268" + "91466679477132949611"); assertEquals(encodedInt2, new String(Base64.encodeInteger(bigInt2))); assertEquals(bigInt2, Base64.decodeInteger(encodedInt2.getBytes(CHARSET_UTF8))); } @Test public void testCodeInteger3() { final String encodedInt3 = "FKIhdgaG5LGKiEtF1vHy4f3y700zaD6QwDS3IrNVGzNp2" + "rY+1LFWTK6D44AyiC1n8uWz1itkYMZF0/aKDK0Yjg=="; final BigInteger bigInt3 = new BigInteger( "10806548154093873461951748545" + "1196989136416448805819079363524309897749044958112417136240557" + "4495062430572478766856090958495998158114332651671116876320938126"); assertEquals(encodedInt3, new String(Base64.encodeInteger(bigInt3))); assertEquals(bigInt3, Base64.decodeInteger(encodedInt3.getBytes(CHARSET_UTF8))); } @Test public void testCodeInteger4() { final String encodedInt4 = "ctA8YGxrtngg/zKVvqEOefnwmViFztcnPBYPlJsvh6yKI" + "4iDm68fnp4Mi3RrJ6bZAygFrUIQLxLjV+OJtgJAEto0xAs+Mehuq1DkSFEpP3o" + "DzCTOsrOiS1DwQe4oIb7zVk/9l7aPtJMHW0LVlMdwZNFNNJoqMcT2ZfCPrfvYv" + "Q0="; final BigInteger bigInt4 = new BigInteger( "80624726256040348115552042320" + "6968135001872753709424419772586693950232350200555646471175944" + "519297087885987040810778908507262272892702303774422853675597" + "748008534040890923814202286633163248086055216976551456088015" + "338880713818192088877057717530169381044092839402438015097654" + "53542091716518238707344493641683483917"); assertEquals(encodedInt4, new String(Base64.encodeInteger(bigInt4))); assertEquals(bigInt4, Base64.decodeInteger(encodedInt4.getBytes(CHARSET_UTF8))); } @Test public void testCodeIntegerEdgeCases() { // TODO } @Test public void testCodeIntegerNull() { try { Base64.encodeInteger(null); fail("Exception not thrown when passing in null to encodeInteger(BigInteger)"); } catch (final NullPointerException npe) { // expected } catch (final Exception e) { fail("Incorrect Exception caught when passing in null to encodeInteger(BigInteger)"); } } @Test public void testConstructors() { Base64 base64; base64 = new Base64(); base64 = new Base64(-1); base64 = new Base64(-1, new byte[] {}); base64 = new Base64(64, new byte[] {}); try { base64 = new Base64(-1, new byte[] { 'A' }); // TODO do we need to // check sep if len // = -1? fail("Should have rejected attempt to use 'A' as a line separator"); } catch (final IllegalArgumentException ignored) { // Expected } try { base64 = new Base64(64, new byte[] { 'A' }); fail("Should have rejected attempt to use 'A' as a line separator"); } catch (final IllegalArgumentException ignored) { // Expected } try { base64 = new Base64(64, new byte[] { '=' }); fail("Should have rejected attempt to use '=' as a line separator"); } catch (final IllegalArgumentException ignored) { // Expected } base64 = new Base64(64, new byte[] { '$' }); // OK try { base64 = new Base64(64, new byte[] { 'A', '$' }); fail("Should have rejected attempt to use 'A$' as a line separator"); } catch (final IllegalArgumentException ignored) { // Expected } base64 = new Base64(64, new byte[] { ' ', '$', '\n', '\r', '\t' }); // OK assertNotNull(base64); } @Test public void testConstructor_Int_ByteArray_Boolean() { final Base64 base64 = new Base64(65, new byte[] { '\t' }, false); final byte[] encoded = base64.encode(Base64TestData.DECODED); String expectedResult = Base64TestData.ENCODED_64_CHARS_PER_LINE; expectedResult = expectedResult.replace('\n', '\t'); final String result = StringUtils.newStringUtf8(encoded); assertEquals("new Base64(65, \\t, false)", expectedResult, result); } @Test public void testConstructor_Int_ByteArray_Boolean_UrlSafe() { // url-safe variation final Base64 base64 = new Base64(64, new byte[] { '\t' }, true); final byte[] encoded = base64.encode(Base64TestData.DECODED); String expectedResult = Base64TestData.ENCODED_64_CHARS_PER_LINE; expectedResult = expectedResult.replaceAll("=", ""); // url-safe has no // == padding. expectedResult = expectedResult.replace('\n', '\t'); expectedResult = expectedResult.replace('+', '-'); expectedResult = expectedResult.replace('/', '_'); final String result = StringUtils.newStringUtf8(encoded); assertEquals("new Base64(64, \\t, true)", result, expectedResult); } /** * Tests conditional true branch for "marker0" test. */ @Test public void testDecodePadMarkerIndex2() { assertEquals("A", new String(Base64.decodeBase64("QQ==".getBytes(CHARSET_UTF8)))); } /** * Tests conditional branches for "marker1" test. */ @Test public void testDecodePadMarkerIndex3() { assertEquals("AA", new String(Base64.decodeBase64("QUE=".getBytes(CHARSET_UTF8)))); assertEquals("AAA", new String(Base64.decodeBase64("QUFB".getBytes(CHARSET_UTF8)))); } @Test public void testDecodePadOnly() { assertEquals(0, Base64.decodeBase64("====".getBytes(CHARSET_UTF8)).length); assertEquals("", new String(Base64.decodeBase64("====".getBytes(CHARSET_UTF8)))); // Test truncated padding assertEquals(0, Base64.decodeBase64("===".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("==".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("=".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("".getBytes(CHARSET_UTF8)).length); } @Test public void testDecodePadOnlyChunked() { assertEquals(0, Base64.decodeBase64("====\n".getBytes(CHARSET_UTF8)).length); assertEquals("", new String(Base64.decodeBase64("====\n".getBytes(CHARSET_UTF8)))); // Test truncated padding assertEquals(0, Base64.decodeBase64("===\n".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("==\n".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("=\n".getBytes(CHARSET_UTF8)).length); assertEquals(0, Base64.decodeBase64("\n".getBytes(CHARSET_UTF8)).length); } @Test public void testDecodeWithWhitespace() throws Exception { final String orig = "I am a late night coder."; final byte[] encodedArray = Base64.encodeBase64(orig.getBytes(CHARSET_UTF8)); final StringBuilder intermediate = new StringBuilder(new String(encodedArray)); intermediate.insert(2, ' '); intermediate.insert(5, '\t'); intermediate.insert(10, '\r'); intermediate.insert(15, '\n'); final byte[] encodedWithWS = intermediate.toString().getBytes(CHARSET_UTF8); final byte[] decodedWithWS = Base64.decodeBase64(encodedWithWS); final String dest = new String(decodedWithWS); assertEquals("Dest string doesn't equal the original", orig, dest); } /** * Test encode and decode of empty byte array. */ @Test public void testEmptyBase64() { byte[] empty = new byte[0]; byte[] result = Base64.encodeBase64(empty); assertEquals("empty base64 encode", 0, result.length); assertEquals("empty base64 encode", null, Base64.encodeBase64(null)); empty = new byte[0]; result = Base64.decodeBase64(empty); assertEquals("empty base64 decode", 0, result.length); assertEquals("empty base64 encode", null, Base64.decodeBase64((byte[]) null)); } // encode/decode a large random array @Test public void testEncodeDecodeRandom() { for (int i = 1; i < 5; i++) { final byte[] data = new byte[this.getRandom().nextInt(10000) + 1]; this.getRandom().nextBytes(data); final byte[] enc = Base64.encodeBase64(data); assertTrue(Base64.isBase64(enc)); final byte[] data2 = Base64.decodeBase64(enc); assertTrue(Arrays.equals(data, data2)); } } // encode/decode random arrays from size 0 to size 11 @Test public void testEncodeDecodeSmall() { for (int i = 0; i < 12; i++) { final byte[] data = new byte[i]; this.getRandom().nextBytes(data); final byte[] enc = Base64.encodeBase64(data); assertTrue("\"" + new String(enc) + "\" is Base64 data.", Base64.isBase64(enc)); final byte[] data2 = Base64.decodeBase64(enc); assertTrue(toString(data) + " equals " + toString(data2), Arrays.equals(data, data2)); } } @Test public void testEncodeOverMaxSize() throws Exception { testEncodeOverMaxSize(-1); testEncodeOverMaxSize(0); testEncodeOverMaxSize(1); testEncodeOverMaxSize(2); } @Test public void testCodec112() { // size calculation assumes always chunked final byte[] in = new byte[] { 0 }; final byte[] out = Base64.encodeBase64(in); Base64.encodeBase64(in, false, false, out.length); } private void testEncodeOverMaxSize(final int maxSize) throws Exception { try { Base64.encodeBase64(Base64TestData.DECODED, true, false, maxSize); fail("Expected " + IllegalArgumentException.class.getName()); } catch (final IllegalArgumentException e) { // Expected } } @Test public void testIgnoringNonBase64InDecode() throws Exception { assertEquals("The quick brown fox jumped over the lazy dogs.", new String(Base64.decodeBase64( "VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n\r\t%#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==" .getBytes(CHARSET_UTF8)))); } @Test public void testIsArrayByteBase64() { assertFalse(Base64.isBase64(new byte[] { Byte.MIN_VALUE })); assertFalse(Base64.isBase64(new byte[] { -125 })); assertFalse(Base64.isBase64(new byte[] { -10 })); assertFalse(Base64.isBase64(new byte[] { 0 })); assertFalse(Base64.isBase64(new byte[] { 64, Byte.MAX_VALUE })); assertFalse(Base64.isBase64(new byte[] { Byte.MAX_VALUE })); assertTrue(Base64.isBase64(new byte[] { 'A' })); assertFalse(Base64.isBase64(new byte[] { 'A', Byte.MIN_VALUE })); assertTrue(Base64.isBase64(new byte[] { 'A', 'Z', 'a' })); assertTrue(Base64.isBase64(new byte[] { '/', '=', '+' })); assertFalse(Base64.isBase64(new byte[] { '$' })); } /** * Tests isUrlSafe. */ @Test public void testIsUrlSafe() { final Base64 base64Standard = new Base64(false); final Base64 base64URLSafe = new Base64(true); assertFalse("Base64.isUrlSafe=false", base64Standard.isUrlSafe()); assertTrue("Base64.isUrlSafe=true", base64URLSafe.isUrlSafe()); final byte[] whiteSpace = { ' ', '\n', '\r', '\t' }; assertTrue("Base64.isBase64(whiteSpace)=true", Base64.isBase64(whiteSpace)); } @Test public void testKnownDecodings() { assertEquals("The quick brown fox jumped over the lazy dogs.", new String(Base64.decodeBase64( "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes(CHARSET_UTF8)))); assertEquals("It was the best of times, it was the worst of times.", new String(Base64.decodeBase64( "SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==".getBytes(CHARSET_UTF8)))); assertEquals("http://jakarta.apache.org/commmons", new String( Base64.decodeBase64("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==".getBytes(CHARSET_UTF8)))); assertEquals("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz", new String(Base64.decodeBase64( "QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==".getBytes(CHARSET_UTF8)))); assertEquals("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }", new String(Base64.decodeBase64("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=".getBytes(CHARSET_UTF8)))); assertEquals("xyzzy!", new String(Base64.decodeBase64("eHl6enkh".getBytes(CHARSET_UTF8)))); } @Test public void testKnownEncodings() { assertEquals("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==", new String( Base64.encodeBase64("The quick brown fox jumped over the lazy dogs.".getBytes(CHARSET_UTF8)))); assertEquals( "YmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJs\r\nYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFo\r\nIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBi\r\nbGFoIGJsYWg=\r\n", new String(Base64.encodeBase64Chunked( "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah" .getBytes(CHARSET_UTF8)))); assertEquals("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==", new String( Base64.encodeBase64("It was the best of times, it was the worst of times.".getBytes(CHARSET_UTF8)))); assertEquals("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==", new String(Base64.encodeBase64("http://jakarta.apache.org/commmons".getBytes(CHARSET_UTF8)))); assertEquals("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==", new String( Base64.encodeBase64("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz".getBytes(CHARSET_UTF8)))); assertEquals("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=", new String(Base64.encodeBase64("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }".getBytes(CHARSET_UTF8)))); assertEquals("eHl6enkh", new String(Base64.encodeBase64("xyzzy!".getBytes(CHARSET_UTF8)))); } @Test public void testNonBase64Test() throws Exception { final byte[] bArray = { '%' }; assertFalse("Invalid Base64 array was incorrectly validated as " + "an array of Base64 encoded data", Base64.isBase64(bArray)); try { final Base64 b64 = new Base64(); final byte[] result = b64.decode(bArray); assertEquals("The result should be empty as the test encoded content did " + "not contain any valid base 64 characters", 0, result.length); } catch (final Exception e) { fail("Exception was thrown when trying to decode " + "invalid base64 encoded data - RFC 2045 requires that all " + "non base64 character be discarded, an exception should not" + " have been thrown"); } } @Test public void testObjectDecodeWithInvalidParameter() throws Exception { final Base64 b64 = new Base64(); try { b64.decode(Integer.valueOf(5)); fail("decode(Object) didn't throw an exception when passed an Integer object"); } catch (final DecoderException e) { // ignored } } @Test public void testObjectDecodeWithValidParameter() throws Exception { final String original = "Hello World!"; final Object o = Base64.encodeBase64(original.getBytes(CHARSET_UTF8)); final Base64 b64 = new Base64(); final Object oDecoded = b64.decode(o); final byte[] baDecoded = (byte[]) oDecoded; final String dest = new String(baDecoded); assertEquals("dest string does not equal original", original, dest); } @Test public void testObjectEncodeWithInvalidParameter() throws Exception { final Base64 b64 = new Base64(); try { b64.encode("Yadayadayada"); fail("encode(Object) didn't throw an exception when passed a String object"); } catch (final EncoderException e) { // Expected } } @Test public void testObjectEncodeWithValidParameter() throws Exception { final String original = "Hello World!"; final Object origObj = original.getBytes(CHARSET_UTF8); final Base64 b64 = new Base64(); final Object oEncoded = b64.encode(origObj); final byte[] bArray = Base64.decodeBase64((byte[]) oEncoded); final String dest = new String(bArray); assertEquals("dest string does not equal original", original, dest); } @Test public void testObjectEncode() throws Exception { final Base64 b64 = new Base64(); assertEquals("SGVsbG8gV29ybGQ=", new String(b64.encode("Hello World".getBytes(CHARSET_UTF8)))); } @Test public void testPairs() { assertEquals("AAA=", new String(Base64.encodeBase64(new byte[] { 0, 0 }))); for (int i = -128; i <= 127; i++) { final byte test[] = { (byte) i, (byte) i }; assertTrue(Arrays.equals(test, Base64.decodeBase64(Base64.encodeBase64(test)))); } } /** * Tests RFC 2045 section 2.1 CRLF definition. */ @Test public void testRfc2045Section2Dot1CrLfDefinition() { assertTrue(Arrays.equals(new byte[] { 13, 10 }, Base64.CHUNK_SEPARATOR)); } /** * Tests RFC 2045 section 6.8 chuck size definition. */ @Test public void testRfc2045Section6Dot8ChunkSizeDefinition() { assertEquals(76, BaseNCodec.MIME_CHUNK_SIZE); } /** * Tests RFC 1421 section 4.3.2.4 chuck size definition. */ @Test public void testRfc1421Section6Dot8ChunkSizeDefinition() { assertEquals(64, BaseNCodec.PEM_CHUNK_SIZE); } /** * Tests RFC 4648 section 10 test vectors. * <ul> * <li>BASE64("") = ""</li> * <li>BASE64("f") = "Zg=="</li> * <li>BASE64("fo") = "Zm8="</li> * <li>BASE64("foo") = "Zm9v"</li> * <li>BASE64("foob") = "Zm9vYg=="</li> * <li>BASE64("fooba") = "Zm9vYmE="</li> * <li>BASE64("foobar") = "Zm9vYmFy"</li> * </ul> * * @see <a href="http://tools.ietf.org/html/rfc4648">http://tools.ietf.org/ * html/rfc4648</a> */ @Test public void testRfc4648Section10Decode() { assertEquals("", StringUtils.newStringUsAscii(Base64.decodeBase64(""))); assertEquals("f", StringUtils.newStringUsAscii(Base64.decodeBase64("Zg=="))); assertEquals("fo", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm8="))); assertEquals("foo", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm9v"))); assertEquals("foob", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm9vYg=="))); assertEquals("fooba", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm9vYmE="))); assertEquals("foobar", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm9vYmFy"))); } /** * Tests RFC 4648 section 10 test vectors. * <ul> * <li>BASE64("") = ""</li> * <li>BASE64("f") = "Zg=="</li> * <li>BASE64("fo") = "Zm8="</li> * <li>BASE64("foo") = "Zm9v"</li> * <li>BASE64("foob") = "Zm9vYg=="</li> * <li>BASE64("fooba") = "Zm9vYmE="</li> * <li>BASE64("foobar") = "Zm9vYmFy"</li> * </ul> * * @see <a href="http://tools.ietf.org/html/rfc4648">http://tools.ietf.org/ * html/rfc4648</a> */ @Test public void testRfc4648Section10DecodeWithCrLf() { final String CRLF = StringUtils.newStringUsAscii(Base64.CHUNK_SEPARATOR); assertEquals("", StringUtils.newStringUsAscii(Base64.decodeBase64("" + CRLF))); assertEquals("f", StringUtils.newStringUsAscii(Base64.decodeBase64("Zg==" + CRLF))); assertEquals("fo", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm8=" + CRLF))); assertEquals("foo", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm9v" + CRLF))); assertEquals("foob", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm9vYg==" + CRLF))); assertEquals("fooba", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm9vYmE=" + CRLF))); assertEquals("foobar", StringUtils.newStringUsAscii(Base64.decodeBase64("Zm9vYmFy" + CRLF))); } /** * Tests RFC 4648 section 10 test vectors. * <ul> * <li>BASE64("") = ""</li> * <li>BASE64("f") = "Zg=="</li> * <li>BASE64("fo") = "Zm8="</li> * <li>BASE64("foo") = "Zm9v"</li> * <li>BASE64("foob") = "Zm9vYg=="</li> * <li>BASE64("fooba") = "Zm9vYmE="</li> * <li>BASE64("foobar") = "Zm9vYmFy"</li> * </ul> * * @see <a href="http://tools.ietf.org/html/rfc4648">http://tools.ietf.org/ * html/rfc4648</a> */ @Test public void testRfc4648Section10Encode() { assertEquals("", Base64.encodeBase64String(StringUtils.getBytesUtf8(""))); assertEquals("Zg==", Base64.encodeBase64String(StringUtils.getBytesUtf8("f"))); assertEquals("Zm8=", Base64.encodeBase64String(StringUtils.getBytesUtf8("fo"))); assertEquals("Zm9v", Base64.encodeBase64String(StringUtils.getBytesUtf8("foo"))); assertEquals("Zm9vYg==", Base64.encodeBase64String(StringUtils.getBytesUtf8("foob"))); assertEquals("Zm9vYmE=", Base64.encodeBase64String(StringUtils.getBytesUtf8("fooba"))); assertEquals("Zm9vYmFy", Base64.encodeBase64String(StringUtils.getBytesUtf8("foobar"))); } /** * Tests RFC 4648 section 10 test vectors. * <ul> * <li>BASE64("") = ""</li> * <li>BASE64("f") = "Zg=="</li> * <li>BASE64("fo") = "Zm8="</li> * <li>BASE64("foo") = "Zm9v"</li> * <li>BASE64("foob") = "Zm9vYg=="</li> * <li>BASE64("fooba") = "Zm9vYmE="</li> * <li>BASE64("foobar") = "Zm9vYmFy"</li> * </ul> * * @see <a href="http://tools.ietf.org/html/rfc4648">http://tools.ietf.org/ * html/rfc4648</a> */ @Test public void testRfc4648Section10DecodeEncode() { testDecodeEncode(""); testDecodeEncode("Zg=="); testDecodeEncode("Zm8="); testDecodeEncode("Zm9v"); testDecodeEncode("Zm9vYg=="); testDecodeEncode("Zm9vYmE="); testDecodeEncode("Zm9vYmFy"); } private void testDecodeEncode(final String encodedText) { final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64(encodedText)); final String encodedText2 = Base64.encodeBase64String(StringUtils.getBytesUtf8(decodedText)); assertEquals(encodedText, encodedText2); } /** * Tests RFC 4648 section 10 test vectors. * <ul> * <li>BASE64("") = ""</li> * <li>BASE64("f") = "Zg=="</li> * <li>BASE64("fo") = "Zm8="</li> * <li>BASE64("foo") = "Zm9v"</li> * <li>BASE64("foob") = "Zm9vYg=="</li> * <li>BASE64("fooba") = "Zm9vYmE="</li> * <li>BASE64("foobar") = "Zm9vYmFy"</li> * </ul> * * @see <a href="http://tools.ietf.org/html/rfc4648">http://tools.ietf.org/ * html/rfc4648</a> */ @Test public void testRfc4648Section10EncodeDecode() { testEncodeDecode(""); testEncodeDecode("f"); testEncodeDecode("fo"); testEncodeDecode("foo"); testEncodeDecode("foob"); testEncodeDecode("fooba"); testEncodeDecode("foobar"); } private void testEncodeDecode(final String plainText) { final String encodedText = Base64.encodeBase64String(StringUtils.getBytesUtf8(plainText)); final String decodedText = StringUtils.newStringUsAscii(Base64.decodeBase64(encodedText)); assertEquals(plainText, decodedText); } @Test public void testSingletons() { assertEquals("AA==", new String(Base64.encodeBase64(new byte[] { (byte) 0 }))); assertEquals("AQ==", new String(Base64.encodeBase64(new byte[] { (byte) 1 }))); assertEquals("Ag==", new String(Base64.encodeBase64(new byte[] { (byte) 2 }))); assertEquals("Aw==", new String(Base64.encodeBase64(new byte[] { (byte) 3 }))); assertEquals("BA==", new String(Base64.encodeBase64(new byte[] { (byte) 4 }))); assertEquals("BQ==", new String(Base64.encodeBase64(new byte[] { (byte) 5 }))); assertEquals("Bg==", new String(Base64.encodeBase64(new byte[] { (byte) 6 }))); assertEquals("Bw==", new String(Base64.encodeBase64(new byte[] { (byte) 7 }))); assertEquals("CA==", new String(Base64.encodeBase64(new byte[] { (byte) 8 }))); assertEquals("CQ==", new String(Base64.encodeBase64(new byte[] { (byte) 9 }))); assertEquals("Cg==", new String(Base64.encodeBase64(new byte[] { (byte) 10 }))); assertEquals("Cw==", new String(Base64.encodeBase64(new byte[] { (byte) 11 }))); assertEquals("DA==", new String(Base64.encodeBase64(new byte[] { (byte) 12 }))); assertEquals("DQ==", new String(Base64.encodeBase64(new byte[] { (byte) 13 }))); assertEquals("Dg==", new String(Base64.encodeBase64(new byte[] { (byte) 14 }))); assertEquals("Dw==", new String(Base64.encodeBase64(new byte[] { (byte) 15 }))); assertEquals("EA==", new String(Base64.encodeBase64(new byte[] { (byte) 16 }))); assertEquals("EQ==", new String(Base64.encodeBase64(new byte[] { (byte) 17 }))); assertEquals("Eg==", new String(Base64.encodeBase64(new byte[] { (byte) 18 }))); assertEquals("Ew==", new String(Base64.encodeBase64(new byte[] { (byte) 19 }))); assertEquals("FA==", new String(Base64.encodeBase64(new byte[] { (byte) 20 }))); assertEquals("FQ==", new String(Base64.encodeBase64(new byte[] { (byte) 21 }))); assertEquals("Fg==", new String(Base64.encodeBase64(new byte[] { (byte) 22 }))); assertEquals("Fw==", new String(Base64.encodeBase64(new byte[] { (byte) 23 }))); assertEquals("GA==", new String(Base64.encodeBase64(new byte[] { (byte) 24 }))); assertEquals("GQ==", new String(Base64.encodeBase64(new byte[] { (byte) 25 }))); assertEquals("Gg==", new String(Base64.encodeBase64(new byte[] { (byte) 26 }))); assertEquals("Gw==", new String(Base64.encodeBase64(new byte[] { (byte) 27 }))); assertEquals("HA==", new String(Base64.encodeBase64(new byte[] { (byte) 28 }))); assertEquals("HQ==", new String(Base64.encodeBase64(new byte[] { (byte) 29 }))); assertEquals("Hg==", new String(Base64.encodeBase64(new byte[] { (byte) 30 }))); assertEquals("Hw==", new String(Base64.encodeBase64(new byte[] { (byte) 31 }))); assertEquals("IA==", new String(Base64.encodeBase64(new byte[] { (byte) 32 }))); assertEquals("IQ==", new String(Base64.encodeBase64(new byte[] { (byte) 33 }))); assertEquals("Ig==", new String(Base64.encodeBase64(new byte[] { (byte) 34 }))); assertEquals("Iw==", new String(Base64.encodeBase64(new byte[] { (byte) 35 }))); assertEquals("JA==", new String(Base64.encodeBase64(new byte[] { (byte) 36 }))); assertEquals("JQ==", new String(Base64.encodeBase64(new byte[] { (byte) 37 }))); assertEquals("Jg==", new String(Base64.encodeBase64(new byte[] { (byte) 38 }))); assertEquals("Jw==", new String(Base64.encodeBase64(new byte[] { (byte) 39 }))); assertEquals("KA==", new String(Base64.encodeBase64(new byte[] { (byte) 40 }))); assertEquals("KQ==", new String(Base64.encodeBase64(new byte[] { (byte) 41 }))); assertEquals("Kg==", new String(Base64.encodeBase64(new byte[] { (byte) 42 }))); assertEquals("Kw==", new String(Base64.encodeBase64(new byte[] { (byte) 43 }))); assertEquals("LA==", new String(Base64.encodeBase64(new byte[] { (byte) 44 }))); assertEquals("LQ==", new String(Base64.encodeBase64(new byte[] { (byte) 45 }))); assertEquals("Lg==", new String(Base64.encodeBase64(new byte[] { (byte) 46 }))); assertEquals("Lw==", new String(Base64.encodeBase64(new byte[] { (byte) 47 }))); assertEquals("MA==", new String(Base64.encodeBase64(new byte[] { (byte) 48 }))); assertEquals("MQ==", new String(Base64.encodeBase64(new byte[] { (byte) 49 }))); assertEquals("Mg==", new String(Base64.encodeBase64(new byte[] { (byte) 50 }))); assertEquals("Mw==", new String(Base64.encodeBase64(new byte[] { (byte) 51 }))); assertEquals("NA==", new String(Base64.encodeBase64(new byte[] { (byte) 52 }))); assertEquals("NQ==", new String(Base64.encodeBase64(new byte[] { (byte) 53 }))); assertEquals("Ng==", new String(Base64.encodeBase64(new byte[] { (byte) 54 }))); assertEquals("Nw==", new String(Base64.encodeBase64(new byte[] { (byte) 55 }))); assertEquals("OA==", new String(Base64.encodeBase64(new byte[] { (byte) 56 }))); assertEquals("OQ==", new String(Base64.encodeBase64(new byte[] { (byte) 57 }))); assertEquals("Og==", new String(Base64.encodeBase64(new byte[] { (byte) 58 }))); assertEquals("Ow==", new String(Base64.encodeBase64(new byte[] { (byte) 59 }))); assertEquals("PA==", new String(Base64.encodeBase64(new byte[] { (byte) 60 }))); assertEquals("PQ==", new String(Base64.encodeBase64(new byte[] { (byte) 61 }))); assertEquals("Pg==", new String(Base64.encodeBase64(new byte[] { (byte) 62 }))); assertEquals("Pw==", new String(Base64.encodeBase64(new byte[] { (byte) 63 }))); assertEquals("QA==", new String(Base64.encodeBase64(new byte[] { (byte) 64 }))); assertEquals("QQ==", new String(Base64.encodeBase64(new byte[] { (byte) 65 }))); assertEquals("Qg==", new String(Base64.encodeBase64(new byte[] { (byte) 66 }))); assertEquals("Qw==", new String(Base64.encodeBase64(new byte[] { (byte) 67 }))); assertEquals("RA==", new String(Base64.encodeBase64(new byte[] { (byte) 68 }))); assertEquals("RQ==", new String(Base64.encodeBase64(new byte[] { (byte) 69 }))); assertEquals("Rg==", new String(Base64.encodeBase64(new byte[] { (byte) 70 }))); assertEquals("Rw==", new String(Base64.encodeBase64(new byte[] { (byte) 71 }))); assertEquals("SA==", new String(Base64.encodeBase64(new byte[] { (byte) 72 }))); assertEquals("SQ==", new String(Base64.encodeBase64(new byte[] { (byte) 73 }))); assertEquals("Sg==", new String(Base64.encodeBase64(new byte[] { (byte) 74 }))); assertEquals("Sw==", new String(Base64.encodeBase64(new byte[] { (byte) 75 }))); assertEquals("TA==", new String(Base64.encodeBase64(new byte[] { (byte) 76 }))); assertEquals("TQ==", new String(Base64.encodeBase64(new byte[] { (byte) 77 }))); assertEquals("Tg==", new String(Base64.encodeBase64(new byte[] { (byte) 78 }))); assertEquals("Tw==", new String(Base64.encodeBase64(new byte[] { (byte) 79 }))); assertEquals("UA==", new String(Base64.encodeBase64(new byte[] { (byte) 80 }))); assertEquals("UQ==", new String(Base64.encodeBase64(new byte[] { (byte) 81 }))); assertEquals("Ug==", new String(Base64.encodeBase64(new byte[] { (byte) 82 }))); assertEquals("Uw==", new String(Base64.encodeBase64(new byte[] { (byte) 83 }))); assertEquals("VA==", new String(Base64.encodeBase64(new byte[] { (byte) 84 }))); assertEquals("VQ==", new String(Base64.encodeBase64(new byte[] { (byte) 85 }))); assertEquals("Vg==", new String(Base64.encodeBase64(new byte[] { (byte) 86 }))); assertEquals("Vw==", new String(Base64.encodeBase64(new byte[] { (byte) 87 }))); assertEquals("WA==", new String(Base64.encodeBase64(new byte[] { (byte) 88 }))); assertEquals("WQ==", new String(Base64.encodeBase64(new byte[] { (byte) 89 }))); assertEquals("Wg==", new String(Base64.encodeBase64(new byte[] { (byte) 90 }))); assertEquals("Ww==", new String(Base64.encodeBase64(new byte[] { (byte) 91 }))); assertEquals("XA==", new String(Base64.encodeBase64(new byte[] { (byte) 92 }))); assertEquals("XQ==", new String(Base64.encodeBase64(new byte[] { (byte) 93 }))); assertEquals("Xg==", new String(Base64.encodeBase64(new byte[] { (byte) 94 }))); assertEquals("Xw==", new String(Base64.encodeBase64(new byte[] { (byte) 95 }))); assertEquals("YA==", new String(Base64.encodeBase64(new byte[] { (byte) 96 }))); assertEquals("YQ==", new String(Base64.encodeBase64(new byte[] { (byte) 97 }))); assertEquals("Yg==", new String(Base64.encodeBase64(new byte[] { (byte) 98 }))); assertEquals("Yw==", new String(Base64.encodeBase64(new byte[] { (byte) 99 }))); assertEquals("ZA==", new String(Base64.encodeBase64(new byte[] { (byte) 100 }))); assertEquals("ZQ==", new String(Base64.encodeBase64(new byte[] { (byte) 101 }))); assertEquals("Zg==", new String(Base64.encodeBase64(new byte[] { (byte) 102 }))); assertEquals("Zw==", new String(Base64.encodeBase64(new byte[] { (byte) 103 }))); assertEquals("aA==", new String(Base64.encodeBase64(new byte[] { (byte) 104 }))); for (int i = -128; i <= 127; i++) { final byte test[] = { (byte) i }; assertTrue(Arrays.equals(test, Base64.decodeBase64(Base64.encodeBase64(test)))); } } @Test public void testSingletonsChunked() { assertEquals("AA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0 }))); assertEquals("AQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 1 }))); assertEquals("Ag==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 2 }))); assertEquals("Aw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 3 }))); assertEquals("BA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 4 }))); assertEquals("BQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 5 }))); assertEquals("Bg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 6 }))); assertEquals("Bw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 7 }))); assertEquals("CA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 8 }))); assertEquals("CQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 9 }))); assertEquals("Cg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 10 }))); assertEquals("Cw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 11 }))); assertEquals("DA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 12 }))); assertEquals("DQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 13 }))); assertEquals("Dg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 14 }))); assertEquals("Dw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 15 }))); assertEquals("EA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 16 }))); assertEquals("EQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 17 }))); assertEquals("Eg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 18 }))); assertEquals("Ew==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 19 }))); assertEquals("FA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 20 }))); assertEquals("FQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 21 }))); assertEquals("Fg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 22 }))); assertEquals("Fw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 23 }))); assertEquals("GA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 24 }))); assertEquals("GQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 25 }))); assertEquals("Gg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 26 }))); assertEquals("Gw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 27 }))); assertEquals("HA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 28 }))); assertEquals("HQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 29 }))); assertEquals("Hg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 30 }))); assertEquals("Hw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 31 }))); assertEquals("IA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 32 }))); assertEquals("IQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 33 }))); assertEquals("Ig==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 34 }))); assertEquals("Iw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 35 }))); assertEquals("JA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 36 }))); assertEquals("JQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 37 }))); assertEquals("Jg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 38 }))); assertEquals("Jw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 39 }))); assertEquals("KA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 40 }))); assertEquals("KQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 41 }))); assertEquals("Kg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 42 }))); assertEquals("Kw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 43 }))); assertEquals("LA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 44 }))); assertEquals("LQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 45 }))); assertEquals("Lg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 46 }))); assertEquals("Lw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 47 }))); assertEquals("MA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 48 }))); assertEquals("MQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 49 }))); assertEquals("Mg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 50 }))); assertEquals("Mw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 51 }))); assertEquals("NA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 52 }))); assertEquals("NQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 53 }))); assertEquals("Ng==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 54 }))); assertEquals("Nw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 55 }))); assertEquals("OA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 56 }))); assertEquals("OQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 57 }))); assertEquals("Og==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 58 }))); assertEquals("Ow==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 59 }))); assertEquals("PA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 60 }))); assertEquals("PQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 61 }))); assertEquals("Pg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 62 }))); assertEquals("Pw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 63 }))); assertEquals("QA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 64 }))); assertEquals("QQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 65 }))); assertEquals("Qg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 66 }))); assertEquals("Qw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 67 }))); assertEquals("RA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 68 }))); assertEquals("RQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 69 }))); assertEquals("Rg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 70 }))); assertEquals("Rw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 71 }))); assertEquals("SA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 72 }))); assertEquals("SQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 73 }))); assertEquals("Sg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 74 }))); assertEquals("Sw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 75 }))); assertEquals("TA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 76 }))); assertEquals("TQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 77 }))); assertEquals("Tg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 78 }))); assertEquals("Tw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 79 }))); assertEquals("UA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 80 }))); assertEquals("UQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 81 }))); assertEquals("Ug==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 82 }))); assertEquals("Uw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 83 }))); assertEquals("VA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 84 }))); assertEquals("VQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 85 }))); assertEquals("Vg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 86 }))); assertEquals("Vw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 87 }))); assertEquals("WA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 88 }))); assertEquals("WQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 89 }))); assertEquals("Wg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 90 }))); assertEquals("Ww==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 91 }))); assertEquals("XA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 92 }))); assertEquals("XQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 93 }))); assertEquals("Xg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 94 }))); assertEquals("Xw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 95 }))); assertEquals("YA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 96 }))); assertEquals("YQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 97 }))); assertEquals("Yg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 98 }))); assertEquals("Yw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 99 }))); assertEquals("ZA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 100 }))); assertEquals("ZQ==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 101 }))); assertEquals("Zg==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 102 }))); assertEquals("Zw==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 103 }))); assertEquals("aA==\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 104 }))); } @Test public void testTriplets() { assertEquals("AAAA", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 0 }))); assertEquals("AAAB", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 1 }))); assertEquals("AAAC", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 2 }))); assertEquals("AAAD", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 3 }))); assertEquals("AAAE", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 4 }))); assertEquals("AAAF", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 5 }))); assertEquals("AAAG", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 6 }))); assertEquals("AAAH", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 7 }))); assertEquals("AAAI", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 8 }))); assertEquals("AAAJ", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 9 }))); assertEquals("AAAK", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 10 }))); assertEquals("AAAL", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 11 }))); assertEquals("AAAM", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 12 }))); assertEquals("AAAN", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 13 }))); assertEquals("AAAO", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 14 }))); assertEquals("AAAP", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 15 }))); assertEquals("AAAQ", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 16 }))); assertEquals("AAAR", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 17 }))); assertEquals("AAAS", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 18 }))); assertEquals("AAAT", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 19 }))); assertEquals("AAAU", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 20 }))); assertEquals("AAAV", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 21 }))); assertEquals("AAAW", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 22 }))); assertEquals("AAAX", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 23 }))); assertEquals("AAAY", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 24 }))); assertEquals("AAAZ", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 25 }))); assertEquals("AAAa", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 26 }))); assertEquals("AAAb", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 27 }))); assertEquals("AAAc", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 28 }))); assertEquals("AAAd", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 29 }))); assertEquals("AAAe", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 30 }))); assertEquals("AAAf", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 31 }))); assertEquals("AAAg", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 32 }))); assertEquals("AAAh", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 33 }))); assertEquals("AAAi", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 34 }))); assertEquals("AAAj", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 35 }))); assertEquals("AAAk", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 36 }))); assertEquals("AAAl", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 37 }))); assertEquals("AAAm", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 38 }))); assertEquals("AAAn", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 39 }))); assertEquals("AAAo", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 40 }))); assertEquals("AAAp", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 41 }))); assertEquals("AAAq", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 42 }))); assertEquals("AAAr", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 43 }))); assertEquals("AAAs", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 44 }))); assertEquals("AAAt", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 45 }))); assertEquals("AAAu", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 46 }))); assertEquals("AAAv", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 47 }))); assertEquals("AAAw", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 48 }))); assertEquals("AAAx", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 49 }))); assertEquals("AAAy", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 50 }))); assertEquals("AAAz", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 51 }))); assertEquals("AAA0", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 52 }))); assertEquals("AAA1", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 53 }))); assertEquals("AAA2", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 54 }))); assertEquals("AAA3", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 55 }))); assertEquals("AAA4", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 56 }))); assertEquals("AAA5", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 57 }))); assertEquals("AAA6", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 58 }))); assertEquals("AAA7", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 59 }))); assertEquals("AAA8", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 60 }))); assertEquals("AAA9", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 61 }))); assertEquals("AAA+", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 62 }))); assertEquals("AAA/", new String(Base64.encodeBase64(new byte[] { (byte) 0, (byte) 0, (byte) 63 }))); } @Test public void testTripletsChunked() { assertEquals("AAAA\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 0 }))); assertEquals("AAAB\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 1 }))); assertEquals("AAAC\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 2 }))); assertEquals("AAAD\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 3 }))); assertEquals("AAAE\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 4 }))); assertEquals("AAAF\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 5 }))); assertEquals("AAAG\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 6 }))); assertEquals("AAAH\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 7 }))); assertEquals("AAAI\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 8 }))); assertEquals("AAAJ\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 9 }))); assertEquals("AAAK\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 10 }))); assertEquals("AAAL\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 11 }))); assertEquals("AAAM\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 12 }))); assertEquals("AAAN\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 13 }))); assertEquals("AAAO\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 14 }))); assertEquals("AAAP\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 15 }))); assertEquals("AAAQ\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 16 }))); assertEquals("AAAR\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 17 }))); assertEquals("AAAS\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 18 }))); assertEquals("AAAT\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 19 }))); assertEquals("AAAU\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 20 }))); assertEquals("AAAV\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 21 }))); assertEquals("AAAW\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 22 }))); assertEquals("AAAX\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 23 }))); assertEquals("AAAY\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 24 }))); assertEquals("AAAZ\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 25 }))); assertEquals("AAAa\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 26 }))); assertEquals("AAAb\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 27 }))); assertEquals("AAAc\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 28 }))); assertEquals("AAAd\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 29 }))); assertEquals("AAAe\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 30 }))); assertEquals("AAAf\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 31 }))); assertEquals("AAAg\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 32 }))); assertEquals("AAAh\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 33 }))); assertEquals("AAAi\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 34 }))); assertEquals("AAAj\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 35 }))); assertEquals("AAAk\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 36 }))); assertEquals("AAAl\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 37 }))); assertEquals("AAAm\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 38 }))); assertEquals("AAAn\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 39 }))); assertEquals("AAAo\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 40 }))); assertEquals("AAAp\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 41 }))); assertEquals("AAAq\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 42 }))); assertEquals("AAAr\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 43 }))); assertEquals("AAAs\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 44 }))); assertEquals("AAAt\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 45 }))); assertEquals("AAAu\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 46 }))); assertEquals("AAAv\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 47 }))); assertEquals("AAAw\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 48 }))); assertEquals("AAAx\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 49 }))); assertEquals("AAAy\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 50 }))); assertEquals("AAAz\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 51 }))); assertEquals("AAA0\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 52 }))); assertEquals("AAA1\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 53 }))); assertEquals("AAA2\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 54 }))); assertEquals("AAA3\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 55 }))); assertEquals("AAA4\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 56 }))); assertEquals("AAA5\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 57 }))); assertEquals("AAA6\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 58 }))); assertEquals("AAA7\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 59 }))); assertEquals("AAA8\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 60 }))); assertEquals("AAA9\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 61 }))); assertEquals("AAA+\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 62 }))); assertEquals("AAA/\r\n", new String(Base64.encodeBase64Chunked(new byte[] { (byte) 0, (byte) 0, (byte) 63 }))); } /** * Tests url-safe Base64 against random data, sizes 0 to 150. */ @Test public void testUrlSafe() { // test random data of sizes 0 thru 150 for (int i = 0; i <= 150; i++) { final byte[][] randomData = Base64TestData.randomData(i, true); final byte[] encoded = randomData[1]; final byte[] decoded = randomData[0]; final byte[] result = Base64.decodeBase64(encoded); assertTrue("url-safe i=" + i, Arrays.equals(decoded, result)); assertFalse("url-safe i=" + i + " no '='", Base64TestData.bytesContain(encoded, (byte) '=')); assertFalse("url-safe i=" + i + " no '\\'", Base64TestData.bytesContain(encoded, (byte) '\\')); assertFalse("url-safe i=" + i + " no '+'", Base64TestData.bytesContain(encoded, (byte) '+')); } } /** * Base64 encoding of UUID's is a common use-case, especially in URL-SAFE * mode. This test case ends up being the "URL-SAFE" JUnit's. * * @throws DecoderException * if Hex.decode() fails - a serious problem since Hex comes * from our own commons-codec! */ @Test public void testUUID() throws DecoderException { // The 4 UUID's below contains mixtures of + and / to help us test the // URL-SAFE encoding mode. final byte[][] ids = new byte[4][]; // ids[0] was chosen so that it encodes with at least one +. ids[0] = Hex.decodeHex("94ed8d0319e4493399560fb67404d370"); // ids[1] was chosen so that it encodes with both / and +. ids[1] = Hex.decodeHex("2bf7cc2701fe4397b49ebeed5acc7090"); // ids[2] was chosen so that it encodes with at least one /. ids[2] = Hex.decodeHex("64be154b6ffa40258d1a01288e7c31ca"); // ids[3] was chosen so that it encodes with both / and +, with / // right at the beginning. ids[3] = Hex.decodeHex("ff7f8fc01cdb471a8c8b5a9306183fe8"); final byte[][] standard = new byte[4][]; standard[0] = StringUtils.getBytesUtf8("lO2NAxnkSTOZVg+2dATTcA=="); standard[1] = StringUtils.getBytesUtf8("K/fMJwH+Q5e0nr7tWsxwkA=="); standard[2] = StringUtils.getBytesUtf8("ZL4VS2/6QCWNGgEojnwxyg=="); standard[3] = StringUtils.getBytesUtf8("/3+PwBzbRxqMi1qTBhg/6A=="); final byte[][] urlSafe1 = new byte[4][]; // regular padding (two '==' signs). urlSafe1[0] = StringUtils.getBytesUtf8("lO2NAxnkSTOZVg-2dATTcA=="); urlSafe1[1] = StringUtils.getBytesUtf8("K_fMJwH-Q5e0nr7tWsxwkA=="); urlSafe1[2] = StringUtils.getBytesUtf8("ZL4VS2_6QCWNGgEojnwxyg=="); urlSafe1[3] = StringUtils.getBytesUtf8("_3-PwBzbRxqMi1qTBhg_6A=="); final byte[][] urlSafe2 = new byte[4][]; // single padding (only one '=' sign). urlSafe2[0] = StringUtils.getBytesUtf8("lO2NAxnkSTOZVg-2dATTcA="); urlSafe2[1] = StringUtils.getBytesUtf8("K_fMJwH-Q5e0nr7tWsxwkA="); urlSafe2[2] = StringUtils.getBytesUtf8("ZL4VS2_6QCWNGgEojnwxyg="); urlSafe2[3] = StringUtils.getBytesUtf8("_3-PwBzbRxqMi1qTBhg_6A="); final byte[][] urlSafe3 = new byte[4][]; // no padding (no '=' signs). urlSafe3[0] = StringUtils.getBytesUtf8("lO2NAxnkSTOZVg-2dATTcA"); urlSafe3[1] = StringUtils.getBytesUtf8("K_fMJwH-Q5e0nr7tWsxwkA"); urlSafe3[2] = StringUtils.getBytesUtf8("ZL4VS2_6QCWNGgEojnwxyg"); urlSafe3[3] = StringUtils.getBytesUtf8("_3-PwBzbRxqMi1qTBhg_6A"); for (int i = 0; i < 4; i++) { final byte[] encodedStandard = Base64.encodeBase64(ids[i]); final byte[] encodedUrlSafe = Base64.encodeBase64URLSafe(ids[i]); final byte[] decodedStandard = Base64.decodeBase64(standard[i]); final byte[] decodedUrlSafe1 = Base64.decodeBase64(urlSafe1[i]); final byte[] decodedUrlSafe2 = Base64.decodeBase64(urlSafe2[i]); final byte[] decodedUrlSafe3 = Base64.decodeBase64(urlSafe3[i]); // Very important debugging output should anyone // ever need to delve closely into this stuff. // { // System.out.println("reference: [" + Hex.encodeHexString(ids[i]) + "]"); // System.out.println("standard: [" + Hex.encodeHexString(decodedStandard) + "] From: [" // + StringUtils.newStringUtf8(standard[i]) + "]"); // System.out.println("safe1: [" + Hex.encodeHexString(decodedUrlSafe1) + "] From: [" // + StringUtils.newStringUtf8(urlSafe1[i]) + "]"); // System.out.println("safe2: [" + Hex.encodeHexString(decodedUrlSafe2) + "] From: [" // + StringUtils.newStringUtf8(urlSafe2[i]) + "]"); // System.out.println("safe3: [" + Hex.encodeHexString(decodedUrlSafe3) + "] From: [" // + StringUtils.newStringUtf8(urlSafe3[i]) + "]"); // } assertTrue("standard encode uuid", Arrays.equals(encodedStandard, standard[i])); assertTrue("url-safe encode uuid", Arrays.equals(encodedUrlSafe, urlSafe3[i])); assertTrue("standard decode uuid", Arrays.equals(decodedStandard, ids[i])); assertTrue("url-safe1 decode uuid", Arrays.equals(decodedUrlSafe1, ids[i])); assertTrue("url-safe2 decode uuid", Arrays.equals(decodedUrlSafe2, ids[i])); assertTrue("url-safe3 decode uuid", Arrays.equals(decodedUrlSafe3, ids[i])); } } @Test public void testByteToStringVariations() throws DecoderException { final Base64 base64 = new Base64(0); final byte[] b1 = StringUtils.getBytesUtf8("Hello World"); final byte[] b2 = new byte[0]; final byte[] b3 = null; final byte[] b4 = Hex.decodeHex("2bf7cc2701fe4397b49ebeed5acc7090"); // for // url-safe // tests assertEquals("byteToString Hello World", "SGVsbG8gV29ybGQ=", base64.encodeToString(b1)); assertEquals("byteToString static Hello World", "SGVsbG8gV29ybGQ=", Base64.encodeBase64String(b1)); assertEquals("byteToString \"\"", "", base64.encodeToString(b2)); assertEquals("byteToString static \"\"", "", Base64.encodeBase64String(b2)); assertEquals("byteToString null", null, base64.encodeToString(b3)); assertEquals("byteToString static null", null, Base64.encodeBase64String(b3)); assertEquals("byteToString UUID", "K/fMJwH+Q5e0nr7tWsxwkA==", base64.encodeToString(b4)); assertEquals("byteToString static UUID", "K/fMJwH+Q5e0nr7tWsxwkA==", Base64.encodeBase64String(b4)); assertEquals("byteToString static-url-safe UUID", "K_fMJwH-Q5e0nr7tWsxwkA", Base64.encodeBase64URLSafeString(b4)); } @Test public void testStringToByteVariations() throws DecoderException { final Base64 base64 = new Base64(); final String s1 = "SGVsbG8gV29ybGQ=\r\n"; final String s2 = ""; final String s3 = null; final String s4a = "K/fMJwH+Q5e0nr7tWsxwkA==\r\n"; final String s4b = "K_fMJwH-Q5e0nr7tWsxwkA"; final byte[] b4 = Hex.decodeHex("2bf7cc2701fe4397b49ebeed5acc7090"); // for // url-safe // tests assertEquals("StringToByte Hello World", "Hello World", StringUtils.newStringUtf8(base64.decode(s1))); assertEquals("StringToByte Hello World", "Hello World", StringUtils.newStringUtf8((byte[]) base64.decode((Object) s1))); assertEquals("StringToByte static Hello World", "Hello World", StringUtils.newStringUtf8(Base64.decodeBase64(s1))); assertEquals("StringToByte \"\"", "", StringUtils.newStringUtf8(base64.decode(s2))); assertEquals("StringToByte static \"\"", "", StringUtils.newStringUtf8(Base64.decodeBase64(s2))); assertEquals("StringToByte null", null, StringUtils.newStringUtf8(base64.decode(s3))); assertEquals("StringToByte static null", null, StringUtils.newStringUtf8(Base64.decodeBase64(s3))); assertTrue("StringToByte UUID", Arrays.equals(b4, base64.decode(s4b))); assertTrue("StringToByte static UUID", Arrays.equals(b4, Base64.decodeBase64(s4a))); assertTrue("StringToByte static-url-safe UUID", Arrays.equals(b4, Base64.decodeBase64(s4b))); } private String toString(final byte[] data) { final StringBuilder buf = new StringBuilder(); for (int i = 0; i < data.length; i++) { buf.append(data[i]); if (i != data.length - 1) { buf.append(","); } } return buf.toString(); } /** * Tests a lineSeparator much bigger than DEFAULT_BUFFER_SIZE. * * @see "<a href='http://mail-archives.apache.org/mod_mbox/commons-dev/201202.mbox/%[email protected]%3E'>[email protected]</a>" */ @Test @Ignore public void testHugeLineSeparator() { final int BaseNCodec_DEFAULT_BUFFER_SIZE = 8192; final int Base64_BYTES_PER_ENCODED_BLOCK = 4; final byte[] baLineSeparator = new byte[BaseNCodec_DEFAULT_BUFFER_SIZE * 4 - 3]; final Base64 b64 = new Base64(Base64_BYTES_PER_ENCODED_BLOCK, baLineSeparator); final String strOriginal = "Hello World"; final String strDecoded = new String(b64.decode(b64.encode(StringUtils.getBytesUtf8(strOriginal)))); assertEquals("testDEFAULT_BUFFER_SIZE", strOriginal, strDecoded); } }
[ { "be_test_class_file": "org/apache/commons/codec/binary/Base64.java", "be_test_class_name": "org.apache.commons.codec.binary.Base64", "be_test_function_name": "decode", "be_test_function_signature": "([BIILorg/apache/commons/codec/binary/BaseNCodec$Context;)V", "line_numbers": [ "431", "432", "434", "435", "437", "438", "439", "440", "442", "443", "445", "446", "447", "448", "449", "450", "451", "452", "453", "462", "463", "467", "471", "473", "474", "475", "477", "478", "479", "480", "482", "485" ], "method_line_rate": 0.8125 }, { "be_test_class_file": "org/apache/commons/codec/binary/Base64.java", "be_test_class_name": "org.apache.commons.codec.binary.Base64", "be_test_function_name": "decodeBase64", "be_test_function_signature": "(Ljava/lang/String;)[B", "line_numbers": [ "693" ], "method_line_rate": 1 }, { "be_test_class_file": "org/apache/commons/codec/binary/Base64.java", "be_test_class_name": "org.apache.commons.codec.binary.Base64", "be_test_function_name": "isInAlphabet", "be_test_function_signature": "(B)Z", "line_numbers": [ "782" ], "method_line_rate": 1 } ]
public class QuarterTests extends TestCase
public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Calendar c = new GregorianCalendar(zone); Quarter q1 = new Quarter(new Date(1017619199999L), zone, Locale.getDefault()); Quarter q2 = new Quarter(new Date(1017619200000L), zone, Locale.getDefault()); assertEquals(1, q1.getQuarter()); assertEquals(1017619199999L, q1.getLastMillisecond(c)); assertEquals(2, q2.getQuarter()); assertEquals(1017619200000L, q2.getFirstMillisecond(c)); }
// // Abstract Java Tested Class // package org.jfree.data.time; // // import java.io.Serializable; // import java.util.Calendar; // import java.util.Date; // import java.util.Locale; // import java.util.TimeZone; // // // // public class Quarter extends RegularTimePeriod implements Serializable { // private static final long serialVersionUID = 3810061714380888671L; // public static final int FIRST_QUARTER = 1; // public static final int LAST_QUARTER = 4; // public static final int[] FIRST_MONTH_IN_QUARTER = { // 0, MonthConstants.JANUARY, MonthConstants.APRIL, MonthConstants.JULY, // MonthConstants.OCTOBER // }; // public static final int[] LAST_MONTH_IN_QUARTER = { // 0, MonthConstants.MARCH, MonthConstants.JUNE, MonthConstants.SEPTEMBER, // MonthConstants.DECEMBER // }; // private short year; // private byte quarter; // private long firstMillisecond; // private long lastMillisecond; // // public Quarter(); // public Quarter(int quarter, int year); // public Quarter(int quarter, Year year); // public Quarter(Date time); // public Quarter(Date time, TimeZone zone); // public Quarter(Date time, TimeZone zone, Locale locale); // public int getQuarter(); // public Year getYear(); // public int getYearValue(); // public long getFirstMillisecond(); // public long getLastMillisecond(); // public void peg(Calendar calendar); // public RegularTimePeriod previous(); // public RegularTimePeriod next(); // public long getSerialIndex(); // public boolean equals(Object obj); // public int hashCode(); // public int compareTo(Object o1); // public String toString(); // public long getFirstMillisecond(Calendar calendar); // public long getLastMillisecond(Calendar calendar); // public static Quarter parseQuarter(String s); // } // // // Abstract Java Test Class // package org.jfree.data.time.junit; // // import java.io.ByteArrayInputStream; // import java.io.ByteArrayOutputStream; // import java.io.ObjectInput; // import java.io.ObjectInputStream; // import java.io.ObjectOutput; // import java.io.ObjectOutputStream; // import java.util.Calendar; // import java.util.Date; // import java.util.GregorianCalendar; // import java.util.Locale; // import java.util.TimeZone; // import junit.framework.Test; // import junit.framework.TestCase; // import junit.framework.TestSuite; // import org.jfree.data.time.Quarter; // import org.jfree.data.time.TimePeriodFormatException; // import org.jfree.data.time.Year; // // // // public class QuarterTests extends TestCase { // private Quarter q1Y1900; // private Quarter q2Y1900; // private Quarter q3Y9999; // private Quarter q4Y9999; // // public static Test suite(); // public QuarterTests(String name); // protected void setUp(); // public void testEqualsSelf(); // public void testEquals(); // public void testDateConstructor1(); // public void testDateConstructor2(); // public void testQ1Y1900Previous(); // public void testQ1Y1900Next(); // public void testQ4Y9999Previous(); // public void testQ4Y9999Next(); // public void testParseQuarter(); // public void testSerialization(); // public void testHashcode(); // public void testNotCloneable(); // public void testConstructor(); // public void testGetFirstMillisecond(); // public void testGetFirstMillisecondWithTimeZone(); // public void testGetFirstMillisecondWithCalendar(); // public void testGetLastMillisecond(); // public void testGetLastMillisecondWithTimeZone(); // public void testGetLastMillisecondWithCalendar(); // public void testGetSerialIndex(); // public void testNext(); // public void testGetStart(); // public void testGetEnd(); // } // You are a professional Java test case writer, please create a test case named `testDateConstructor1` for the `Quarter` class, utilizing the provided abstract Java class context information and the following natural language annotations. /** * In GMT, the end of Q1 2002 is java.util.Date(1017619199999L). Use this * to check the quarter constructor. */
tests/org/jfree/data/time/junit/QuarterTests.java
package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone;
public Quarter(); public Quarter(int quarter, int year); public Quarter(int quarter, Year year); public Quarter(Date time); public Quarter(Date time, TimeZone zone); public Quarter(Date time, TimeZone zone, Locale locale); public int getQuarter(); public Year getYear(); public int getYearValue(); public long getFirstMillisecond(); public long getLastMillisecond(); public void peg(Calendar calendar); public RegularTimePeriod previous(); public RegularTimePeriod next(); public long getSerialIndex(); public boolean equals(Object obj); public int hashCode(); public int compareTo(Object o1); public String toString(); public long getFirstMillisecond(Calendar calendar); public long getLastMillisecond(Calendar calendar); public static Quarter parseQuarter(String s);
150
testDateConstructor1
```java // Abstract Java Tested Class package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Quarter extends RegularTimePeriod implements Serializable { private static final long serialVersionUID = 3810061714380888671L; public static final int FIRST_QUARTER = 1; public static final int LAST_QUARTER = 4; public static final int[] FIRST_MONTH_IN_QUARTER = { 0, MonthConstants.JANUARY, MonthConstants.APRIL, MonthConstants.JULY, MonthConstants.OCTOBER }; public static final int[] LAST_MONTH_IN_QUARTER = { 0, MonthConstants.MARCH, MonthConstants.JUNE, MonthConstants.SEPTEMBER, MonthConstants.DECEMBER }; private short year; private byte quarter; private long firstMillisecond; private long lastMillisecond; public Quarter(); public Quarter(int quarter, int year); public Quarter(int quarter, Year year); public Quarter(Date time); public Quarter(Date time, TimeZone zone); public Quarter(Date time, TimeZone zone, Locale locale); public int getQuarter(); public Year getYear(); public int getYearValue(); public long getFirstMillisecond(); public long getLastMillisecond(); public void peg(Calendar calendar); public RegularTimePeriod previous(); public RegularTimePeriod next(); public long getSerialIndex(); public boolean equals(Object obj); public int hashCode(); public int compareTo(Object o1); public String toString(); public long getFirstMillisecond(Calendar calendar); public long getLastMillisecond(Calendar calendar); public static Quarter parseQuarter(String s); } // Abstract Java Test Class package org.jfree.data.time.junit; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jfree.data.time.Quarter; import org.jfree.data.time.TimePeriodFormatException; import org.jfree.data.time.Year; public class QuarterTests extends TestCase { private Quarter q1Y1900; private Quarter q2Y1900; private Quarter q3Y9999; private Quarter q4Y9999; public static Test suite(); public QuarterTests(String name); protected void setUp(); public void testEqualsSelf(); public void testEquals(); public void testDateConstructor1(); public void testDateConstructor2(); public void testQ1Y1900Previous(); public void testQ1Y1900Next(); public void testQ4Y9999Previous(); public void testQ4Y9999Next(); public void testParseQuarter(); public void testSerialization(); public void testHashcode(); public void testNotCloneable(); public void testConstructor(); public void testGetFirstMillisecond(); public void testGetFirstMillisecondWithTimeZone(); public void testGetFirstMillisecondWithCalendar(); public void testGetLastMillisecond(); public void testGetLastMillisecondWithTimeZone(); public void testGetLastMillisecondWithCalendar(); public void testGetSerialIndex(); public void testNext(); public void testGetStart(); public void testGetEnd(); } ``` You are a professional Java test case writer, please create a test case named `testDateConstructor1` for the `Quarter` class, utilizing the provided abstract Java class context information and the following natural language annotations. ```java /** * In GMT, the end of Q1 2002 is java.util.Date(1017619199999L). Use this * to check the quarter constructor. */
135
// // Abstract Java Tested Class // package org.jfree.data.time; // // import java.io.Serializable; // import java.util.Calendar; // import java.util.Date; // import java.util.Locale; // import java.util.TimeZone; // // // // public class Quarter extends RegularTimePeriod implements Serializable { // private static final long serialVersionUID = 3810061714380888671L; // public static final int FIRST_QUARTER = 1; // public static final int LAST_QUARTER = 4; // public static final int[] FIRST_MONTH_IN_QUARTER = { // 0, MonthConstants.JANUARY, MonthConstants.APRIL, MonthConstants.JULY, // MonthConstants.OCTOBER // }; // public static final int[] LAST_MONTH_IN_QUARTER = { // 0, MonthConstants.MARCH, MonthConstants.JUNE, MonthConstants.SEPTEMBER, // MonthConstants.DECEMBER // }; // private short year; // private byte quarter; // private long firstMillisecond; // private long lastMillisecond; // // public Quarter(); // public Quarter(int quarter, int year); // public Quarter(int quarter, Year year); // public Quarter(Date time); // public Quarter(Date time, TimeZone zone); // public Quarter(Date time, TimeZone zone, Locale locale); // public int getQuarter(); // public Year getYear(); // public int getYearValue(); // public long getFirstMillisecond(); // public long getLastMillisecond(); // public void peg(Calendar calendar); // public RegularTimePeriod previous(); // public RegularTimePeriod next(); // public long getSerialIndex(); // public boolean equals(Object obj); // public int hashCode(); // public int compareTo(Object o1); // public String toString(); // public long getFirstMillisecond(Calendar calendar); // public long getLastMillisecond(Calendar calendar); // public static Quarter parseQuarter(String s); // } // // // Abstract Java Test Class // package org.jfree.data.time.junit; // // import java.io.ByteArrayInputStream; // import java.io.ByteArrayOutputStream; // import java.io.ObjectInput; // import java.io.ObjectInputStream; // import java.io.ObjectOutput; // import java.io.ObjectOutputStream; // import java.util.Calendar; // import java.util.Date; // import java.util.GregorianCalendar; // import java.util.Locale; // import java.util.TimeZone; // import junit.framework.Test; // import junit.framework.TestCase; // import junit.framework.TestSuite; // import org.jfree.data.time.Quarter; // import org.jfree.data.time.TimePeriodFormatException; // import org.jfree.data.time.Year; // // // // public class QuarterTests extends TestCase { // private Quarter q1Y1900; // private Quarter q2Y1900; // private Quarter q3Y9999; // private Quarter q4Y9999; // // public static Test suite(); // public QuarterTests(String name); // protected void setUp(); // public void testEqualsSelf(); // public void testEquals(); // public void testDateConstructor1(); // public void testDateConstructor2(); // public void testQ1Y1900Previous(); // public void testQ1Y1900Next(); // public void testQ4Y9999Previous(); // public void testQ4Y9999Next(); // public void testParseQuarter(); // public void testSerialization(); // public void testHashcode(); // public void testNotCloneable(); // public void testConstructor(); // public void testGetFirstMillisecond(); // public void testGetFirstMillisecondWithTimeZone(); // public void testGetFirstMillisecondWithCalendar(); // public void testGetLastMillisecond(); // public void testGetLastMillisecondWithTimeZone(); // public void testGetLastMillisecondWithCalendar(); // public void testGetSerialIndex(); // public void testNext(); // public void testGetStart(); // public void testGetEnd(); // } // You are a professional Java test case writer, please create a test case named `testDateConstructor1` for the `Quarter` class, utilizing the provided abstract Java class context information and the following natural language annotations. /** * In GMT, the end of Q1 2002 is java.util.Date(1017619199999L). Use this * to check the quarter constructor. */ public void testDateConstructor1() {
/** * In GMT, the end of Q1 2002 is java.util.Date(1017619199999L). Use this * to check the quarter constructor. */
1
org.jfree.data.time.Quarter
tests
```java // Abstract Java Tested Class package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Quarter extends RegularTimePeriod implements Serializable { private static final long serialVersionUID = 3810061714380888671L; public static final int FIRST_QUARTER = 1; public static final int LAST_QUARTER = 4; public static final int[] FIRST_MONTH_IN_QUARTER = { 0, MonthConstants.JANUARY, MonthConstants.APRIL, MonthConstants.JULY, MonthConstants.OCTOBER }; public static final int[] LAST_MONTH_IN_QUARTER = { 0, MonthConstants.MARCH, MonthConstants.JUNE, MonthConstants.SEPTEMBER, MonthConstants.DECEMBER }; private short year; private byte quarter; private long firstMillisecond; private long lastMillisecond; public Quarter(); public Quarter(int quarter, int year); public Quarter(int quarter, Year year); public Quarter(Date time); public Quarter(Date time, TimeZone zone); public Quarter(Date time, TimeZone zone, Locale locale); public int getQuarter(); public Year getYear(); public int getYearValue(); public long getFirstMillisecond(); public long getLastMillisecond(); public void peg(Calendar calendar); public RegularTimePeriod previous(); public RegularTimePeriod next(); public long getSerialIndex(); public boolean equals(Object obj); public int hashCode(); public int compareTo(Object o1); public String toString(); public long getFirstMillisecond(Calendar calendar); public long getLastMillisecond(Calendar calendar); public static Quarter parseQuarter(String s); } // Abstract Java Test Class package org.jfree.data.time.junit; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jfree.data.time.Quarter; import org.jfree.data.time.TimePeriodFormatException; import org.jfree.data.time.Year; public class QuarterTests extends TestCase { private Quarter q1Y1900; private Quarter q2Y1900; private Quarter q3Y9999; private Quarter q4Y9999; public static Test suite(); public QuarterTests(String name); protected void setUp(); public void testEqualsSelf(); public void testEquals(); public void testDateConstructor1(); public void testDateConstructor2(); public void testQ1Y1900Previous(); public void testQ1Y1900Next(); public void testQ4Y9999Previous(); public void testQ4Y9999Next(); public void testParseQuarter(); public void testSerialization(); public void testHashcode(); public void testNotCloneable(); public void testConstructor(); public void testGetFirstMillisecond(); public void testGetFirstMillisecondWithTimeZone(); public void testGetFirstMillisecondWithCalendar(); public void testGetLastMillisecond(); public void testGetLastMillisecondWithTimeZone(); public void testGetLastMillisecondWithCalendar(); public void testGetSerialIndex(); public void testNext(); public void testGetStart(); public void testGetEnd(); } ``` You are a professional Java test case writer, please create a test case named `testDateConstructor1` for the `Quarter` class, utilizing the provided abstract Java class context information and the following natural language annotations. ```java /** * In GMT, the end of Q1 2002 is java.util.Date(1017619199999L). Use this * to check the quarter constructor. */ public void testDateConstructor1() { ```
public class Quarter extends RegularTimePeriod implements Serializable
package org.jfree.data.time.junit; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jfree.data.time.Quarter; import org.jfree.data.time.TimePeriodFormatException; import org.jfree.data.time.Year;
public static Test suite(); public QuarterTests(String name); protected void setUp(); public void testEqualsSelf(); public void testEquals(); public void testDateConstructor1(); public void testDateConstructor2(); public void testQ1Y1900Previous(); public void testQ1Y1900Next(); public void testQ4Y9999Previous(); public void testQ4Y9999Next(); public void testParseQuarter(); public void testSerialization(); public void testHashcode(); public void testNotCloneable(); public void testConstructor(); public void testGetFirstMillisecond(); public void testGetFirstMillisecondWithTimeZone(); public void testGetFirstMillisecondWithCalendar(); public void testGetLastMillisecond(); public void testGetLastMillisecondWithTimeZone(); public void testGetLastMillisecondWithCalendar(); public void testGetSerialIndex(); public void testNext(); public void testGetStart(); public void testGetEnd();
0ba02ff7fd0493e77215bb8e0fc7275134751165c747cc7762e387d2e1b0e719
[ "org.jfree.data.time.junit.QuarterTests::testDateConstructor1" ]
private static final long serialVersionUID = 3810061714380888671L; public static final int FIRST_QUARTER = 1; public static final int LAST_QUARTER = 4; public static final int[] FIRST_MONTH_IN_QUARTER = { 0, MonthConstants.JANUARY, MonthConstants.APRIL, MonthConstants.JULY, MonthConstants.OCTOBER }; public static final int[] LAST_MONTH_IN_QUARTER = { 0, MonthConstants.MARCH, MonthConstants.JUNE, MonthConstants.SEPTEMBER, MonthConstants.DECEMBER }; private short year; private byte quarter; private long firstMillisecond; private long lastMillisecond;
public void testDateConstructor1()
private Quarter q1Y1900; private Quarter q2Y1900; private Quarter q3Y9999; private Quarter q4Y9999;
Chart
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * ----------------- * QuarterTests.java * ----------------- * (C) Copyright 2001-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Nov-2001 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 11-Jan-2005 : Added check for non-clonability (DG); * 05-Oct-2006 : Added some new tests (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time.junit; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jfree.data.time.Quarter; import org.jfree.data.time.TimePeriodFormatException; import org.jfree.data.time.Year; /** * Tests for the {link Quarter} class. */ public class QuarterTests extends TestCase { /** A quarter. */ private Quarter q1Y1900; /** A quarter. */ private Quarter q2Y1900; /** A quarter. */ private Quarter q3Y9999; /** A quarter. */ private Quarter q4Y9999; /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(QuarterTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public QuarterTests(String name) { super(name); } /** * Common test setup. */ protected void setUp() { this.q1Y1900 = new Quarter(1, 1900); this.q2Y1900 = new Quarter(2, 1900); this.q3Y9999 = new Quarter(3, 9999); this.q4Y9999 = new Quarter(4, 9999); } /** * Check that a Quarter instance is equal to itself. * * SourceForge Bug ID: 558850. */ public void testEqualsSelf() { Quarter quarter = new Quarter(); assertTrue(quarter.equals(quarter)); } /** * Tests the equals method. */ public void testEquals() { Quarter q1 = new Quarter(2, 2002); Quarter q2 = new Quarter(2, 2002); assertTrue(q1.equals(q2)); } /** * In GMT, the end of Q1 2002 is java.util.Date(1017619199999L). Use this * to check the quarter constructor. */ public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Calendar c = new GregorianCalendar(zone); Quarter q1 = new Quarter(new Date(1017619199999L), zone, Locale.getDefault()); Quarter q2 = new Quarter(new Date(1017619200000L), zone, Locale.getDefault()); assertEquals(1, q1.getQuarter()); assertEquals(1017619199999L, q1.getLastMillisecond(c)); assertEquals(2, q2.getQuarter()); assertEquals(1017619200000L, q2.getFirstMillisecond(c)); } /** * In Istanbul, the end of Q1 2002 is java.util.Date(1017608399999L). Use * this to check the quarter constructor. */ public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("Europe/Istanbul"); Calendar c = new GregorianCalendar(zone); Quarter q1 = new Quarter(new Date(1017608399999L), zone, Locale.getDefault()); Quarter q2 = new Quarter(new Date(1017608400000L), zone, Locale.getDefault()); assertEquals(1, q1.getQuarter()); assertEquals(1017608399999L, q1.getLastMillisecond(c)); assertEquals(2, q2.getQuarter()); assertEquals(1017608400000L, q2.getFirstMillisecond(c)); } /** * Set up a quarter equal to Q1 1900. Request the previous quarter, it * should be null. */ public void testQ1Y1900Previous() { Quarter previous = (Quarter) this.q1Y1900.previous(); assertNull(previous); } /** * Set up a quarter equal to Q1 1900. Request the next quarter, it should * be Q2 1900. */ public void testQ1Y1900Next() { Quarter next = (Quarter) this.q1Y1900.next(); assertEquals(this.q2Y1900, next); } /** * Set up a quarter equal to Q4 9999. Request the previous quarter, it * should be Q3 9999. */ public void testQ4Y9999Previous() { Quarter previous = (Quarter) this.q4Y9999.previous(); assertEquals(this.q3Y9999, previous); } /** * Set up a quarter equal to Q4 9999. Request the next quarter, it should * be null. */ public void testQ4Y9999Next() { Quarter next = (Quarter) this.q4Y9999.next(); assertNull(next); } /** * Test the string parsing code... */ public void testParseQuarter() { Quarter quarter = null; // test 1... try { quarter = Quarter.parseQuarter("Q1-2000"); } catch (TimePeriodFormatException e) { quarter = new Quarter(1, 1900); } assertEquals(1, quarter.getQuarter()); assertEquals(2000, quarter.getYear().getYear()); // test 2... try { quarter = Quarter.parseQuarter("2001-Q2"); } catch (TimePeriodFormatException e) { quarter = new Quarter(1, 1900); } assertEquals(2, quarter.getQuarter()); assertEquals(2001, quarter.getYear().getYear()); // test 3... try { quarter = Quarter.parseQuarter("Q3, 2002"); } catch (TimePeriodFormatException e) { quarter = new Quarter(1, 1900); } assertEquals(3, quarter.getQuarter()); assertEquals(2002, quarter.getYear().getYear()); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { Quarter q1 = new Quarter(4, 1999); Quarter q2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(q1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); q2 = (Quarter) in.readObject(); in.close(); } catch (Exception e) { System.out.println(e.toString()); } assertEquals(q1, q2); } /** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { Quarter q1 = new Quarter(2, 2003); Quarter q2 = new Quarter(2, 2003); assertTrue(q1.equals(q2)); int h1 = q1.hashCode(); int h2 = q2.hashCode(); assertEquals(h1, h2); } /** * The {@link Quarter} class is immutable, so should not be * {@link Cloneable}. */ public void testNotCloneable() { Quarter q = new Quarter(2, 2003); assertFalse(q instanceof Cloneable); } /** * Some tests for the constructor with (int, int) arguments. Covers bug * report 1377239. */ public void testConstructor() { boolean pass = false; try { /*Quarter q =*/ new Quarter(0, 2005); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { /*Quarter q =*/ new Quarter(5, 2005); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); } /** * Some checks for the getFirstMillisecond() method. */ public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Quarter q = new Quarter(3, 1970); assertEquals(15634800000L, q.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithTimeZone() { Quarter q = new Quarter(2, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-623347200000L, q.getFirstMillisecond(c)); // try null calendar boolean pass = false; try { q.getFirstMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ public void testGetFirstMillisecondWithCalendar() { Quarter q = new Quarter(1, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, q.getFirstMillisecond(calendar)); // try null calendar boolean pass = false; try { q.getFirstMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); } /** * Some checks for the getLastMillisecond() method. */ public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Quarter q = new Quarter(3, 1970); assertEquals(23583599999L, q.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithTimeZone() { Quarter q = new Quarter(2, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-615488400001L, q.getLastMillisecond(c)); // try null calendar boolean pass = false; try { q.getLastMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ public void testGetLastMillisecondWithCalendar() { Quarter q = new Quarter(3, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1001894399999L, q.getLastMillisecond(calendar)); // try null calendar boolean pass = false; try { q.getLastMillisecond((Calendar) null); } catch (NullPointerException e) { pass = true; } assertTrue(pass); } /** * Some checks for the getSerialIndex() method. */ public void testGetSerialIndex() { Quarter q = new Quarter(1, 2000); assertEquals(8001L, q.getSerialIndex()); q = new Quarter(1, 1900); assertEquals(7601L, q.getSerialIndex()); } /** * Some checks for the testNext() method. */ public void testNext() { Quarter q = new Quarter(1, 2000); q = (Quarter) q.next(); assertEquals(new Year(2000), q.getYear()); assertEquals(2, q.getQuarter()); q = new Quarter(4, 9999); assertNull(q.next()); } /** * Some checks for the getStart() method. */ public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JULY, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); Quarter q = new Quarter(3, 2006); assertEquals(cal.getTime(), q.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.MARCH, 31, 23, 59, 59); cal.set(Calendar.MILLISECOND, 999); Quarter q = new Quarter(1, 2006); assertEquals(cal.getTime(), q.getEnd()); Locale.setDefault(saved); } }
[ { "be_test_class_file": "org/jfree/data/time/Quarter.java", "be_test_class_name": "org.jfree.data.time.Quarter", "be_test_function_name": "getFirstMillisecond", "be_test_function_signature": "(Ljava/util/Calendar;)J", "line_numbers": [ "421", "422", "423", "426" ], "method_line_rate": 1 }, { "be_test_class_file": "org/jfree/data/time/Quarter.java", "be_test_class_name": "org.jfree.data.time.Quarter", "be_test_function_name": "getLastMillisecond", "be_test_function_signature": "(Ljava/util/Calendar;)J", "line_numbers": [ "441", "442", "443", "444", "447" ], "method_line_rate": 1 }, { "be_test_class_file": "org/jfree/data/time/Quarter.java", "be_test_class_name": "org.jfree.data.time.Quarter", "be_test_function_name": "getQuarter", "be_test_function_signature": "()I", "line_numbers": [ "197" ], "method_line_rate": 1 }, { "be_test_class_file": "org/jfree/data/time/Quarter.java", "be_test_class_name": "org.jfree.data.time.Quarter", "be_test_function_name": "peg", "be_test_function_signature": "(Ljava/util/Calendar;)V", "line_numbers": [ "257", "258", "259" ], "method_line_rate": 1 } ]
public class TimePeriodValuesCollectionTests extends TestCase
" public void testGetDomainBoundsWithInterval() {\n // check empty dataset\n TimePe(...TRUNCATED)
"// // Abstract Java Tested Class\n// package org.jfree.data.time;\n// \n// import java.io.Serializa(...TRUNCATED)
tests/org/jfree/data/time/junit/TimePeriodValuesCollectionTests.java
"package org.jfree.data.time;\n\nimport java.io.Serializable;\nimport java.util.Iterator;\nimport ja(...TRUNCATED)
" public TimePeriodValuesCollection();\n public TimePeriodValuesCollection(TimePeriodValues se(...TRUNCATED)
252
testGetDomainBoundsWithInterval
"```java\n// Abstract Java Tested Class\npackage org.jfree.data.time;\n\nimport java.io.Serializable(...TRUNCATED)
221
"// // Abstract Java Tested Class\n// package org.jfree.data.time;\n// \n// import java.io.Serializa(...TRUNCATED)
" /**\n * Some more checks for the getDomainBounds() method.\n * \n * @see #testGetDo(...TRUNCATED)
1
org.jfree.data.time.TimePeriodValuesCollection
tests
"```java\n// Abstract Java Tested Class\npackage org.jfree.data.time;\n\nimport java.io.Serializable(...TRUNCATED)
"public class TimePeriodValuesCollection extends AbstractIntervalXYDataset\n implements Inter(...TRUNCATED)
"package org.jfree.data.time.junit;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArra(...TRUNCATED)
" public static Test suite();\n public TimePeriodValuesCollectionTests(String name);\n prot(...TRUNCATED)
0bcba3f18197f9fb514670eac8301174c25863bf6adafed26dc96ad0936cda1c
[ "org.jfree.data.time.junit.TimePeriodValuesCollectionTests::testGetDomainBoundsWithInterval" ]
" private static final long serialVersionUID = -3077934065236454199L;\n private List data;\n (...TRUNCATED)
public void testGetDomainBoundsWithInterval()
private static final double EPSILON = 0.0000000001;
Chart
"/* ===========================================================\n * JFreeChart : a free chart librar(...TRUNCATED)
[{"be_test_class_file":"org/jfree/data/time/TimePeriodValuesCollection.java","be_test_class_name":"o(...TRUNCATED)
public class TestJavaType extends BaseMapTest
" public void testLocalType728() throws Exception\n {\n TypeFactory tf = TypeFactory.de(...TRUNCATED)
"// // Abstract Java Tested Class\n// package com.fasterxml.jackson.databind;\n// \n// import java.l(...TRUNCATED)
src/test/java/com/fasterxml/jackson/databind/type/TestJavaType.java
"package com.fasterxml.jackson.databind;\n\nimport java.lang.reflect.Modifier;\nimport java.util.Lis(...TRUNCATED)
" protected JavaType(Class<?> raw, int additionalHash,\n Object valueHandler, Object t(...TRUNCATED)
66
testLocalType728
"```java\n// Abstract Java Tested Class\npackage com.fasterxml.jackson.databind;\n\nimport java.lang(...TRUNCATED)
47
"// // Abstract Java Tested Class\n// package com.fasterxml.jackson.databind;\n// \n// import java.l(...TRUNCATED)
" /*\n /**********************************************************\n /* Test methods\n /(...TRUNCATED)
112
com.fasterxml.jackson.databind.JavaType
src/test/java
"```java\n// Abstract Java Tested Class\npackage com.fasterxml.jackson.databind;\n\nimport java.lang(...TRUNCATED)
"public abstract class JavaType\n extends ResolvedType\n implements java.io.Serializable, // 2(...TRUNCATED)
"package com.fasterxml.jackson.databind.type;\n\nimport java.lang.reflect.Method;\nimport java.util.(...TRUNCATED)
" public void testLocalType728() throws Exception;\n public void testSimpleClass();\n @Supp(...TRUNCATED)
0d676cbccbd37177e90a562c831ea69a6dead74601d4b96dc0ab27c91142eafa
[ "com.fasterxml.jackson.databind.type.TestJavaType::testLocalType728" ]
" private static final long serialVersionUID = 1;\n protected final Class<?> _class;\n prot(...TRUNCATED)
public void testLocalType728() throws Exception
JacksonDatabind
"package com.fasterxml.jackson.databind.type;\n\nimport java.lang.reflect.Method;\nimport java.util.(...TRUNCATED)
[{"be_test_class_file":"com/fasterxml/jackson/databind/JavaType.java","be_test_class_name":"com.fast(...TRUNCATED)
public class TestTypeFactory extends BaseMapTest
" public void testCollections()\n {\n // Ok, first: let's test what happens when we pas(...TRUNCATED)
"// private String _resolveTypePlaceholders(JavaType sourceType, JavaType actualType)\n// (...TRUNCATED)
src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java
"package com.fasterxml.jackson.databind.type;\n\nimport java.util.*;\nimport java.util.concurrent.at(...TRUNCATED)
" private TypeFactory();\n protected TypeFactory(LRUMap<Object,JavaType> typeCache);\n prot(...TRUNCATED)
299
testCollections
"```java\n private String _resolveTypePlaceholders(JavaType sourceType, JavaType actualType)\n (...TRUNCATED)
277
"// private String _resolveTypePlaceholders(JavaType sourceType, JavaType actualType)\n// (...TRUNCATED)
" /*\n /**********************************************************\n /* Unit tests: collect(...TRUNCATED)
112
com.fasterxml.jackson.databind.type.TypeFactory
src/test/java
"```java\n private String _resolveTypePlaceholders(JavaType sourceType, JavaType actualType)\n (...TRUNCATED)
"@SuppressWarnings({\"rawtypes\" })\npublic final class TypeFactory\n implements java.io.Serializ(...TRUNCATED)
"package com.fasterxml.jackson.databind.type;\n\nimport java.lang.reflect.Field;\nimport java.util.*(...TRUNCATED)
" public void testSimpleTypes();\n public void testArrays();\n public void testProperties()(...TRUNCATED)
0e619b558937c405b63e04fd631da036fb5cd8d44a8650a8c38261b2582b00c5
[ "com.fasterxml.jackson.databind.type.TestTypeFactory::testCollections" ]
" private static final long serialVersionUID = 1L;\n private final static JavaType[] NO_TYPES (...TRUNCATED)
public void testCollections()
JacksonDatabind
"package com.fasterxml.jackson.databind.type;\n\nimport java.lang.reflect.Field;\nimport java.util.*(...TRUNCATED)
[{"be_test_class_file":"com/fasterxml/jackson/databind/type/TypeFactory.java","be_test_class_name":"(...TRUNCATED)
"public class ChartPanelTests extends TestCase\n implements ChartChangeListener, ChartMouseLi(...TRUNCATED)
" public void test2502355_zoomInRange() {\n DefaultXYDataset dataset = new DefaultXYDatase(...TRUNCATED)
"// public int getZoomTriggerDistance();\n// public void setZoomTriggerDistance(int distance(...TRUNCATED)
tests/org/jfree/chart/junit/ChartPanelTests.java
"package org.jfree.chart;\n\nimport java.awt.AWTEvent;\nimport java.awt.AlphaComposite;\nimport java(...TRUNCATED)
" public ChartPanel(JFreeChart chart);\n public ChartPanel(JFreeChart chart, boolean useBuffer(...TRUNCATED)
266
test2502355_zoomInRange
"```java\n public int getZoomTriggerDistance();\n public void setZoomTriggerDistance(int dista(...TRUNCATED)
255
"// public int getZoomTriggerDistance();\n// public void setZoomTriggerDistance(int distance(...TRUNCATED)
" /**\n * Checks that a call to the zoomInRange() method, for a plot with more\n * than o(...TRUNCATED)
1
org.jfree.chart.ChartPanel
tests
"```java\n public int getZoomTriggerDistance();\n public void setZoomTriggerDistance(int dista(...TRUNCATED)
"public class ChartPanel extends JPanel implements ChartChangeListener,\n ChartProgressListen(...TRUNCATED)
"package org.jfree.chart.junit;\n\nimport java.awt.geom.Rectangle2D;\nimport java.util.EventListener(...TRUNCATED)
" public void chartChanged(ChartChangeEvent event);\n public static Test suite();\n public (...TRUNCATED)
11b55f009809888b81eff828ca5211becfbc7b51c16f6aae6bdaa569fae9d1f3
[ "org.jfree.chart.junit.ChartPanelTests::test2502355_zoomInRange" ]
" private static final long serialVersionUID = 6046366297214274674L;\n public static final boo(...TRUNCATED)
public void test2502355_zoomInRange()
private List chartChangeEvents = new java.util.ArrayList();
Chart
"/* ===========================================================\n * JFreeChart : a free chart librar(...TRUNCATED)
[{"be_test_class_file":"org/jfree/chart/ChartPanel.java","be_test_class_name":"org.jfree.chart.Chart(...TRUNCATED)
public class YIntervalSeriesCollectionTests extends TestCase
" public void test1170825() {\n YIntervalSeries s1 = new YIntervalSeries(\"Series1\");\n (...TRUNCATED)
"// // Abstract Java Tested Class\n// package org.jfree.data.xy;\n// \n// import java.io.Serializabl(...TRUNCATED)
tests/org/jfree/data/xy/junit/YIntervalSeriesCollectionTests.java
"package org.jfree.data.xy;\n\nimport java.io.Serializable;\nimport java.util.List;\nimport org.jfre(...TRUNCATED)
" public YIntervalSeriesCollection();\n public void addSeries(YIntervalSeries series);\n pu(...TRUNCATED)
212
test1170825
"```java\n// Abstract Java Tested Class\npackage org.jfree.data.xy;\n\nimport java.io.Serializable;\(...TRUNCATED)
199
"// // Abstract Java Tested Class\n// package org.jfree.data.xy;\n// \n// import java.io.Serializabl(...TRUNCATED)
" /**\n * A test for bug report 1170825 (originally affected XYSeriesCollection,\n * this(...TRUNCATED)
1
org.jfree.data.xy.YIntervalSeriesCollection
tests
"```java\n// Abstract Java Tested Class\npackage org.jfree.data.xy;\n\nimport java.io.Serializable;\(...TRUNCATED)
"public class YIntervalSeriesCollection extends AbstractIntervalXYDataset\n implements Interv(...TRUNCATED)
"package org.jfree.data.xy.junit;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayO(...TRUNCATED)
" public static Test suite();\n public YIntervalSeriesCollectionTests(String name);\n publi(...TRUNCATED)
11f55f2a23b466fce112f6edd9f5e153e0c77a813e297e5bc5a1566da3f6f57e
[ "org.jfree.data.xy.junit.YIntervalSeriesCollectionTests::test1170825" ]
private List data;
public void test1170825()
Chart
"/* ===========================================================\n * JFreeChart : a free chart librar(...TRUNCATED)
[{"be_test_class_file":"org/jfree/data/xy/YIntervalSeriesCollection.java","be_test_class_name":"org.(...TRUNCATED)
"public class ChartPanelTests extends TestCase\n implements ChartChangeListener, ChartMouseLi(...TRUNCATED)
" public void test2502355_restoreAutoDomainBounds() {\n DefaultXYDataset dataset = new Def(...TRUNCATED)
"// public int getZoomTriggerDistance();\n// public void setZoomTriggerDistance(int distance(...TRUNCATED)
tests/org/jfree/chart/junit/ChartPanelTests.java
"package org.jfree.chart;\n\nimport java.awt.AWTEvent;\nimport java.awt.AlphaComposite;\nimport java(...TRUNCATED)
" public ChartPanel(JFreeChart chart);\n public ChartPanel(JFreeChart chart, boolean useBuffer(...TRUNCATED)
317
test2502355_restoreAutoDomainBounds
"```java\n public int getZoomTriggerDistance();\n public void setZoomTriggerDistance(int dista(...TRUNCATED)
306
"// public int getZoomTriggerDistance();\n// public void setZoomTriggerDistance(int distance(...TRUNCATED)
" /**\n * Checks that a call to the restoreAutoDomainBounds() method, for a plot\n * with(...TRUNCATED)
1
org.jfree.chart.ChartPanel
tests
"```java\n public int getZoomTriggerDistance();\n public void setZoomTriggerDistance(int dista(...TRUNCATED)
"public class ChartPanel extends JPanel implements ChartChangeListener,\n ChartProgressListen(...TRUNCATED)
"package org.jfree.chart.junit;\n\nimport java.awt.geom.Rectangle2D;\nimport java.util.EventListener(...TRUNCATED)
" public void chartChanged(ChartChangeEvent event);\n public static Test suite();\n public (...TRUNCATED)
120d4c313dabe9b92188839845983799ef35cdb6332a5452875330a3a399de04
[ "org.jfree.chart.junit.ChartPanelTests::test2502355_restoreAutoDomainBounds" ]
" private static final long serialVersionUID = 6046366297214274674L;\n public static final boo(...TRUNCATED)
public void test2502355_restoreAutoDomainBounds()
private List chartChangeEvents = new java.util.ArrayList();
Chart
"/* ===========================================================\n * JFreeChart : a free chart librar(...TRUNCATED)
[{"be_test_class_file":"org/jfree/chart/ChartPanel.java","be_test_class_name":"org.jfree.chart.Chart(...TRUNCATED)
public class FixedOrderComparatorTest extends AbstractComparatorTest<String>
" @Test\n public void testConstructorPlusAdd() {\n final FixedOrderComparator<String> c(...TRUNCATED)
"// // Abstract Java Tested Class\n// package org.apache.commons.collections4.comparators;\n// \n// (...TRUNCATED)
src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java
"package org.apache.commons.collections4.comparators;\n\nimport java.io.Serializable;\nimport java.u(...TRUNCATED)
" public FixedOrderComparator();\n public FixedOrderComparator(final T... items);\n public (...TRUNCATED)
96
testConstructorPlusAdd
"```java\n// Abstract Java Tested Class\npackage org.apache.commons.collections4.comparators;\n\nimp(...TRUNCATED)
88
"// // Abstract Java Tested Class\n// package org.apache.commons.collections4.comparators;\n// \n// (...TRUNCATED)
" /**\n * Tests that the constructor plus add method compares items properly.\n */\n /(...TRUNCATED)
28
org.apache.commons.collections4.comparators.FixedOrderComparator
src/test/java
"```java\n// Abstract Java Tested Class\npackage org.apache.commons.collections4.comparators;\n\nimp(...TRUNCATED)
public class FixedOrderComparator<T> implements Comparator<T>, Serializable
"package org.apache.commons.collections4.comparators;\n\nimport java.util.Arrays;\nimport java.util.(...TRUNCATED)
" public FixedOrderComparatorTest(final String name);\n @Override\n public Comparator<Strin(...TRUNCATED)
125461b8ca4f4385e5689b7f74c4b9eca78c4101611bd7e99a12547ead401f84
[ "org.apache.commons.collections4.comparators.FixedOrderComparatorTest::testConstructorPlusAdd" ]
" private static final long serialVersionUID = 82794675842863201L;\n private final Map<T, Inte(...TRUNCATED)
@Test public void testConstructorPlusAdd()
" private static final String topCities[] = new String[] {\n \"Tokyo\",\n \"Mexico (...TRUNCATED)
Collections
"/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license a(...TRUNCATED)
[{"be_test_class_file":"org/apache/commons/collections4/comparators/FixedOrderComparator.java","be_t(...TRUNCATED)
public class SegmentedTimelineTests extends TestCase
" public void testFifteenMinSegmentedTimeline() {\n assertEquals(SegmentedTimeline.FIFTEEN(...TRUNCATED)
"// \"2000-12-25\", \"2001-01-01\", \"2001-01-15\", \"2001-02-19\", \"2001-04-13\",\n// (...TRUNCATED)
tests/org/jfree/chart/axis/junit/SegmentedTimelineTests.java
"package org.jfree.chart.axis;\n\nimport java.io.Serializable;\nimport java.util.ArrayList;\nimport (...TRUNCATED)
" public SegmentedTimeline(long segmentSize,\n int segmentsIncluded,\(...TRUNCATED)
348
testFifteenMinSegmentedTimeline
"```java\n \"2000-12-25\", \"2001-01-01\", \"2001-01-15\", \"2001-02-19\", \"2001-04-13\",\n (...TRUNCATED)
340
"// \"2000-12-25\", \"2001-01-01\", \"2001-01-15\", \"2001-02-19\", \"2001-04-13\",\n// (...TRUNCATED)
" /**\n * Tests that the factory method that creates a 15-min 9:00 AM 4:00 PM\n * segmen(...TRUNCATED)
1
org.jfree.chart.axis.SegmentedTimeline
tests
"```java\n \"2000-12-25\", \"2001-01-01\", \"2001-01-15\", \"2001-02-19\", \"2001-04-13\",\n (...TRUNCATED)
public class SegmentedTimeline implements Timeline, Cloneable, Serializable
"package org.jfree.chart.axis.junit;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArr(...TRUNCATED)
" public static Test suite();\n public SegmentedTimelineTests(String name);\n protected voi(...TRUNCATED)
14576b2f5539d56a91243e003b1fcd7a08b0e68b102633cc35665aaf8189ae49
[ "org.jfree.chart.axis.junit.SegmentedTimelineTests::testFifteenMinSegmentedTimeline" ]
" private static final long serialVersionUID = 1093779862539903110L;\n public static final lon(...TRUNCATED)
public void testFifteenMinSegmentedTimeline()
" private static final int TEST_CYCLE_START = 0;\n private static final int TEST_CYCLE_END =(...TRUNCATED)
Chart
"/* ===========================================================\n * JFreeChart : a free chart librar(...TRUNCATED)
[{"be_test_class_file":"org/jfree/chart/axis/SegmentedTimeline.java","be_test_class_name":"org.jfree(...TRUNCATED)
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
57
Edit dataset card