Skip to content

Commit

Permalink
Merge branch '2.19' into joohyukkim/2.19/523-csv-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jan 12, 2025
2 parents 739e679 + 579691a commit 98526a1
Show file tree
Hide file tree
Showing 59 changed files with 465 additions and 215 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.fasterxml.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
@@ -1,11 +1,10 @@
package com.fasterxml.jackson.dataformat.yaml;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.format.DataFormatDetector;
import com.fasterxml.jackson.core.format.DataFormatMatcher;
import com.fasterxml.jackson.core.format.MatchStrength;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.format.*;

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

public class FormatDetectionTest extends ModuleTestBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.fasterxml.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 com.fasterxml.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,17 +2,22 @@

import java.util.Map;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.MappingIterator;

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

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

private final YAMLFactory YAML_F = MAPPER.getFactory();

@Test
public void testMultipleDocumentsViaParser() throws Exception
{
final String YAML = "num: 42\n"
Expand All @@ -39,6 +44,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,7 +4,12 @@
import java.util.Arrays;
import java.util.Collections;

import com.fasterxml.jackson.databind.*;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SequenceWriter;

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

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

@Test
public void testWriteMultipleDocsBeans() throws Exception
{
ObjectMapper mapper = newObjectMapper();
Expand All @@ -29,6 +35,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 @@ -2,11 +2,16 @@

import java.io.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.*;

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

public class TestVersions extends ModuleTestBase
{
@SuppressWarnings("resource")
@Test
public void testMapperVersions() throws IOException
{
YAMLFactory f = new YAMLFactory();
Expand All @@ -18,6 +23,7 @@ public void testMapperVersions() throws IOException
assertVersion(jgen);
}

@Test
public void testDefaults() throws Exception
{
YAMLFactory f = new YAMLFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.fasterxml.jackson.dataformat.yaml.constraints;


import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import com.fasterxml.jackson.dataformat.yaml.*;

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
Expand All @@ -25,6 +29,7 @@ public class DeeplyNestedYAMLReadWriteTest
.build()
);

@Test
public void testDeepNestingRead() throws Exception
{
final String DOC = YAML_MAPPER.writeValueAsString(createDeepNestedDoc(11));
Expand All @@ -44,6 +49,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 @@ -5,18 +5,21 @@
import java.util.Arrays;
import java.util.Random;

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

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;

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

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

@Test
public void testBinaryViaTree() throws Exception
{
final String BASE64 = " R0lGODlhDAAMAIQAAP//9/X1\n"
Expand All @@ -43,10 +46,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 @@ -65,7 +69,7 @@ public void testReadLongBinary() throws Exception {
assertEquals(JsonToken.FIELD_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,13 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.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 +140,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 com.fasterxml.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 com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.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
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import java.util.Collections;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;

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

// for [dataformats-text#306]
public class NameQuoting306Test extends ModuleTestBase
{
private final YAMLMapper MAPPER = newObjectMapper();

// for [dataformats-text#306]
@Test
public void testComplexName() throws Exception
{
final String key = "SomeKey:\nOtherLine";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.fasterxml.jackson.dataformat.yaml.deser;

import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLParser;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.dataformat.yaml.*;

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

// [dataformats-text#130]: Easy enough to fix, if we choose to,
// but due to timing cannot include in 2.12 (too close to release
Expand All @@ -23,6 +25,7 @@ public void setValue(String str) {
private final YAMLMapper MAPPER = newObjectMapper();

// [dataformats-text#130]
@Test
public void testEmptyValueToNull130() throws Exception
{
// by default, empy Strings are coerced:
Expand Down
Loading

0 comments on commit 98526a1

Please sign in to comment.