INT-1280: ship commons code out to external project

This commit is contained in:
David Syer
2010-08-25 12:22:27 +00:00
parent 78deab7677
commit d98ff8eaa1
24 changed files with 89 additions and 543 deletions

View File

@@ -1,87 +0,0 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.commons.serializer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.NotSerializableException;
import java.io.Serializable;
import org.junit.Test;
import org.springframework.commons.serializer.java.JavaStreamingConverter;
/**
* @author Gary Russell
* @since 2.0
*
*/
public class JavaSerializationTests {
@Test
public void testGood() {
JavaStreamingConverter streamingConverter = new JavaStreamingConverter();
SerializingConverter toBytes = new SerializingConverter(streamingConverter);
byte[] bytes = toBytes.convert("Testing");
DeserializingConverter fromBytes = new DeserializingConverter(streamingConverter);
assertEquals("Testing", fromBytes.convert(bytes));
}
@Test
public void testBadSerializeNotSerializable() {
SerializingConverter toBytes = new SerializingConverter(new JavaStreamingConverter());
try {
toBytes.convert(new Object());
fail("Expected IllegalArgumentException");
} catch (SerializationFailureException e) {
assertNotNull(e.getCause());
assertTrue(e.getCause() instanceof IllegalArgumentException);
}
}
@Test
public void testBadSerializeNotSerializableField() {
SerializingConverter toBytes = new SerializingConverter(new JavaStreamingConverter());
try {
toBytes.convert(new UnSerializable());
fail("Expected SerializationFailureException");
} catch (SerializationFailureException e) {
assertNotNull(e.getCause());
assertTrue(e.getCause() instanceof NotSerializableException);
}
}
@Test
public void testBadDeserialize() {
DeserializingConverter fromBytes = new DeserializingConverter(new JavaStreamingConverter());
try {
fromBytes.convert("Junk".getBytes());
fail("Expected DeserializationFailureException");
} catch (DeserializationFailureException e) { }
}
class UnSerializable implements Serializable {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private Object object;
}
}