/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 jakarta.el;
import java.util.ArrayList;
import org.junit.Assert; import org.junit.Test;
import org.apache.tomcat.util.res.StringManager;
publicclass TestImportHandler {
/** * java.lang should be imported by default
*/
@Test publicvoid testResolveClass01() {
ImportHandler handler = new ImportHandler();
Class<?> result = handler.resolveClass("String");
Assert.assertEquals(String.class, result);
}
/** * Resolve an unknown class
*/
@Test publicvoid testResolveClass02() {
ImportHandler handler = new ImportHandler();
Class<?> result = handler.resolveClass("Foo");
Assert.assertNull(result);
}
/** * Conflict on resolution.
*/
@Test publicvoid testResolveClass03() {
ImportHandler handler = new ImportHandler();
/** * Attempting to resolve something that isn't a simple class name * https://bz.apache.org/bugzilla/show_bug.cgi?id=57132
*/
@Test publicvoid testResolveClass05() {
ImportHandler handler = new ImportHandler();
/** * Attempting to resolve something that isn't a simple class name * https://bz.apache.org/bugzilla/show_bug.cgi?id=57132
*/
@Test publicvoid testResolveClass06() {
ImportHandler handler = new ImportHandler();
handler.importPackage("java.nio");
Class<?> clazz = handler.resolveClass(null);
Assert.assertNull(clazz);
}
/** * Import a valid class.
*/
@Test publicvoid testImportClass01() {
ImportHandler handler = new ImportHandler();
/** * Import an invalid static field - does not exist.
*/
@Test(expected = ELException.class) publicvoid testImportStatic02() {
ImportHandler handler = new ImportHandler();
/** * Import an invalid static field - conflict.
*/
@Test publicvoid testImportStatic04() {
ImportHandler handler = new ImportHandler();
handler.importStatic("org.apache.tomcat.util.scan.Constants.Package"); for (int i = 1; i <= 3; i++) { try {
handler.importStatic("org.apache.tomcat.util.threads.Constants.Package"); Assert.fail("Expected ELException but got none on iteration " + i);
} catch (ELException ex) { // Expected
}
}
}
/** * Package imports with conflicts due to non-public classes should not conflict.
*/
@Test publicvoid testBug57135() {
ImportHandler importHandler = new ImportHandler();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.