Skip to content

Commit

Permalink
[ JSTEP-10 ] Migrate csv module tests to JUnit 5 (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim authored Jan 12, 2025
1 parent 9359af8 commit c702930
Show file tree
Hide file tree
Showing 76 changed files with 669 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.fasterxml.jackson.dataformat.csv;

import java.io.StringReader;
import java.io.StringWriter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.StreamReadFeature;
import com.fasterxml.jackson.core.StreamWriteFeature;

import java.io.StringReader;
import java.io.StringWriter;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;


public class CSVFactoryFeaturesTest extends ModuleTestBase
{
@Test
public void testFactoryFeatures() throws Exception
{
CsvFactory f = new CsvFactory();
Expand All @@ -31,6 +38,7 @@ public void testFactoryFeatures() throws Exception
g.close();
}

@Test
public void testFactoryFastFeatures() throws Exception
{
CsvFactory f = new CsvFactory();
Expand All @@ -46,6 +54,7 @@ public void testFactoryFastFeatures() throws Exception
assertTrue(generator.isEnabled(StreamWriteFeature.USE_FAST_DOUBLE_WRITER));
}

@Test
public void testFactoryFastBigNumberFeature() throws Exception
{
CsvFactory f = new CsvFactory();
Expand All @@ -57,6 +66,7 @@ public void testFactoryFastBigNumberFeature() throws Exception
assertTrue(parser.isEnabled(StreamReadFeature.USE_FAST_BIG_NUMBER_PARSER));
}

@Test
public void testFactoryBuilderFastFeatures() throws Exception
{
CsvFactory f = CsvFactory.builder()
Expand All @@ -73,6 +83,7 @@ public void testFactoryBuilderFastFeatures() throws Exception
assertTrue(generator.isEnabled(StreamWriteFeature.USE_FAST_DOUBLE_WRITER));
}

@Test
public void testFactoryBuilderFastBigNumberFeature() throws Exception
{
CsvFactory f = CsvFactory.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.fasterxml.jackson.dataformat.csv;

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 java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.*;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
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
{
public enum Gender { MALE, FEMALE };

Expand Down Expand Up @@ -332,4 +329,5 @@ protected byte[] readResource(String ref)
}
return bytes.toByteArray();
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.fasterxml.jackson.dataformat.csv;

import java.io.*;
import java.io.Reader;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectReader;

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


public class NullReader122Test extends ModuleTestBase
{
private final CsvMapper MAPPER = mapperForCsv();

// for [dataformats-text#122]: passing `null` Reader leads to infinite loop
@Test
public void testEmptyStream() throws Exception {
CsvSchema columns = CsvSchema.emptySchema().withHeader().withColumnSeparator(';');
ObjectReader r = MAPPER.readerFor(Map.class).with(columns);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.fasterxml.jackson.dataformat.csv;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonView;

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


public class SchemaCaching288Test extends ModuleTestBase
{
static class ViewA { }
Expand All @@ -28,6 +33,7 @@ static class Bean288
*/

// [dataformats-text#288]: caching should not overlap with View
@Test
public void testCachingNoViewFirst() throws Exception
{
CsvMapper mapper1 = mapperForCsv();
Expand All @@ -52,6 +58,7 @@ public void testCachingNoViewFirst() throws Exception
}

// [dataformats-text#288]: caching should not overlap with View
@Test
public void testCachingWithViewFirst() throws Exception
{
CsvMapper mapper1 = mapperForCsv();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.fasterxml.jackson.dataformat.csv;

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

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

import com.fasterxml.jackson.core.Versioned;
import com.fasterxml.jackson.databind.MapperFeature;

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

public class TestVersions extends ModuleTestBase
{
@Test
public void testMapperVersions() throws IOException
{
CsvFactory f = new CsvFactory();
Expand All @@ -20,6 +26,7 @@ public void testMapperVersions() throws IOException
}

// Mostly to verify #11
@Test
public void testMapperDefaults()
{
CsvMapper mapper = new CsvMapper();
Expand All @@ -28,6 +35,7 @@ public void testMapperDefaults()

// Also, not strictly related to version but...

@Test
public void testMapperCopy()
{
CsvMapper mapper = new CsvMapper();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.fasterxml.jackson.dataformat.csv.deser;

import java.util.*;
import java.util.LinkedHashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.dataformat.csv.*;

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

public class AnySetterTest extends ModuleTestBase
{
static class Entry {
Expand All @@ -29,6 +34,7 @@ public void set(String key, Object value) {
/**********************************************************************
*/

@Test
public void testSimpleHeader() throws Exception
{
CsvMapper mapper = mapperForCsv();
Expand All @@ -42,6 +48,7 @@ public void testSimpleHeader() throws Exception
}

// [dataformat-csv@109]: allow "any-setter-like"
@Test
public void testWithMapToAny() throws Exception
{
CsvMapper mapper = mapperForCsv();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.fasterxml.jackson.dataformat.csv.deser;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.dataformat.csv.*;

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

// for [dataformat-csv#57]
public class ArrayReadTest extends ModuleTestBase
{
Expand All @@ -32,6 +34,7 @@ public ValueEntry(@JsonProperty("id") String id,

private final CsvMapper MAPPER = mapperForCsv();

@Test
public void testSimpleExplicitLooseTyping() throws Exception
{
ValueEntry value = MAPPER.readerWithSchemaFor(ValueEntry.class)
Expand All @@ -48,6 +51,7 @@ public void testSimpleExplicitLooseTyping() throws Exception
}

// Same as above, but Array value in double-quotes:
@Test
public void testSimpleExplicitLooseTypingWithQuotes() throws Exception
{
ValueEntry value = MAPPER.readerWithSchemaFor(ValueEntry.class)
Expand All @@ -63,6 +67,7 @@ public void testSimpleExplicitLooseTypingWithQuotes() throws Exception
assertEquals(3, v[2]);
}

@Test
public void testSimpleExplicitStrictTyping() throws Exception
{
ValueEntry value = MAPPER.readerWithTypedSchemaFor(ValueEntry.class)
Expand All @@ -88,6 +93,7 @@ public void testSimpleExplicitStrictTyping() throws Exception
assertEquals(0, v.length);
}

@Test
public void testSeparatorOverrideSpace() throws Exception
{
ValueEntry input = new ValueEntry("foo", "stuff", new int[] {1, 2, 3});
Expand All @@ -113,6 +119,7 @@ public void testSeparatorOverrideSpace() throws Exception
assertEquals(3, v[2]);
}

@Test
public void testSeparatorOverrideMulti() throws Exception
{
ValueEntry input = new ValueEntry("foo", "stuff", new int[] {1, 2, 3});
Expand Down
Loading

0 comments on commit c702930

Please sign in to comment.