remove extra serialization ex
This commit is contained in:
parent
cc39f18d21
commit
b18c4deb3f
|
@ -4,31 +4,10 @@ import org.junit.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
public class UserTest {
|
public class UserTest {
|
||||||
|
|
||||||
|
|
||||||
Path userData;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void init() throws IOException {
|
|
||||||
userData = Paths.get("src/test/resources/user.data");
|
|
||||||
if (!Files.exists(userData))
|
|
||||||
Files.createFile(userData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenUserInstance_whenIntializedWithNew_thenInstanceIsNotNull() {
|
public void givenUserInstance_whenIntializedWithNew_thenInstanceIsNotNull() {
|
||||||
User user = new User("Alice", 1);
|
User user = new User("Alice", 1);
|
||||||
|
@ -49,18 +28,6 @@ public class UserTest {
|
||||||
assertThat(clonedUser).isEqualTo(user);
|
assertThat(clonedUser).isEqualTo(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenFileWithBitsRepresentingUser_whenDeserialized_thenUserIsCreated() throws FileNotFoundException, IOException, ClassNotFoundException {
|
|
||||||
try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(userData.toFile())))) {
|
|
||||||
User user = new User("Tom", 0);
|
|
||||||
out.writeObject(user);
|
|
||||||
}
|
|
||||||
try (ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(userData.toFile())))) {
|
|
||||||
User deserializedUser = (User) in.readObject();
|
|
||||||
assertThat(deserializedUser).isNotNull();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenUserInstance_whenValuesAreNotInitialized_thenUserNameAndIdReturnDefault() {
|
public void givenUserInstance_whenValuesAreNotInitialized_thenUserNameAndIdReturnDefault() {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
|
Loading…
Reference in New Issue