-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathAbstractFieldTest.java
More file actions
86 lines (68 loc) · 3 KB
/
Copy pathAbstractFieldTest.java
File metadata and controls
86 lines (68 loc) · 3 KB
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
/*
* Copyright 2013-2025 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.chronicle.wire;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.core.Jvm;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;
class AbstractFieldTest extends WireTestCommon {
// The specific WireType configuration to be used for each test.
private WireType wireType;
// Provide a collection of WireTypes for parameterized testing.
public static Collection<Object[]> wireTypes() {
return Arrays.asList(
new Object[]{WireType.BINARY},
new Object[]{WireType.BINARY_LIGHT},
new Object[]{WireType.TEXT},
new Object[]{WireType.YAML},
new Object[]{WireType.YAML_ONLY},
new Object[]{WireType.JSON_ONLY}
);
}
// Test serialization and deserialization of the abstract field in MSDMHolder class.
@ParameterizedTest
@MethodSource("wireTypes")
void abstractField(WireType wireType) {
this.wireType = wireType;
assumeFalse(Jvm.maxDirectMemory() == 0);
MSDMHolder holder = new MSDMHolder();
holder.marshallable = new MySelfDescribingMarshallable("Hello World");
Wire wire = wireType.apply(Bytes.allocateElasticOnHeap());
wire.getValueOut().object(MSDMHolder.class, holder);
MSDMHolder result = wire.getValueIn().object(MSDMHolder.class);
assertEquals(holder, result);
}
// Test serialization and deserialization of the abstract field in MSDMHolder2 class.
@ParameterizedTest
@MethodSource("wireTypes")
void abstractField2(WireType wireType) {
this.wireType = wireType;
assumeFalse(Jvm.maxDirectMemory() == 0);
MSDMHolder2 holder = new MSDMHolder2();
holder.marshallable = new MySelfDescribingMarshallable("Hello World");
Wire wire = wireType.apply(Bytes.allocateElasticOnHeap());
wire.getValueOut().object(MSDMHolder2.class, holder);
MSDMHolder2 result = wire.getValueIn().object(MSDMHolder2.class);
assertEquals(holder, result);
}
// Holder class to test serialization and deserialization with an abstract field.
static class MSDMHolder extends SelfDescribingMarshallable {
SelfDescribingMarshallable marshallable;
}
// Second holder class to test serialization and deserialization with a specific MySelfDescribingMarshallable field.
static class MSDMHolder2 extends SelfDescribingMarshallable {
MySelfDescribingMarshallable marshallable;
}
// Custom Marshallable class for testing purposes.
static class MySelfDescribingMarshallable extends SelfDescribingMarshallable {
String text;
MySelfDescribingMarshallable(String s) {
text = s;
}
}
}