jp.terasoluna.fw.beans.jxpath.DynamicPointerExTest.java Source code

Java tutorial

Introduction

Here is the source code for jp.terasoluna.fw.beans.jxpath.DynamicPointerExTest.java

Source

/*
 * Copyright (c) 2007 NTT DATA Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jp.terasoluna.fw.beans.jxpath;

import static org.junit.Assert.assertSame;
import java.lang.reflect.Field;
import java.util.Locale;

import org.apache.commons.jxpath.DynamicPropertyHandler;
import org.apache.commons.jxpath.MapDynamicPropertyHandler;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.junit.Test;
import org.apache.commons.jxpath.ri.model.dynamic.DynamicPropertyPointer;

/**
 * {@link jp.terasoluna.fw.beans.jxpath.DynamicPointerEx} ?
 * <p>
 * <h4>???</h4> null????Map?<br>
 * ????
 * <p>
 * @see jp.terasoluna.fw.beans.jxpath.DynamicPointerEx
 */
public class DynamicPointerExTest {

    /**
     * testDynamicPointerExQname01() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     * () name:not null<br>
     * () bean:new Object()<br>
     * () handler:not null<br>
     * () locale:Locale("ja")<br>
     * () this.handler:null<br>
     * <br>
     * () this.handler:???<br>
     * <br>
     * ?? <br>
     * @throws Exception ?????
     */
    @Test
    public void testDynamicPointerExQname01() throws Exception {
        // ??
        QName qName = new QName("name");
        Object bean = new Object();
        DynamicPropertyHandler handler = new MapDynamicPropertyHandler();
        Locale locale = new Locale("ja");

        // 
        DynamicPointerEx result = new DynamicPointerEx(qName, bean, handler, locale);

        // 
        Field field = DynamicPointerEx.class.getDeclaredField("handler");
        field.setAccessible(true);
        Object resultHandler = field.get(result);
        assertSame(handler, resultHandler);
    }

    /**
     * testDynamicPointerExNodePointer01() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     * () parent:not null<br>
     * () name:not null<br>
     * () bean:new Object()<br>
     * () handler:not null<br>
     * () this.handler:null<br>
     * <br>
     * () this.handler:???<br>
     * <br>
     * ?? <br>
     * @throws Exception ?????
     */
    @Test
    public void testDynamicPointerExNodePointer01() throws Exception {
        // ??
        QName qName = new QName("name");
        Object bean = new Object();
        DynamicPropertyHandler handler = new MapDynamicPropertyHandler();
        Locale locale = new Locale("ja");
        NodePointer nodePointer = NodePointer.newNodePointer(qName, bean, locale);

        // 
        DynamicPointerEx result = new DynamicPointerEx(nodePointer, qName, bean, handler);

        // 
        Field field = DynamicPointerEx.class.getDeclaredField("handler");
        field.setAccessible(true);
        Object resultHandler = field.get(result);
        assertSame(handler, resultHandler);
    }

    /**
     * testGetPropertyPointer01() <br>
     * <br>
     * () <br>
     * A <br>
     * <br>
     * () this.handler:not null<br>
     * <br>
     * () PropertyPointer:new DynamicPropertyPointerEx{<br>
     * parent=this<br>
     * handler=?????handler<br>
     * }<br>
     * <br>
     * ???? <br>
     * @throws Exception ?????
     */
    @Test
    public void testGetPropertyPointer01() throws Exception {
        // ??
        QName qName = new QName("name");
        Object bean = new Object();
        DynamicPropertyHandler handler = new MapDynamicPropertyHandler();
        Locale locale = new Locale("ja");
        DynamicPointerEx pointer = new DynamicPointerEx(qName, bean, handler, locale);

        // 
        Object result = pointer.getPropertyPointer();

        // 
        assertSame(DynamicPropertyPointerEx.class, result.getClass());
        assertSame(pointer, ((DynamicPropertyPointerEx) result).getParent());
        Field field = DynamicPropertyPointer.class.getDeclaredField("handler");
        field.setAccessible(true);
        Object resultHandler = field.get(result);
        assertSame(handler, resultHandler);
    }

}