testregistrytests.java

来自「cqME :java framework for TCK test.」· Java 代码 · 共 144 行

JAVA
144
字号
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.midp.javatest;import java.io.IOException;import java.util.Arrays;import junit.framework.TestCase;import junit.framework.TestSuite;import com.sun.tck.unitTests.lib.Utils;/** * Tests for TestRegistry class. */public class TestRegistryTests extends TestCase {    private static final String TEST_ID = "test_id";    /**     * Quick test for most basic entries with some spaces.     */    public void testAddSimpleJadEntries() throws IOException {        String line1 = "key:value";        String line2 = "key2 : value2   ";        String line3 = "   key3:value3";        String[] lines = new String[] {                line1, line2, line3        };        TestRegistry.addTestJad(TEST_ID, getFileName(lines));        String[] result = TestRegistry.getTestJad(TEST_ID);        assertTrue(Arrays.equals(                new String[] {line1, line2, line3},                result        ));    }    /**     * getTestJad() must return <code>null</code> if no additional jad entries     * has been registered with the test.     *     */    public void testGetTestJadForAnotherTest() {        assertNull("Must return null", TestRegistry.getTestJad("SOME_TEST"));    }    /**     * addTestJad() should throw IllegalArgumentException     * if file contains invalid entries.     */    public void testAddJadEntriesExcepion() throws IOException {        String[] lines = new String[] {"key without value"};        try {            TestRegistry.addTestJad(                    TEST_ID, getFileName(lines));            fail("IllegalArgumentException not thrown");        } catch (IllegalArgumentException iae) {}    }    /**     * addTestJad() should throw IllegalArgumentException     * if file contains no entries.     */    public void testAddEmptyJadEntriesExcepion() throws IOException {        String[] lines = new String[] {};        try {            TestRegistry.addTestJad(                    TEST_ID, getFileName(lines));            fail("IllegalArgumentException not thrown");        } catch (IllegalArgumentException iae) {}    }        /**     * addTestJad() should throw IOException     * if file doesn't exist.     */    public void testAddNonExistingJad() throws IOException {        String[] lines = new String[] {};        try {            TestRegistry.addTestJad(                    TEST_ID, "FILE_DOESNT_EXIST");            fail("IOException not thrown");        } catch (IOException iae) {}    }    /**     * addTestJad() throws NPE if testId is null.     * @throws IOException     */    public void testAddTestJadNull() throws IOException {        try {            TestRegistry.addTestJad(null, getFileName(new String[] {"a:b"}));            fail("NPE not thrown");        } catch (NullPointerException npe) {}    }    /**     * getTestJad() throws NPE if testId is null.     * @throws IOException     */    public void testGetTestJadNull() throws IOException {        try {            TestRegistry.getTestJad(null);            fail("NPE not thrown");        } catch (NullPointerException npe) {}    }    public static junit.framework.Test suite() {        return new TestSuite(TestRegistryTests.class, "TestRegistry Tests");    }    public static void main(String[] args) {        junit.textui.TestRunner.run(suite());    }    private static String getFileName(String[] lines) throws IOException {        return Utils.createFile(lines).getCanonicalPath();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?