View Javadoc

1   /*
2    * Copyright 2005,2009 Ivan SZKIBA
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.ini4j;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertSame;
21  import static org.junit.Assert.assertTrue;
22  
23  import org.junit.Test;
24  
25  public class BasicRegistryTest extends Ini4jCase
26  {
27      private static final String KEY = "key";
28      private static final String DUMMY = "dummy";
29      private static final String VERSION = "Windows Registry Editor Version 5.00";
30  
31      @Test public void testVersion()
32      {
33          BasicRegistry reg = new BasicRegistry();
34  
35          assertEquals(VERSION, reg.getVersion());
36          reg.setVersion(DUMMY);
37          assertEquals(DUMMY, reg.getVersion());
38      }
39  
40      @Test public void testWrapped() throws Exception
41      {
42          BasicRegistry reg = new BasicRegistry();
43          Registry.Key key1 = reg.add(KEY);
44          Registry.Key key2 = reg.add(KEY);
45  
46          assertNotNull(key1);
47          assertNotNull(key2);
48          assertTrue(reg.get(KEY) instanceof Registry.Key);
49          assertTrue(reg.get(KEY, 1) instanceof Registry.Key);
50          Registry.Key key3 = new BasicRegistryKey(reg, KEY);
51  
52          assertSame(key1, reg.put(KEY, key3, 0));
53          assertSame(key2, reg.put(KEY, key3));
54          assertSame(key3, reg.remove(KEY, 1));
55          assertSame(key3, reg.remove(KEY));
56          key1 = reg.add(KEY);
57          assertSame(key1, reg.remove(key1));
58      }
59  }