Skip to content

Commit 1027a6d

Browse files
author
mikr
committed
JAVA-8279 Split or move Java core module (fix review comments)
1 parent adce68a commit 1027a6d

File tree

4 files changed

+75
-7
lines changed

4 files changed

+75
-7
lines changed

core-java-modules/core-java-serialization/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<groupId>com.baeldung.core-java-modules</groupId>
1313
<artifactId>core-java-modules</artifactId>
1414
<version>0.0.1-SNAPSHOT</version>
15-
<relativePath>../</relativePath>
1615
</parent>
1716

1817
<dependencies>
@@ -186,8 +185,8 @@
186185
<!-- maven plugins -->
187186
<javamoney.moneta.version>1.1</javamoney.moneta.version>
188187
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
189-
<source.version>1.8</source.version>
190-
<target.version>1.8</target.version>
188+
<!-- <source.version>1.8</source.version>-->
189+
<!-- <target.version>1.8</target.version>-->
191190
<spring.core.version>4.3.20.RELEASE</spring.core.version>
192191
</properties>
193192

core-java-modules/core-java-serialization/src/test/java/com/baeldung/deserialization/DeserializationUnitTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class DeserializationUnitTest {
2525
@Test
2626
public void testDeserializeObj_compatible() throws IOException, ClassNotFoundException {
2727

28-
Assert.assertEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID());
28+
assertEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID());
2929

3030
AppleProduct macBook = new AppleProduct();
3131
macBook.headphonePort = "headphonePort2020";
@@ -61,7 +61,7 @@ public void testDeserializeObj_compatible() throws IOException, ClassNotFoundExc
6161
@Test(expected = InvalidClassException.class)
6262
public void testDeserializeObj_incompatible() throws ClassNotFoundException, IOException {
6363

64-
Assert.assertNotEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID());
64+
assertNotEquals(userDefinedSerialVersionUID, AppleProduct.getSerialVersionUID());
6565
// attempts to deserialize the "AppleProduct" object
6666
DeserializationUtility.deSerializeObjectFromString(serializedObj);
6767
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.baeldung.externalizable;
2+
3+
import org.junit.Test;
4+
5+
import java.io.*;
6+
7+
import static org.junit.Assert.assertTrue;
8+
9+
public class ExternalizableUnitTest {
10+
11+
private final static String OUTPUT_FILE = "externalizable.txt";
12+
13+
@Test
14+
public void whenSerializing_thenUseExternalizable() throws IOException, ClassNotFoundException {
15+
16+
Country c = new Country();
17+
c.setCapital("Yerevan");
18+
c.setCode(374);
19+
c.setName("Armenia");
20+
21+
FileOutputStream fileOutputStream = new FileOutputStream(OUTPUT_FILE);
22+
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
23+
c.writeExternal(objectOutputStream);
24+
25+
objectOutputStream.flush();
26+
objectOutputStream.close();
27+
fileOutputStream.close();
28+
29+
FileInputStream fileInputStream = new FileInputStream(OUTPUT_FILE);
30+
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
31+
32+
Country c2 = new Country();
33+
c2.readExternal(objectInputStream);
34+
35+
objectInputStream.close();
36+
fileInputStream.close();
37+
38+
assertTrue(c2.getCode() == c.getCode());
39+
assertTrue(c2.getName().equals(c.getName()));
40+
}
41+
42+
@Test
43+
public void whenInheritanceSerialization_then_UseExternalizable() throws IOException, ClassNotFoundException {
44+
45+
Region r = new Region();
46+
r.setCapital("Yerevan");
47+
r.setCode(374);
48+
r.setName("Armenia");
49+
r.setClimate("Mediterranean");
50+
r.setPopulation(120.000);
51+
52+
FileOutputStream fileOutputStream = new FileOutputStream(OUTPUT_FILE);
53+
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
54+
r.writeExternal(objectOutputStream);
55+
56+
objectOutputStream.flush();
57+
objectOutputStream.close();
58+
fileOutputStream.close();
59+
60+
FileInputStream fileInputStream = new FileInputStream(OUTPUT_FILE);
61+
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
62+
63+
Region r2 = new Region();
64+
r2.readExternal(objectInputStream);
65+
66+
objectInputStream.close();
67+
fileInputStream.close();
68+
69+
assertTrue(r2.getPopulation() == null);
70+
}
71+
}

core-java-modules/core-java-uuid/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@
149149
<properties>
150150
<assertj-core.version>3.10.0</assertj-core.version>
151151
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
152-
<source.version>1.8</source.version>
153-
<target.version>1.8</target.version>
154152
</properties>
155153

156154
</project>

0 commit comments

Comments
 (0)