001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.flatfile;
018
019import static org.junit.Assert.assertTrue;
020
021import org.junit.Test;
022
023/**
024 *
025 */
026public class ImmutableTest extends EntityParserTestBase {
027    @Test
028    public void test1() throws Exception {
029        Entity test1 = entityFactory.getEntity("test1");
030        assertValue("FOOxBARxBAZ", test1);
031        test1.fill((byte) 'y');
032        assertValue("FOOyBARyBAZ", test1);
033    }
034
035    @Test
036    public void test2() throws Exception {
037        Entity test2 = entityFactory.getEntity("test2");
038        assertTrue(test2 instanceof IndexedEntityCollection);
039        test2.fill((byte) '0');
040        assertValue("submarine", test2);
041    }
042
043    @Test
044    public void test3() throws Exception {
045        NamedEntityCollection test3 = (NamedEntityCollection) entityFactory
046                .getEntity("test3");
047        // verify the immutable children are still Entities:
048        test3.getChild("a");
049        test3.getChild("c");
050        assertValue("whatyouworry", test3);
051    }
052
053    @Test
054    public void test4() throws Exception {
055        assertValue("xxxxxxxxxx", entityFactory.getEntity("test4"));
056    }
057
058    /**
059     * {@inheritDoc}
060     */
061    protected String getSource() {
062        return "immutable.test";
063    }
064}