Skip to content

Commit 2f90e7e

Browse files
committed
Merge pull request #783 from mderka/newserialization
Refactored the serialization test to use the base test
2 parents 9ac6a82 + 5c3fc94 commit 2f90e7e

File tree

2 files changed

+25
-32
lines changed

2 files changed

+25
-32
lines changed

gcloud-java-dns/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
</exclusion>
4141
</exclusions>
4242
</dependency>
43+
<dependency>
44+
<groupId>${project.groupId}</groupId>
45+
<artifactId>gcloud-java-core</artifactId>
46+
<version>${project.version}</version>
47+
<type>test-jar</type>
48+
<scope>test</scope>
49+
</dependency>
4350
<dependency>
4451
<groupId>junit</groupId>
4552
<artifactId>junit</artifactId>

gcloud-java-dns/src/test/java/com/google/gcloud/dns/SerializationTest.java

+18-32
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,17 @@
1616

1717
package com.google.gcloud.dns;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotSame;
21-
2219
import com.google.common.collect.ImmutableList;
20+
import com.google.gcloud.AuthCredentials;
21+
import com.google.gcloud.BaseSerializationTest;
22+
import com.google.gcloud.Restorable;
2323
import com.google.gcloud.RetryParams;
2424

25-
import org.junit.Test;
26-
27-
import java.io.ByteArrayInputStream;
28-
import java.io.ByteArrayOutputStream;
29-
import java.io.IOException;
30-
import java.io.ObjectInputStream;
31-
import java.io.ObjectOutputStream;
3225
import java.io.Serializable;
3326
import java.math.BigInteger;
3427
import java.util.concurrent.TimeUnit;
3528

36-
public class SerializationTest {
29+
public class SerializationTest extends BaseSerializationTest {
3730

3831
private static final ZoneInfo FULL_ZONE_INFO = Zone.of("some zone name", "www.example.com",
3932
"some descriptions").toBuilder()
@@ -86,31 +79,24 @@ public class SerializationTest {
8679
.startTimeMillis(132L)
8780
.build();
8881

89-
@Test
90-
public void testModelAndRequests() throws Exception {
91-
Serializable[] objects = {FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION,
82+
@Override
83+
protected Serializable[] serializableObjects() {
84+
DnsOptions options = DnsOptions.builder()
85+
.authCredentials(AuthCredentials.createForAppEngine())
86+
.projectId("id1")
87+
.build();
88+
DnsOptions otherOptions = options.toBuilder()
89+
.authCredentials(null)
90+
.build();
91+
return new Serializable[]{FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION,
9292
DNS_REOCRD_LIST_OPTION, CHANGE_REQUEST_LIST_OPTION, ZONE_OPTION, CHANGE_REQUEST_OPTION,
9393
PROJECT_OPTION, PARTIAL_PROJECT_INFO, FULL_PROJECT_INFO, OPTIONS, FULL_ZONE, PARTIAL_ZONE,
9494
OPTIONS, CHANGE_REQUEST_PARTIAL, DNS_RECORD_PARTIAL, DNS_RECORD_COMPLETE,
95-
CHANGE_REQUEST_COMPLETE};
96-
for (Serializable obj : objects) {
97-
Object copy = serializeAndDeserialize(obj);
98-
assertEquals(obj, obj);
99-
assertEquals(obj, copy);
100-
assertNotSame(obj, copy);
101-
assertEquals(copy, copy);
102-
}
95+
CHANGE_REQUEST_COMPLETE, options, otherOptions};
10396
}
10497

105-
@SuppressWarnings("unchecked")
106-
private <T> T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException {
107-
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
108-
try (ObjectOutputStream output = new ObjectOutputStream(bytes)) {
109-
output.writeObject(obj);
110-
}
111-
try (ObjectInputStream input =
112-
new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
113-
return (T) input.readObject();
114-
}
98+
@Override
99+
protected Restorable<?>[] restorableObjects() {
100+
return new Restorable<?>[0];
115101
}
116102
}

0 commit comments

Comments
 (0)