File: BeanSerializerTest.java

package info (click to toggle)
libkryo-java 2.20-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 580 kB
  • sloc: java: 8,712; xml: 172; makefile: 4
file content (102 lines) | stat: -rw-r--r-- 2,474 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

package com.esotericsoftware.kryo;

import com.esotericsoftware.kryo.serializers.BeanSerializer;

/** @author Nathan Sweet <misc@n4te.com> */
public class BeanSerializerTest extends KryoTestCase {
	{
		supportsCopy = true;
	}

	public void testBeanSerializer () {
		kryo.register(TestClass.class, new BeanSerializer(kryo, TestClass.class));

		TestClass test = new TestClass();
		test.setOptional(12);
		test.setNullField("value");
		test.setText("123");
		test.setChild(new TestClass());
		roundTrip(37, test);
		test.setNullField(null);
		roundTrip(33, test);
	}

	static public class TestClass {
		private String text = "something";
		private String nullField;
		private TestClass child;
		private TestClass child2;
		private float abc = 1.2f;
		private int optional;

		public String getText () {
			return text;
		}

		public void setText (String text) {
			this.text = text;
		}

		public String getNullField () {
			return nullField;
		}

		public void setNullField (String nullField) {
			this.nullField = nullField;
		}

		public TestClass getChild () {
			return child;
		}

		public void setChild (TestClass child) {
			this.child = child;
		}

		public TestClass getChild2 () {
			return child2;
		}

		public void setChild2 (TestClass child2) {
			this.child2 = child2;
		}

		public float getAbc () {
			return abc;
		}

		public void setAbc (float abc) {
			this.abc = abc;
		}

		public int getOptional () {
			return optional;
		}

		public void setOptional (int optional) {
			this.optional = optional;
		}

		public boolean equals (Object obj) {
			if (this == obj) return true;
			if (obj == null) return false;
			if (getClass() != obj.getClass()) return false;
			TestClass other = (TestClass)obj;
			if (Float.floatToIntBits(abc) != Float.floatToIntBits(other.abc)) return false;
			if (child == null) {
				if (other.child != null) return false;
			} else if (child != this && !child.equals(other.child)) return false;
			if (child2 == null) {
				if (other.child2 != null) return false;
			} else if (child2 != this && !child2.equals(other.child2)) return false;
			if (nullField == null) {
				if (other.nullField != null) return false;
			} else if (!nullField.equals(other.nullField)) return false;
			if (text == null) {
				if (other.text != null) return false;
			} else if (!text.equals(other.text)) return false;
			return true;
		}
	}
}