Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 12, 2025
2 parents be5da22 + 579691a commit f0412af
Show file tree
Hide file tree
Showing 62 changed files with 425 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package tools.jackson.dataformat.javaprop.testutil;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.SequenceInputStream;
import java.io.StringReader;
import java.io.*;
import java.nio.charset.StandardCharsets;

import tools.jackson.core.io.IOContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package tools.jackson.dataformat.toml.testutil.failure;

import org.junit.jupiter.api.extension.ExtendWith;
import java.lang.annotation.*;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* <p>
Expand All @@ -24,6 +21,7 @@
*
* &#64;Test
* &#64;JacksonTestFailureExpected
* @Test
* public void testFeatureNotYetImplemented() {
* // Test code that is expected to fail
* }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package tools.jackson.dataformat.toml.testutil.failure;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;

import java.lang.reflect.Method;

import org.junit.jupiter.api.extension.*;

/**
* Custom {@link InvocationInterceptor} that intercepts test method invocation.
* To pass the test ***only if*** test fails with an exception, and fail the test otherwise.
Expand Down
2 changes: 1 addition & 1 deletion yaml/src/test/java/perf/YAMLDeserPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private MediaItem buildItem()

return item;
}

public void test() throws Exception
{
int sum = 0;
Expand Down
4 changes: 2 additions & 2 deletions yaml/src/test/java/perf/YAMLSerPerf.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package perf;

import java.io.*;
import java.io.ByteArrayOutputStream;

import tools.jackson.core.*;
import tools.jackson.databind.JsonNode;
Expand Down Expand Up @@ -46,7 +46,7 @@ private MediaItem buildItem()

return item;
}

public void test() throws Exception
{
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package tools.jackson.dataformat.yaml;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.fail;

/**
* Tests to try to ensure that SnakeYAML exceptions are not leaked,
* both because they are problematic on OSGi runtimes (depending on
Expand All @@ -8,6 +12,7 @@
*/
public class ExceptionConversionTest extends ModuleTestBase
{
@Test
public void testSimpleParsingLeakage() throws Exception
{
YAMLMapper mapper = newObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import java.io.*;
import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JDKSerializabilityTest extends ModuleTestBase
{
public void testApacheMapperWithModule() throws Exception {
Expand Down Expand Up @@ -37,8 +42,7 @@ private YAMLMapper serializeAndDeserialize(YAMLMapper mapper) throws Exception {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(serializedBytes);
ObjectInputStream inputStream = new ObjectInputStream(byteArrayInputStream);
Object deserializedObject = inputStream.readObject();
assertTrue("Deserialized object should be an instance of YAMLMapper",
deserializedObject instanceof YAMLMapper);
assertTrue(deserializedObject instanceof YAMLMapper);
return (YAMLMapper) deserializedObject;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package tools.jackson.dataformat.yaml;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import tools.jackson.core.*;

public abstract class ModuleTestBase extends junit.framework.TestCase
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public abstract class ModuleTestBase
{
/**
* Slightly modified sample class from Jackson tutorial ("JacksonInFiveMinutes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

import java.util.Map;

import org.junit.jupiter.api.Test;

import tools.jackson.core.*;
import tools.jackson.core.type.TypeReference;

import tools.jackson.databind.MappingIterator;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MultipleDocumentsReadTest extends ModuleTestBase
{
private final YAMLMapper MAPPER = YAMLMapper.shared();

@Test
public void testMultipleDocumentsViaParser() throws Exception
{
final String YAML = "num: 42\n"
Expand All @@ -37,6 +42,7 @@ public void testMultipleDocumentsViaParser() throws Exception
p.close();
}

@Test
public void testMultipleDocumentsViaIterator() throws Exception
{
final String YAML = "num: 42\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import java.util.Arrays;
import java.util.Collections;

import org.junit.jupiter.api.Test;

import tools.jackson.databind.*;

import static org.junit.jupiter.api.Assertions.assertEquals;

// for [dataformats-text#163]
public class MultipleDocumentsWriteTest extends ModuleTestBase
{
Expand All @@ -15,6 +19,7 @@ static class POJO163 {
public POJO163(int v) { value = v; }
}

@Test
public void testWriteMultipleDocsBeans() throws Exception
{
ObjectMapper mapper = newObjectMapper();
Expand All @@ -29,6 +34,7 @@ public void testWriteMultipleDocsBeans() throws Exception
assertEquals("---\nvalue: 42\n---\nvalue: 28", yaml);
}

@Test
public void testWriteMultipleDocsLists() throws Exception
{
ObjectMapper mapper = newObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import tools.jackson.core.*;

import static org.junit.jupiter.api.Assertions.*;

public class TestVersions extends ModuleTestBase
{
private final YAMLMapper MAPPER = newObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tools.jackson.dataformat.yaml.constraints;

import org.junit.jupiter.api.Test;

import tools.jackson.core.*;
import tools.jackson.core.exc.StreamConstraintsException;

Expand All @@ -10,6 +12,9 @@
import tools.jackson.dataformat.yaml.YAMLFactory;
import tools.jackson.dataformat.yaml.YAMLMapper;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Unit test(s) for verifying handling of maximum nesting depth
* for reading (StreamReadConstraints) and writing (StreamWriteConstraints).
Expand All @@ -27,6 +32,7 @@ public class DeeplyNestedYAMLReadWriteTest
.build()
);

@Test
public void testDeepNestingRead() throws Exception
{
final String DOC = YAML_MAPPER.writeValueAsString(createDeepNestedDoc(11));
Expand All @@ -46,6 +52,7 @@ private void _testDeepNestingRead(JsonParser p) throws Exception
}
}

@Test
public void testDeepNestingWrite() throws Exception
{
final JsonNode docRoot = createDeepNestedDoc(13);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
import java.util.Arrays;
import java.util.Random;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import tools.jackson.core.*;

import tools.jackson.databind.*;
import tools.jackson.databind.node.JsonNodeType;
import tools.jackson.dataformat.yaml.ModuleTestBase;

import static org.junit.jupiter.api.Assertions.*;

public class BinaryYAMLReadTest extends ModuleTestBase
{
private final ObjectMapper MAPPER = newObjectMapper();

@Test
public void testBinaryViaTree() throws Exception
{
final String BASE64 = " R0lGODlhDAAMAIQAAP//9/X1\n"
Expand All @@ -42,10 +45,11 @@ public void testBinaryViaTree() throws Exception
assertEquals(65, gif.length);
final byte[] actualFileHeader = Arrays.copyOfRange(gif, 0, 6);
final byte[] expectedFileHeader = new byte[]{'G', 'I', 'F', '8', '9', 'a'};
Assert.assertArrayEquals(expectedFileHeader, actualFileHeader);
assertArrayEquals(expectedFileHeader, actualFileHeader);
}

// [dataformats-text#90]
@Test
public void testReadLongBinary() throws Exception {
final byte[] data = new byte[1000];
new Random(1234).nextBytes(data);
Expand All @@ -64,7 +68,7 @@ public void testReadLongBinary() throws Exception {
assertEquals(JsonToken.PROPERTY_NAME, parser.nextToken());
assertEquals("data", parser.currentName());
assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, parser.nextToken());
Assert.assertArrayEquals(data, parser.getBinaryValue());
assertArrayEquals(data, parser.getBinaryValue());
assertEquals(JsonToken.END_OBJECT, parser.nextToken());
assertNull(parser.nextToken());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.dataformat.yaml.ModuleTestBase;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class DatabindAdvancedTest extends ModuleTestBase
{
enum Size { SMALL, LARGE; }
Expand Down Expand Up @@ -136,6 +141,7 @@ public Image(String uri, String title, int w, int h, Size s)
/**********************************************************
*/

@Test
public void testReadComplexPojo() throws Exception
{
ObjectMapper mapper = newObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package tools.jackson.dataformat.yaml.deser;

import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonProperty;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.dataformat.yaml.ModuleTestBase;

import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests for checking functioning of the databinding
* on top of YAML layer.
Expand Down Expand Up @@ -74,6 +74,7 @@ public void setVersion(String version) {

private final ObjectMapper MAPPER = newObjectMapper();

@Test
public void testSimpleNested() throws Exception
{
final String YAML =
Expand All @@ -100,6 +101,7 @@ public void testSimpleNested() throws Exception

}

@Test
public void testBasicUntyped() throws Exception
{
final String YAML =
Expand All @@ -122,6 +124,7 @@ public void testBasicUntyped() throws Exception
assertEquals(EXP, json);
}

@Test
public void testBasicPOJO() throws Exception
{
final String YAML =
Expand All @@ -138,9 +141,10 @@ public void testBasicPOJO() throws Exception
assertTrue(user.isVerified());
byte[] data = user.getUserImage();
assertNotNull(data);
Assert.assertArrayEquals(new byte[] { 1, 2, 3, 4, 5 }, data);
assertArrayEquals(new byte[] { 1, 2, 3, 4, 5 }, data);
}

@Test
public void testIssue1() throws Exception
{
final byte[] YAML = "firstName: Billy".getBytes("UTF-8");
Expand All @@ -150,6 +154,7 @@ public void testIssue1() throws Exception
assertEquals("Billy", user.firstName);
}

@Test
public void testUUIDs() throws Exception
{
UUID uuid = new UUID(0, 0);
Expand All @@ -159,6 +164,7 @@ public void testUUIDs() throws Exception
assertEquals(uuid, result);
}

@Test
public void testEmptyBean() throws Exception
{
String yaml = MAPPER.writer()
Expand All @@ -175,6 +181,7 @@ public void testEmptyBean() throws Exception
}

// [dataformats-text#205]
@Test
public void testRenamingIssue205() throws Exception
{
final String YAML =
Expand Down
Loading

0 comments on commit f0412af

Please sign in to comment.