1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2;
18
19 import java.io.Serializable;
20
21 import org.apache.commons.lang3.SerializationUtils;
22 import org.junit.Assert;
23 import org.junit.Test;
24
25
26
27
28
29
30 public class FileTypeTest {
31
32 private static class Fixture implements Serializable {
33 private static final long serialVersionUID = 1L;
34 private final FileType fileType = FileType.FILE;
35
36 public FileType getFileType() {
37 return this.fileType;
38 }
39
40 }
41
42 private void assertEquals(final FileType expected, final FileType actualFileType) {
43 Assert.assertEquals(expected.getName(), actualFileType.getName());
44 Assert.assertEquals(expected.hasAttributes(), actualFileType.hasAttributes());
45 Assert.assertEquals(expected.hasChildren(), actualFileType.hasChildren());
46 Assert.assertEquals(expected.hasContent(), actualFileType.hasContent());
47 }
48
49 private void test(final FileType expected) {
50 final byte[] serialized = SerializationUtils.serialize(expected);
51 final FileType actualFileType = (FileType) SerializationUtils.deserialize(serialized);
52 assertEquals(expected, actualFileType);
53 }
54
55 @Test
56 public void testSerializationContainer() {
57 final Fixture expectedFixture = new Fixture();
58 final byte[] serialized = SerializationUtils.serialize(expectedFixture);
59 final Fixture actualFixture = (Fixture) SerializationUtils.deserialize(serialized);
60 assertEquals(expectedFixture.getFileType(), actualFixture.getFileType());
61 }
62
63 @Test
64 public void testSerializationFile() {
65 test(FileType.FILE);
66 }
67
68 @Test
69 public void testSerializationFileOrFolder() {
70 test(FileType.FILE_OR_FOLDER);
71 }
72
73 @Test
74 public void testSerializationFolder() {
75 test(FileType.FOLDER);
76 }
77
78 @Test
79 public void testSerializationImaginary() {
80 test(FileType.IMAGINARY);
81 }
82 }