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

Clean up BaseTest. Remove deprecated methods, warnings and etc... #4137

Merged
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
100 changes: 3 additions & 97 deletions src/test/java/com/fasterxml/jackson/databind/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import com.fasterxml.jackson.core.*;

//import static org.junit.Assert.*;

public abstract class BaseTest
extends TestCase
{
Expand Down Expand Up @@ -45,89 +43,6 @@ public abstract class BaseTest
+"}"
;

/*
/**********************************************************
/* Helper classes (beans)
/**********************************************************
*/

/**
* Sample class from Jackson tutorial ("JacksonInFiveMinutes")
*/
protected static class FiveMinuteUser {
public enum Gender { MALE, FEMALE };

public static class Name
{
private String _first, _last;

public Name() { }
public Name(String f, String l) {
_first = f;
_last = l;
}

public String getFirst() { return _first; }
public String getLast() { return _last; }

public void setFirst(String s) { _first = s; }
public void setLast(String s) { _last = s; }

@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
Name other = (Name) o;
return _first.equals(other._first) && _last.equals(other._last);
}
}

private Gender _gender;
private Name _name;
private boolean _isVerified;
private byte[] _userImage;

public FiveMinuteUser() { }

public FiveMinuteUser(String first, String last, boolean verified, Gender g, byte[] data)
{
_name = new Name(first, last);
_isVerified = verified;
_gender = g;
_userImage = data;
}

public Name getName() { return _name; }
public boolean isVerified() { return _isVerified; }
public Gender getGender() { return _gender; }
public byte[] getUserImage() { return _userImage; }

public void setName(Name n) { _name = n; }
public void setVerified(boolean b) { _isVerified = b; }
public void setGender(Gender g) { _gender = g; }
public void setUserImage(byte[] b) { _userImage = b; }

@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
FiveMinuteUser other = (FiveMinuteUser) o;
if (_isVerified != other._isVerified) return false;
if (_gender != other._gender) return false;
if (!_name.equals(other._name)) return false;
byte[] otherImage = other._userImage;
if (otherImage.length != _userImage.length) return false;
for (int i = 0, len = _userImage.length; i < len; ++i) {
if (_userImage[i] != otherImage[i]) {
return false;
}
}
return true;
}
}

/*
/**********************************************************
/* High-level helpers
Expand Down Expand Up @@ -316,7 +231,7 @@ protected JsonParser createParserUsingStream(JsonFactory f,
/**********************************************************
*/

protected final static byte[] jdkSerialize(Object o)
protected static byte[] jdkSerialize(Object o)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream(2000);
try (ObjectOutputStream obOut = new ObjectOutputStream(bytes)) {
Expand All @@ -329,7 +244,7 @@ protected final static byte[] jdkSerialize(Object o)
}

@SuppressWarnings("unchecked")
protected final static <T> T jdkDeserialize(byte[] raw)
protected static <T> T jdkDeserialize(byte[] raw)
{
try (ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(raw))) {
return (T) objIn.readObject();
Expand Down Expand Up @@ -386,7 +301,7 @@ public static void verifyException(Throwable e, String... anyMatches)
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : anyMatches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
if (lmsg.contains(lmatch)) {
return;
}
}
Expand Down Expand Up @@ -442,18 +357,9 @@ public static String q(String str) {
return '"'+str+'"';
}

@Deprecated // use q
public String quote(String str) {
return q(str);
}

// `public` since 2.16, was only `protected` before then.
public static String a2q(String json) {
return json.replace("'", "\"");
}

@Deprecated // use a2q
protected static String aposToQuotes(String json) {
return a2q(json);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.databind.deser.merge;

import com.fasterxml.jackson.databind.testutil.FiveMinuteUser;
import java.util.concurrent.atomic.AtomicReference;

import com.fasterxml.jackson.annotation.*;
Expand Down Expand Up @@ -71,15 +72,6 @@ static class MergedReference
public StringReference value = new StringReference("default");
}

static class MergedX<T>
{
@JsonMerge
public T value;

public MergedX(T v) { value = v; }
protected MergedX() { }
}

// // // Classes with invalid merge definition(s)

static class CantMergeInts {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.fasterxml.jackson.databind.testutil;

/**
* Sample class from Jackson tutorial ("JacksonInFiveMinutes")
*/
public class FiveMinuteUser
{
public enum Gender { MALE, FEMALE };

public static class Name
{
private String _first, _last;

public Name() { }
public Name(String f, String l) {
_first = f;
_last = l;
}

public String getFirst() { return _first; }
public String getLast() { return _last; }

public void setFirst(String s) { _first = s; }
public void setLast(String s) { _last = s; }

@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
Name other = (Name) o;
return _first.equals(other._first) && _last.equals(other._last);
}
}

private Gender _gender;
private Name _name;
private boolean _isVerified;
private byte[] _userImage;

public FiveMinuteUser() { }

public FiveMinuteUser(String first, String last, boolean verified, Gender g, byte[] data)
{
_name = new Name(first, last);
_isVerified = verified;
_gender = g;
_userImage = data;
}

public Name getName() { return _name; }
public boolean isVerified() { return _isVerified; }
public Gender getGender() { return _gender; }
public byte[] getUserImage() { return _userImage; }

public void setName(Name n) { _name = n; }
public void setVerified(boolean b) { _isVerified = b; }
public void setGender(Gender g) { _gender = g; }
public void setUserImage(byte[] b) { _userImage = b; }

@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
FiveMinuteUser other = (FiveMinuteUser) o;
if (_isVerified != other._isVerified) return false;
if (_gender != other._gender) return false;
if (!_name.equals(other._name)) return false;
byte[] otherImage = other._userImage;
if (otherImage.length != _userImage.length) return false;
for (int i = 0, len = _userImage.length; i < len; ++i) {
if (_userImage[i] != otherImage[i]) {
return false;
}
}
return true;
}
}