Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ JSTEP-10 ] Migrate protobuf module tests to JUnit 5 #552

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.dataformat.protobuf;

import java.io.*;
import java.io.IOException;
import java.io.OutputStream;

/**
* Helper object used for buffering content for cases where we need (byte-)length prefixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.format.InputAccessor;
import com.fasterxml.jackson.core.format.MatchStrength;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.io.ContentReference;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;

public class ProtobufFactory extends JsonFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.dataformat.protobuf;

import java.io.*;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.Charset;
Expand All @@ -10,11 +11,7 @@
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.json.JsonWriteContext;
import com.fasterxml.jackson.core.util.JacksonFeatureSet;
import com.fasterxml.jackson.dataformat.protobuf.schema.FieldType;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
import com.fasterxml.jackson.dataformat.protobuf.schema.WireType;
import com.fasterxml.jackson.dataformat.protobuf.schema.*;

public class ProtobufGenerator extends GeneratorBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package com.fasterxml.jackson.dataformat.protobuf;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URL;
import java.util.concurrent.locks.ReentrantLock;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperBuilder;
import com.fasterxml.jackson.dataformat.protobuf.schema.DescriptorLoader;
import com.fasterxml.jackson.dataformat.protobuf.schema.FileDescriptorSet;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;
import com.fasterxml.jackson.dataformat.protobuf.schema.*;
import com.fasterxml.jackson.dataformat.protobuf.schemagen.ProtobufSchemaGenerator;

public class ProtobufMapper extends ObjectMapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
import com.fasterxml.jackson.core.base.ParserMinimalBase;
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.core.util.JacksonFeatureSet;
import com.fasterxml.jackson.core.util.TextBuffer;
import com.fasterxml.jackson.core.util.VersionUtil;

import com.fasterxml.jackson.core.util.*;
import com.fasterxml.jackson.dataformat.protobuf.schema.*;

public class ProtobufParser extends ParserMinimalBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.dataformat.protobuf;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonStreamContext;
import com.fasterxml.jackson.core.io.CharTypes;
import com.fasterxml.jackson.core.io.ContentReference;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.fasterxml.jackson.dataformat.protobuf.schema;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.*;
import java.net.URL;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fasterxml.jackson.dataformat.protobuf.schema;

import java.util.*;
import java.util.Arrays;

/**
* Helper class used for cases where {@link ProtobufField} instances
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fasterxml.jackson.dataformat.protobuf.schema;

import java.util.*;
import java.util.EnumMap;

import com.squareup.protoparser.DataType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
import java.util.EnumMap;
import java.util.Map;

import com.squareup.protoparser.DataType;
import com.squareup.protoparser.EnumConstantElement;
import com.squareup.protoparser.EnumElement;
import com.squareup.protoparser.FieldElement;
import com.squareup.protoparser.MessageElement;
import com.squareup.protoparser.OptionElement;
import com.squareup.protoparser.ProtoFile;
import com.squareup.protoparser.*;

/**
* @since 2.9
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.fasterxml.jackson.dataformat.protobuf.schema;

import java.util.*;
import java.util.Collection;

import com.fasterxml.jackson.core.SerializableString;
import com.squareup.protoparser.FieldElement;
import com.squareup.protoparser.OptionElement;

import com.fasterxml.jackson.core.SerializableString;

public class ProtobufField
// sorted in increasing order
implements Comparable<ProtobufField>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fasterxml.jackson.dataformat.protobuf.schema;

import java.util.*;
import java.util.Arrays;

import com.fasterxml.jackson.core.SerializableString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import java.util.*;

import com.fasterxml.jackson.core.util.InternCache;
import com.squareup.protoparser.*;

import com.fasterxml.jackson.core.util.InternCache;

/**
* Stateful class needed to properly resolve type definitions of
* protobuf message (and related types); some complexity coming
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.fasterxml.jackson.dataformat.protobuf.schemagen;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.*;

import com.fasterxml.jackson.databind.JavaType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import java.util.Set;

import com.squareup.protoparser.*;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor.Base;
import com.squareup.protoparser.EnumConstantElement;
import com.squareup.protoparser.EnumElement;
import com.squareup.protoparser.TypeElement;

public class EnumElementVisitor extends Base implements TypeElementBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
import java.util.HashSet;
import java.util.Set;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;

import com.squareup.protoparser.DataType;
import com.squareup.protoparser.*;
import com.squareup.protoparser.DataType.NamedType;
import com.squareup.protoparser.DataType.ScalarType;
import com.squareup.protoparser.FieldElement;
import com.squareup.protoparser.FieldElement.Label;
import com.squareup.protoparser.MessageElement;
import com.squareup.protoparser.TypeElement;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;

public class MessageElementVisitor extends JsonObjectFormatVisitor.Base
implements TypeElementBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import java.util.LinkedHashSet;
import java.util.Set;

import com.squareup.protoparser.DataType;
import com.squareup.protoparser.DataType.ScalarType;
import com.squareup.protoparser.TypeElement;

import com.fasterxml.jackson.core.JsonParser.NumberType;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonFormatVisitors.*;

import com.squareup.protoparser.DataType;
import com.squareup.protoparser.TypeElement;
import com.squareup.protoparser.DataType.ScalarType;

public class ProtoBufSchemaVisitor extends JsonFormatVisitorWrapper.Base
implements TypeElementBuilder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.jsonFormatVisitors.*;

import com.fasterxml.jackson.dataformat.protobuf.schema.NativeProtobufSchema;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.nio.ByteBuffer;
import java.util.UUID;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.BeanProperty;
import com.fasterxml.jackson.databind.JavaType;

public class ProtobufSchemaHelper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.fasterxml.jackson.dataformat.protobuf;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;

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

public class EnumHandlingTest extends ProtobufTestBase
{
enum TinyEnum {
Expand Down Expand Up @@ -38,6 +43,7 @@ static class BigEnumWrapper {

final ProtobufMapper MAPPER = newObjectMapper();

@Test
public void testBigEnum() throws Exception
{
ProtobufSchema schema = MAPPER.generateSchemaFor(BigEnumWrapper.class);
Expand All @@ -55,6 +61,7 @@ public void testBigEnum() throws Exception
assertEquals(input.value, result.value);
}

@Test
public void testTinyEnum() throws Exception
{
ProtobufSchema schema = MAPPER.generateSchemaFor(TinyEnumWrapper.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import java.io.*;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.StreamReadCapability;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;

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

public class FactoryPropertiesTest extends ProtobufTestBase
{
final ProtobufSchema POINT_SCHEMA;
Expand All @@ -22,6 +23,7 @@ public FactoryPropertiesTest() throws IOException {
POINT_SCHEMA = ProtobufSchemaLoader.std.parse(PROTOC_BOX, "Point");
}

@Test
public void testProtoFactorySerializable() throws Exception
{
ProtobufFactory f = new ProtobufFactory();
Expand All @@ -34,6 +36,7 @@ public void testProtoFactorySerializable() throws Exception
assertNotNull(f2);
}

@Test
public void testProtoFactoryCopy() throws Exception
{
ProtobufFactory f2 = PROTO_F.copy();
Expand All @@ -43,6 +46,7 @@ public void testProtoFactoryCopy() throws Exception
assertNotNull(doc);
}

@Test
public void testVersions() throws Exception
{
ProtobufFactory f = PROTO_F;
Expand All @@ -60,6 +64,7 @@ public void testVersions() throws Exception
p.close();
}

@Test
public void testCapabilities() throws Exception
{
assertTrue(PROTO_F.canHandleBinaryNatively());
Expand All @@ -68,6 +73,7 @@ public void testCapabilities() throws Exception
assertNull(PROTO_F.getFormatWriteFeatureType());
}

@Test
public void testInabilityToReadChars() throws Exception
{
final String EXP = "non-byte-based source";
Expand All @@ -91,6 +97,7 @@ public void testInabilityToReadChars() throws Exception
}
}

@Test
public void testInabilityToWriteChars() throws Exception
{
try {
Expand All @@ -102,6 +109,7 @@ public void testInabilityToWriteChars() throws Exception
}

// @since 2.14
@Test
public void testStreamReadCapabilities() throws Exception
{
byte[] doc = _writeDoc(PROTO_F);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.fasterxml.jackson.dataformat.protobuf;

import org.junit.jupiter.api.Test;

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

import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;

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

public class NestedWrite67Test extends ProtobufTestBase
{
@JsonPropertyOrder({ "value1", "level2" })
Expand Down Expand Up @@ -36,6 +39,7 @@ public static class Level3 {
/**********************************************************
*/

@Test
public void testIssue67() throws Exception
{
ProtobufSchema schema = MAPPER.generateSchemaFor(Level1.class);
Expand Down
Loading