j2mebasetestsuitetests.java

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

JAVA
174
字号
/* * $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.j2me.javatest;import java.io.File;import java.io.IOException;import java.util.HashMap;import junit.framework.TestCase;import com.sun.javatest.TestDescription;import com.sun.tck.unitTests.lib.Utils;public class J2meBaseTestSuiteTests extends TestCase {    private J2meBaseTestSuite j2ts;    public static void main(String[] args) {        junit.textui.TestRunner.run(J2meBaseTestSuiteTests.class);    }    protected void setUp() throws Exception {        super.setUp();        j2ts = new J2meBaseTestSuite(                new File("file"), new HashMap(), ClassLoader.getSystemClassLoader());    }    protected void tearDown() throws Exception {        j2ts = null;        super.tearDown();    }    /**     * Test for getFilesForTest(TestDescription).     */    public void testGetFilesForTest() throws IOException {        TestDescription td = Utils.createTDWithEntry("a", "b");        assertNotNull(j2ts.getFilesForTest(td));        int origFilesCount = j2ts.getFilesForTest(td).length;        assertEquals(1, origFilesCount);        td = Utils.createTDWithEntry("source", "Test.java");        assertEquals(2, j2ts.getFilesForTest(td).length);        File file1 = Utils.createFile(new String[] {"source file 1 content"});        File file2 = Utils.createFile(new String[] {"source file 2 content"});        String src1 = file1.toURI().toURL().toString();        String src2 = file2.toURI().toURL().toString();                td = Utils.createTDWithEntry("remoteSource", src1);        assertEquals(2, j2ts.getFilesForTest(td).length);        td = Utils.createTDWithEntry("remoteSource", src1 + " " + src2);        assertEquals(3, j2ts.getFilesForTest(td).length);        td = Utils.createTDWithEntry("Jad-addon", src1);        assertEquals(2, j2ts.getFilesForTest(td).length);        td = Utils.createTDWithEntry("Manifest-addon", src2);        assertEquals(2, j2ts.getFilesForTest(td).length);    }    /**     * Test for getFilesForTest(TestDescription), with relative path to     * the source file.     */    public void testGetFilesForTestWithRelativePath() throws Exception {        File src = Utils.createFile(new String[] {"source file"});        // put relative source path into test description        HashMap params = new HashMap();        params.put("Manifest-addon", src.getName());        TestDescription td = new TestDescription(                src.getParentFile(), new File(File.pathSeparator), params);        assertEquals(2, j2ts.getFilesForTest(td).length);        // put relative source path into test description, TWICE :)        // the second file should not be returned        params = new HashMap();        params.put("Jad-addon", src.getName() + " " + src.getName());        td = new TestDescription(                src.getParentFile(), new File(File.pathSeparator), params);        assertEquals(2, j2ts.getFilesForTest(td).length);    }    /**     * Test for getFilesForTest(TestDescription), with both jad and     * manifest entries present.     *     * @throws Exception in case of io error.     */    public void testGetFilesForTestWithBothJadAndMf() throws Exception {        File jad = Utils.createFile(new String[] {"Jad file"});        File mf = Utils.createFile(new String[] {"MF file"});        HashMap params = new HashMap();        TestDescription td;        // both jad and manifest files are added, and they are the same        params.put("Jad-addon", jad.getName());        params.put("Manifest-addon", jad.getName());        td = new TestDescription(                jad.getParentFile(), new File(File.pathSeparator), params);        // since jad and manifest are the same files,        // only one of them should be reported        assertEquals(2, j2ts.getFilesForTest(td).length);        // put different jad and manifest files        params.put("Jad-addon", jad.getName());        params.put("Manifest-addon", mf.getName());        td = new TestDescription(                jad.getParentFile(), new File(File.pathSeparator), params);        // since jad and manifest are different files,        // both of them should be reported        assertEquals(3, j2ts.getFilesForTest(td).length);    }    /**     * Test for getFilesForTest(TestDescription), with jad,     * manifest and remoteSourcee entries present.     *     * @throws Exception in case of io error.     */    public void testGetFilesForTestWithJadMfAndRemoteSrcs() throws Exception {        File jad = Utils.createFile(new String[] {"Jad file"});        File mf = Utils.createFile(new String[] {"MF file"});        File remoteSrc = Utils.createFile(new String[] {"Remote Source file"});        HashMap params = new HashMap();        TestDescription td;        // add jad, manifest and remote source        params.put("Jad-addon", jad.getName());        params.put("Manifest-addon", mf.getName());        params.put("remoteSource", remoteSrc.getName());        td = new TestDescription(                jad.getParentFile(), new File(File.pathSeparator), params);        // should return root, jad, manifest and remote source        assertEquals(4, j2ts.getFilesForTest(td).length);    }}

⌨️ 快捷键说明

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