/* * 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.List;
import jakarta.el.TesterEvaluationListener.Pair;
import org.junit.Assert; import org.junit.Test;
publicclass TestELContext {
/** * Tests that a null key results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testGetContext() {
ELContext elContext = new TesterELContext();
elContext.getContext(null);
}
/** * Tests that a null key results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testPutContext01() {
ELContext elContext = new TesterELContext();
elContext.putContext(null, new Object());
}
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testPutContext02() {
ELContext elContext = new TesterELContext();
elContext.putContext(Object.class, null);
}
/** * Tests that the context object will be added to the map with context objects. The key is used as unique identifier * of the context object in the map.
*/
@Test publicvoid testPutContext03() {
ELContext elContext = new TesterELContext(); Assert.assertNull(elContext.getContext(String.class));
elContext.putContext(String.class, "test"); Assert.assertEquals("test", elContext.getContext(String.class));
elContext.putContext(String.class, "test1"); Assert.assertEquals("test1", elContext.getContext(String.class));
}
/** * Tests that propertyResolved will be set to true and the corresponding listeners will be notified.
*/
@Test publicvoid testSetPropertyResolved() {
ELContext elContext = new TesterELContext();
TesterEvaluationListener listener = new TesterEvaluationListener();
elContext.addEvaluationListener(listener);
/** * Tests that the corresponding listeners will be notified.
*/
@Test publicvoid testNotifyBeforeEvaluation() {
ELContext elContext = new TesterELContext();
TesterEvaluationListener listener = new TesterEvaluationListener();
elContext.addEvaluationListener(listener);
/** * Tests that the corresponding listeners will be notified.
*/
@Test publicvoid testNotifyAfterEvaluation() {
ELContext elContext = new TesterELContext();
TesterEvaluationListener listener = new TesterEvaluationListener();
elContext.addEvaluationListener(listener);
/** * Tests not compatible object and type.
*/
@Test(expected = ELException.class) publicvoid testConvertToType01() {
ELContext elContext = new TesterELContext();
elContext.convertToType("test", Integer.class);
}
/** * Tests that if there is no ELResolver the standard coercions will be invoked.
*/
@Test publicvoid testConvertToType02() {
ELContext elContext = new TesterELContext(); boolean originalPropertyResolved = false;
elContext.setPropertyResolved(originalPropertyResolved);
Object result = elContext.convertToType("test", String.class); Assert.assertEquals("test", result);
/** * Tests that if there is ELResolver it will handle the conversion. If this resolver cannot return a result the * standard coercions will be invoked.
*/
@Test publicvoid testConvertToType03() {
ELContext elContext = new TesterELContext(new TesterELResolverOne());
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.