[JAVA-9021] Clean up uncommitted artifacts (#11754)
This commit is contained in:
parent
19d7034d42
commit
a7980094d1
2
apache-poi/.gitignore
vendored
2
apache-poi/.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
*.docx
|
*.docx
|
||||||
temp.xls
|
temp.xls
|
||||||
temp.xlsx
|
temp.xlsx
|
||||||
|
|
||||||
|
CellStyleTest_output.xlsx
|
@ -2,3 +2,5 @@
|
|||||||
.settings/
|
.settings/
|
||||||
.classpath
|
.classpath
|
||||||
.project
|
.project
|
||||||
|
|
||||||
|
*.log
|
||||||
|
@ -1,14 +1,29 @@
|
|||||||
package com.baeldung.externalizable;
|
package com.baeldung.externalizable;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class ExternalizableUnitTest {
|
public class ExternalizableUnitTest {
|
||||||
|
|
||||||
private final static String OUTPUT_FILE = "externalizable.txt";
|
private final static String OUTPUT_FILE_NAME = "externalizable.txt";
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||||
|
|
||||||
|
private File outputFile;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
outputFile = tempFolder.newFile(OUTPUT_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSerializing_thenUseExternalizable() throws IOException, ClassNotFoundException {
|
public void whenSerializing_thenUseExternalizable() throws IOException, ClassNotFoundException {
|
||||||
@ -18,7 +33,7 @@ public class ExternalizableUnitTest {
|
|||||||
c.setCode(374);
|
c.setCode(374);
|
||||||
c.setName("Armenia");
|
c.setName("Armenia");
|
||||||
|
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream(OUTPUT_FILE);
|
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
|
||||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||||
c.writeExternal(objectOutputStream);
|
c.writeExternal(objectOutputStream);
|
||||||
|
|
||||||
@ -26,7 +41,7 @@ public class ExternalizableUnitTest {
|
|||||||
objectOutputStream.close();
|
objectOutputStream.close();
|
||||||
fileOutputStream.close();
|
fileOutputStream.close();
|
||||||
|
|
||||||
FileInputStream fileInputStream = new FileInputStream(OUTPUT_FILE);
|
FileInputStream fileInputStream = new FileInputStream(outputFile);
|
||||||
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
||||||
|
|
||||||
Country c2 = new Country();
|
Country c2 = new Country();
|
||||||
@ -35,8 +50,8 @@ public class ExternalizableUnitTest {
|
|||||||
objectInputStream.close();
|
objectInputStream.close();
|
||||||
fileInputStream.close();
|
fileInputStream.close();
|
||||||
|
|
||||||
assertTrue(c2.getCode() == c.getCode());
|
assertEquals(c2.getCode(), c.getCode());
|
||||||
assertTrue(c2.getName().equals(c.getName()));
|
assertEquals(c2.getName(), c.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -49,7 +64,7 @@ public class ExternalizableUnitTest {
|
|||||||
r.setClimate("Mediterranean");
|
r.setClimate("Mediterranean");
|
||||||
r.setPopulation(120.000);
|
r.setPopulation(120.000);
|
||||||
|
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream(OUTPUT_FILE);
|
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
|
||||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||||
r.writeExternal(objectOutputStream);
|
r.writeExternal(objectOutputStream);
|
||||||
|
|
||||||
@ -57,7 +72,7 @@ public class ExternalizableUnitTest {
|
|||||||
objectOutputStream.close();
|
objectOutputStream.close();
|
||||||
fileOutputStream.close();
|
fileOutputStream.close();
|
||||||
|
|
||||||
FileInputStream fileInputStream = new FileInputStream(OUTPUT_FILE);
|
FileInputStream fileInputStream = new FileInputStream(outputFile);
|
||||||
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
||||||
|
|
||||||
Region r2 = new Region();
|
Region r2 = new Region();
|
||||||
@ -66,6 +81,6 @@ public class ExternalizableUnitTest {
|
|||||||
objectInputStream.close();
|
objectInputStream.close();
|
||||||
fileInputStream.close();
|
fileInputStream.close();
|
||||||
|
|
||||||
assertTrue(r2.getPopulation() == null);
|
assertNull(r2.getPopulation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,54 @@
|
|||||||
package com.baeldung.serialization;
|
package com.baeldung.serialization;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class PersonUnitTest {
|
public class PersonUnitTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||||
|
|
||||||
|
private File outputFile;
|
||||||
|
|
||||||
|
private File outputFile2;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
outputFile = tempFolder.newFile("yourfile.txt");
|
||||||
|
outputFile2 = tempFolder.newFile("yourfile2.txt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSerializingAndDeserializing_ThenObjectIsTheSame() throws IOException, ClassNotFoundException {
|
public void whenSerializingAndDeserializing_ThenObjectIsTheSame() throws IOException, ClassNotFoundException {
|
||||||
Person p = new Person();
|
Person p = new Person();
|
||||||
p.setAge(20);
|
p.setAge(20);
|
||||||
p.setName("Joe");
|
p.setName("Joe");
|
||||||
|
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream("yofile.txt");
|
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
|
||||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||||
objectOutputStream.writeObject(p);
|
objectOutputStream.writeObject(p);
|
||||||
objectOutputStream.flush();
|
objectOutputStream.flush();
|
||||||
objectOutputStream.close();
|
objectOutputStream.close();
|
||||||
|
|
||||||
FileInputStream fileInputStream = new FileInputStream("yofile.txt");
|
FileInputStream fileInputStream = new FileInputStream(outputFile);
|
||||||
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
||||||
Person p2 = (Person) objectInputStream.readObject();
|
Person p2 = (Person) objectInputStream.readObject();
|
||||||
objectInputStream.close();
|
objectInputStream.close();
|
||||||
|
|
||||||
assertTrue(p2.getAge() == p.getAge());
|
assertEquals(p2.getAge(), p.getAge());
|
||||||
assertTrue(p2.getName().equals(p.getName()));
|
assertEquals(p2.getName(), p.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -46,19 +64,19 @@ public class PersonUnitTest {
|
|||||||
e.setPerson(p);
|
e.setPerson(p);
|
||||||
e.setAddress(a);
|
e.setAddress(a);
|
||||||
|
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream("yofile2.txt");
|
FileOutputStream fileOutputStream = new FileOutputStream(outputFile2);
|
||||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||||
objectOutputStream.writeObject(e);
|
objectOutputStream.writeObject(e);
|
||||||
objectOutputStream.flush();
|
objectOutputStream.flush();
|
||||||
objectOutputStream.close();
|
objectOutputStream.close();
|
||||||
|
|
||||||
FileInputStream fileInputStream = new FileInputStream("yofile2.txt");
|
FileInputStream fileInputStream = new FileInputStream(outputFile2);
|
||||||
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
|
||||||
Employee e2 = (Employee) objectInputStream.readObject();
|
Employee e2 = (Employee) objectInputStream.readObject();
|
||||||
objectInputStream.close();
|
objectInputStream.close();
|
||||||
|
|
||||||
assertTrue(e2.getPerson().getAge() == e.getPerson().getAge());
|
assertEquals(e2.getPerson().getAge(), e.getPerson().getAge());
|
||||||
assertTrue(e2.getAddress().getHouseNumber() == (e.getAddress().getHouseNumber()));
|
assertEquals(e2.getAddress().getHouseNumber(), (e.getAddress().getHouseNumber()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -13,17 +14,32 @@ import java.io.ObjectOutputStream;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.apache.commons.lang3.SerializationUtils;
|
import org.apache.commons.lang3.SerializationUtils;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.baeldung.util.MySerializationUtils;
|
import com.baeldung.util.MySerializationUtils;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
public class SerializationUnitTest {
|
public class SerializationUnitTest {
|
||||||
|
|
||||||
|
private final static String OUTPUT_FILE_NAME = "yourfile.txt";
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||||
|
|
||||||
|
private File outputFile;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
outputFile = tempFolder.newFile(OUTPUT_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = NotSerializableException.class)
|
@Test(expected = NotSerializableException.class)
|
||||||
public void whenSerializing_ThenThrowsError() throws IOException {
|
public void whenSerializing_ThenThrowsError() throws IOException {
|
||||||
Address address = new Address();
|
Address address = new Address();
|
||||||
address.setHouseNumber(10);
|
address.setHouseNumber(10);
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream("yofile.txt");
|
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
|
||||||
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream)) {
|
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream)) {
|
||||||
objectOutputStream.writeObject(address);
|
objectOutputStream.writeObject(address);
|
||||||
}
|
}
|
||||||
@ -35,12 +51,12 @@ public class SerializationUnitTest {
|
|||||||
p.setAge(20);
|
p.setAge(20);
|
||||||
p.setName("Joe");
|
p.setName("Joe");
|
||||||
|
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream("yofile.txt");
|
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
|
||||||
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream)) {
|
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream)) {
|
||||||
objectOutputStream.writeObject(p);
|
objectOutputStream.writeObject(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInputStream fileInputStream = new FileInputStream("yofile.txt");
|
FileInputStream fileInputStream = new FileInputStream(outputFile);
|
||||||
try (ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream)) {
|
try (ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream)) {
|
||||||
Person p2 = (Person) objectInputStream.readObject();
|
Person p2 = (Person) objectInputStream.readObject();
|
||||||
assertEquals(p2.getAge(), p.getAge());
|
assertEquals(p2.getAge(), p.getAge());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user