001/*
002 * Copyright 2005,2009 Ivan SZKIBA
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.ini4j;
017
018import static org.junit.Assert.assertEquals;
019import static org.junit.Assert.assertNotNull;
020import static org.junit.Assert.assertSame;
021import static org.junit.Assert.assertTrue;
022
023import org.junit.Test;
024
025public class BasicRegistryTest extends Ini4jCase
026{
027    private static final String KEY = "key";
028    private static final String DUMMY = "dummy";
029    private static final String VERSION = "Windows Registry Editor Version 5.00";
030
031    @Test public void testVersion()
032    {
033        BasicRegistry reg = new BasicRegistry();
034
035        assertEquals(VERSION, reg.getVersion());
036        reg.setVersion(DUMMY);
037        assertEquals(DUMMY, reg.getVersion());
038    }
039
040    @Test public void testWrapped() throws Exception
041    {
042        BasicRegistry reg = new BasicRegistry();
043        Registry.Key key1 = reg.add(KEY);
044        Registry.Key key2 = reg.add(KEY);
045
046        assertNotNull(key1);
047        assertNotNull(key2);
048        assertTrue(reg.get(KEY) instanceof Registry.Key);
049        assertTrue(reg.get(KEY, 1) instanceof Registry.Key);
050        Registry.Key key3 = new BasicRegistryKey(reg, KEY);
051
052        assertSame(key1, reg.put(KEY, key3, 0));
053        assertSame(key2, reg.put(KEY, key3));
054        assertSame(key3, reg.remove(KEY, 1));
055        assertSame(key3, reg.remove(KEY));
056        key1 = reg.add(KEY);
057        assertSame(key1, reg.remove(key1));
058    }
059}