View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      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  package org.apache.commons.vfs2;
18  
19  import org.junit.Assert;
20  import org.junit.Test;
21  
22  /**
23   * Check FileSystemOptions.
24   *
25   * @since 2.1
26   */
27  public class FileSystemOptionsTest {
28  
29      public static class JUnitConfigBuilder extends FileSystemConfigBuilder {
30          private abstract static class JUnitFS implements FileSystem {
31          }
32  
33          private static final JUnitConfigBuilder BUILDER = new JUnitConfigBuilder();
34  
35          public static JUnitConfigBuilder getInstance() {
36              return BUILDER;
37          }
38  
39          @Override
40          protected Class<? extends FileSystem> getConfigClass() {
41              return JUnitFS.class;
42          }
43  
44          public void setId(final FileSystemOptions opts, final String id) {
45              setParam(opts, "id", id);
46          }
47  
48          public void setNames(final FileSystemOptions opts, final String[] names) {
49              setParam(opts, "names", names);
50          }
51      }
52  
53      @Test
54      public void testEqualsHashCodeAndCompareTo() {
55          final JUnitConfigBuilder builder = JUnitConfigBuilder.getInstance();
56          final FileSystemOptions expected = new FileSystemOptions();
57          builder.setId(expected, "Test");
58  
59          final FileSystemOptions actual = new FileSystemOptions();
60          builder.setId(actual, "Test");
61  
62          Assert.assertEquals(expected, actual);
63          Assert.assertEquals(0, actual.compareTo(expected));
64          Assert.assertEquals(expected.hashCode(), actual.hashCode());
65  
66          builder.setNames(expected, new String[] { "A", "B", "C" });
67  
68          Assert.assertNotEquals(expected, actual);
69          Assert.assertEquals(-1, actual.compareTo(expected));
70          Assert.assertNotEquals(expected.hashCode(), actual.hashCode());
71  
72          builder.setNames(actual, new String[] { "A", "B", "C" });
73  
74          Assert.assertEquals(expected, actual);
75          Assert.assertEquals(0, actual.compareTo(expected));
76          Assert.assertEquals(expected.hashCode(), actual.hashCode());
77      }
78  
79  }