forked from EsotericSoftware/kryo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
test/com/esotericsoftware/kryo/CompatibleFieldSerializerInheritanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package com.esotericsoftware.kryo; | ||
|
||
import com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer; | ||
|
||
import java.io.FileNotFoundException; | ||
|
||
/** | ||
* Created by phamrak on 13.5.2016. | ||
*/ | ||
public class CompatibleFieldSerializerInheritanceTest extends KryoTestCase { | ||
{ | ||
supportsCopy = true; | ||
} | ||
|
||
public void testAddedField () throws FileNotFoundException { | ||
TestClass2 test2 = new TestClass2(); | ||
test2.setText1("someText1"); | ||
test2.setText2("someText2"); | ||
test2.setMoo1(1); | ||
test2.setMoo2(2l); | ||
|
||
CompatibleFieldSerializer serializer = new CompatibleFieldSerializer(kryo, TestClass2.class, true); | ||
kryo.register(TestClass2.class, serializer); | ||
roundTrip(147, 147, test2); | ||
|
||
Object object2 = kryo.readClassAndObject(input); | ||
assertEquals(test2, object2); | ||
} | ||
|
||
static public class TestClass1 { | ||
private String text1; | ||
private int moo1; | ||
private long moo2; | ||
|
||
public String getText1() { | ||
return text1; | ||
} | ||
|
||
public void setText1(String text1) { | ||
this.text1 = text1; | ||
} | ||
|
||
public int getMoo1() { | ||
return moo1; | ||
} | ||
|
||
public void setMoo1(int moo1) { | ||
this.moo1 = moo1; | ||
} | ||
|
||
public long getMoo2() { | ||
return moo2; | ||
} | ||
|
||
public void setMoo2(long moo2) { | ||
this.moo2 = moo2; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
TestClass1 that = (TestClass1) o; | ||
|
||
if (moo1 != that.moo1) return false; | ||
if (moo2 != that.moo2) return false; | ||
return text1 != null ? text1.equals(that.text1) : that.text1 == null; | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = text1 != null ? text1.hashCode() : 0; | ||
result = 31 * result + moo1; | ||
result = 31 * result + (int) (moo2 ^ (moo2 >>> 32)); | ||
return result; | ||
} | ||
} | ||
|
||
static public class TestClass2 extends TestClass1 { | ||
private String text1; | ||
private String text2; | ||
private int moo1; | ||
private long moo2; | ||
|
||
@Override | ||
public String getText1() { | ||
return text1; | ||
} | ||
|
||
@Override | ||
public void setText1(String text1) { | ||
this.text1 = text1; | ||
} | ||
|
||
public String getText2() { | ||
return text2; | ||
} | ||
|
||
public void setText2(String text2) { | ||
this.text2 = text2; | ||
} | ||
|
||
@Override | ||
public int getMoo1() { | ||
return moo1; | ||
} | ||
|
||
@Override | ||
public void setMoo1(int moo1) { | ||
this.moo1 = moo1; | ||
} | ||
|
||
@Override | ||
public long getMoo2() { | ||
return moo2; | ||
} | ||
|
||
@Override | ||
public void setMoo2(long moo2) { | ||
this.moo2 = moo2; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
TestClass2 that = (TestClass2) o; | ||
|
||
if (moo1 != that.moo1) return false; | ||
if (moo2 != that.moo2) return false; | ||
if (text1 != null ? !text1.equals(that.text1) : that.text1 != null) return false; | ||
return text2 != null ? text2.equals(that.text2) : that.text2 == null; | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = text1 != null ? text1.hashCode() : 0; | ||
result = 31 * result + (text2 != null ? text2.hashCode() : 0); | ||
result = 31 * result + moo1; | ||
result = 31 * result + (int) (moo2 ^ (moo2 >>> 32)); | ||
return result; | ||
} | ||
} | ||
} |