ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/jakarta/el/TestELContext.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/jakarta/el/TestELContext.java
Status
scanned
Type
file
Name
TestELContext.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
6052 (5.9 KB)
MD5
df6beb19914752f7fe8061f0fe93a2b2
SHA1
ee646374a1efcfc857aece52b503f42ec64cad10
SHA256
8c852eb1a6b19da1e0debee4bdb9b5a2d220bcfceab1c9e605d9de1fd72fe895
SHA512

      
    
SHA1_git
3dd09e7bc9377755e225e1a19802785140c75124
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestELContext.java | 5.9 KB |

/* * 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; public class TestELContext { /** * Tests that a null key results in an NPE as per EL Javadoc. */ @Test(expected = NullPointerException.class) public void 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) public void 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) public void 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 public void 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 public void testSetPropertyResolved() { ELContext elContext = new TesterELContext(); TesterEvaluationListener listener = new TesterEvaluationListener(); elContext.addEvaluationListener(listener); TesterBean bean = new TesterBean("test"); elContext.setPropertyResolved(bean, "name"); Assert.assertTrue(elContext.isPropertyResolved()); List<Pair> events = listener.getResolvedProperties(); Assert.assertEquals(1, events.size()); Pair p = events.get(0); Assert.assertEquals(bean, p.getBase()); Assert.assertEquals("name", p.getProperty()); } /** * Tests that the corresponding listeners will be notified. */ @Test public void testNotifyBeforeEvaluation() { ELContext elContext = new TesterELContext(); TesterEvaluationListener listener = new TesterEvaluationListener(); elContext.addEvaluationListener(listener); elContext.notifyBeforeEvaluation("before"); List<String> events = listener.getBeforeEvaluationExpressions(); Assert.assertEquals(1, events.size()); Assert.assertEquals("before", events.get(0)); } /** * Tests that the corresponding listeners will be notified. */ @Test public void testNotifyAfterEvaluation() { ELContext elContext = new TesterELContext(); TesterEvaluationListener listener = new TesterEvaluationListener(); elContext.addEvaluationListener(listener); elContext.notifyAfterEvaluation("after"); List<String> events = listener.getAfterEvaluationExpressions(); Assert.assertEquals(1, events.size()); Assert.assertEquals("after", events.get(0)); } /** * Tests not compatible object and type. */ @Test(expected = ELException.class) public void testConvertToType01() { ELContext elContext = new TesterELContext(); elContext.convertToType("test", Integer.class); } /** * Tests that if there is no ELResolver the standard coercions will be invoked. */ @Test public void testConvertToType02() { ELContext elContext = new TesterELContext(); boolean originalPropertyResolved = false; elContext.setPropertyResolved(originalPropertyResolved); Object result = elContext.convertToType("test", String.class); Assert.assertEquals("test", result); Assert.assertTrue(originalPropertyResolved == elContext.isPropertyResolved()); } /** * 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 public void testConvertToType03() { ELContext elContext = new TesterELContext(new TesterELResolverOne()); boolean originalPropertyResolved = false; elContext.setPropertyResolved(originalPropertyResolved); Object result = elContext.convertToType("1", String.class); Assert.assertEquals("ONE", result); Assert.assertTrue(originalPropertyResolved == elContext.isPropertyResolved()); result = elContext.convertToType("test", String.class); Assert.assertEquals("test", result); Assert.assertTrue(originalPropertyResolved == elContext.isPropertyResolved()); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
21.29
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9