Skip to content

Commit

Permalink
Prevent need to create temporary files
Browse files Browse the repository at this point in the history
  • Loading branch information
abuijze committed Jul 3, 2018
1 parent 359c76d commit 4951a7c
Showing 1 changed file with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -19,15 +19,12 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.axonframework.serialization.SerializedObject;
import org.axonframework.serialization.xml.XStreamSerializer;
import org.junit.*;
import org.junit.Before;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.*;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

/**
* This test class tests whether the {@link AggregateScopeDescriptor} is serializable as expected, by Java, XStream and
Expand All @@ -39,7 +36,6 @@
public class AggregateScopeDescriptorSerializationTest {

private AggregateScopeDescriptor testSubject;

private String expectedType = "aggregateType";
private String expectedIdentifier = "identifier";

Expand All @@ -50,14 +46,12 @@ public void setUp() {

@Test
public void testJavaSerializationCorrectlySetsIdentifierField() throws IOException, ClassNotFoundException {
FileOutputStream fileOutputStream = new FileOutputStream("some-file");
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(out);
objectOutputStream.writeObject(testSubject);
objectOutputStream.flush();
objectOutputStream.close();

FileInputStream fileInputStream = new FileInputStream("some-file");
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
AggregateScopeDescriptor result = (AggregateScopeDescriptor) objectInputStream.readObject();

assertEquals(expectedType, result.getType());
Expand Down Expand Up @@ -89,4 +83,4 @@ public void testJacksonSerializationWorksAsExpected() throws IOException {
assertEquals(expectedType, result.getType());
assertEquals(expectedIdentifier, result.getIdentifier());
}
}
}

0 comments on commit 4951a7c

Please sign in to comment.