01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Pavel Dolgov
19: * @version $Revision$
20: */package java.awt.datatransfer;
21:
22: import java.io.File;
23: import java.io.FileInputStream;
24: import java.io.FileOutputStream;
25: import java.io.IOException;
26: import java.io.ObjectInputStream;
27: import java.io.ObjectOutputStream;
28: import java.io.Serializable;
29:
30: import junit.framework.TestCase;
31:
32: public class DataFlavorRTest extends TestCase {
33:
34: public void testSerializeDefaultDataFlavor() {
35: DataFlavor flavor = new DataFlavor();
36: DataFlavor restored = (DataFlavor) writeAndRead(flavor);
37: assertEquals(restored, flavor);
38: }
39:
40: private Serializable writeAndRead(Serializable original) {
41:
42: try {
43: File tempFile = File.createTempFile("save", ".object");
44:
45: FileOutputStream fos = new FileOutputStream(tempFile);
46:
47: ObjectOutputStream oos = new ObjectOutputStream(fos);
48: oos.writeObject(original);
49: oos.close();
50:
51: FileInputStream fis = new FileInputStream(tempFile);
52: ObjectInputStream ois = new ObjectInputStream(fis);
53:
54: Serializable restored = (Serializable) ois.readObject();
55: tempFile.delete();
56: return restored;
57: } catch (IOException e) {
58: throw new RuntimeException(e);
59: } catch (ClassNotFoundException e) {
60: throw new RuntimeException(e);
61: }
62: }
63:
64: }
|