Quelle TestStaticFieldELResolver.java
Sprache: JAVA
/* * 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;
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testGetValue01() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
resolver.getValue(null, new Object(), new Object());
}
/** * Tests that a valid property is resolved.
*/
@Test publicvoid testGetValue02() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object result = resolver.getValue(context, new ELClass(TesterClass.class), PROPERTY01_NAME);
/** * Tests that a valid property is not resolved if base is not ELCLass.
*/
@Test publicvoid testGetValue03() {
doNegativeTest(new Object(), PROPERTY01_NAME, MethodUnderTest.GET_VALUE);
}
/** * Tests that non String property is not resolved.
*/
@Test publicvoid testGetValue04() {
doNegativeTest(new ELClass(TesterClass.class), new Object(), MethodUnderTest.GET_VALUE);
}
/** * Property is not static
*/
@Test publicvoid testGetValue06() {
doThrowableTest(PROPERTY03_NAME, MethodUnderTest.GET_VALUE, false);
}
/** * Property is not public
*/
@Test publicvoid testGetValue07() {
doThrowableTest(PROPERTY04_NAME, MethodUnderTest.GET_VALUE, true);
}
/** * Property is neither public nor static
*/
@Test publicvoid testGetValue08() {
doThrowableTest(PROPERTY05_NAME, MethodUnderTest.GET_VALUE, true);
}
/** * Tests that a valid property of Enum is resolved.
*/
@Test publicvoid testGetValue09() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object result = resolver.getValue(context, new ELClass(MethodUnderTest.class),
MethodUnderTest.GET_TYPE.toString());
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testSetValue01() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
resolver.setValue(null, new Object(), new Object(), new Object());
}
/** * Tests that cannot write to a static field.
*/
@Test(expected = PropertyNotWritableException.class) publicvoid testSetValue02() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
resolver.setValue(context, new ELClass(TesterClass.class), PROPERTY01_NAME, PROPERTY01_VALUE);
}
/** * Tests that the operation is not invoked if base is not ELCLass.
*/
@Test publicvoid testSetValue03() {
doNegativeTest(new Object(), PROPERTY01_NAME, MethodUnderTest.SET_VALUE);
}
/** * Tests that the operation is no invoked when the property is not String.
*/
@Test publicvoid testSetValue04() {
doNegativeTest(new ELClass(TesterClass.class), new Object(), MethodUnderTest.SET_VALUE);
}
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testIsReadOnly01() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
resolver.isReadOnly(null, new Object(), new Object());
}
/** * Tests that the propertyResolved is true when base is ELCLass and the property is String.
*/
@Test publicvoid testIsReadOnly02() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
boolean result = resolver.isReadOnly(context, new ELClass(TesterClass.class), PROPERTY01_NAME);
/** * Tests that the propertyResolved is false if base is not ELCLass.
*/
@Test publicvoid testIsReadOnly03() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
boolean result = resolver.isReadOnly(context, new Object(), PROPERTY01_NAME);
/** * Tests that the propertyResolved is false when the property is not String.
*/
@Test publicvoid testIsReadOnly04() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
boolean result = resolver.isReadOnly(context, new ELClass(TesterClass.class), new Object());
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testGetType01() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
resolver.getType(null, new Object(), new Object());
}
/** * Tests that a valid property is resolved.
*/
@Test publicvoid testGetType02() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Class<?> result = resolver.getType(context, new ELClass(TesterClass.class), PROPERTY01_NAME);
// Resolver is read-only so this should return null Assert.assertNull(result);
}
/** * Tests that a valid property is not resolved if base is not ELCLass.
*/
@Test publicvoid testGetType03() {
doNegativeTest(new Object(), PROPERTY01_NAME, MethodUnderTest.GET_TYPE);
}
/** * Tests that non String property is not resolved.
*/
@Test publicvoid testGetType04() {
doNegativeTest(new ELClass(TesterClass.class), new Object(), MethodUnderTest.GET_TYPE);
}
/** * Property is not static
*/
@Test publicvoid testGetType06() {
doThrowableTest(PROPERTY03_NAME, MethodUnderTest.GET_TYPE, false);
}
/** * Property is not public
*/
@Test publicvoid testGetType07() {
doThrowableTest(PROPERTY04_NAME, MethodUnderTest.GET_TYPE, true);
}
/** * Property is neither public nor static
*/
@Test publicvoid testGetType08() {
doThrowableTest(PROPERTY05_NAME, MethodUnderTest.GET_TYPE, true);
}
/** * Tests that a valid property of Enum is resolved.
*/
@Test publicvoid testGetType09() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Class<?> result = resolver.getType(context, new ELClass(MethodUnderTest.class),
MethodUnderTest.GET_TYPE.toString());
// Resolver is read-only so this should return null Assert.assertNull(result);
}
/** * Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class) publicvoid testInvoke01() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
resolver.invoke(null, new Object(), new Object(), newClass<?>[] {}, new Object[] {});
}
/** * Tests a constructor invocation.
*/
@Test publicvoid testInvoke02() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object result = resolver.invoke(context, new ELClass(TesterClass.class), METHOD01_NAME, null, null);
/** * Tests that a valid method is not resolved if base is not ELCLass.
*/
@Test publicvoid testInvoke04() {
doNegativeTest(new Object(), METHOD02_NAME, MethodUnderTest.INVOKE);
}
/** * Tests that non String method name is not resolved.
*/
@Test publicvoid testInvoke05() {
doNegativeTest(new ELClass(TesterClass.class), new Object(), MethodUnderTest.INVOKE);
}
/** * Tests that a private constructor invocation will fail.
*/
@Test publicvoid testInvoke06() {
doThrowableTest(METHOD01_NAME, MethodUnderTest.INVOKE, false);
}
/** * Tests that a non static method invocation will fail.
*/
@Test publicvoid testInvoke07() {
doThrowableTest(METHOD03_NAME, MethodUnderTest.INVOKE, false);
}
/** * Tests a void method invocation.
*/
@Test publicvoid testInvoke08() {
StaticFieldELResolver resolver = new StaticFieldELResolver();
ELContext context = new StandardELContext(ELManager.getExpressionFactory());
Object result = resolver.invoke(context, new ELClass(TesterClass.class), METHOD04_NAME, newClass<?>[] {}, new Object[] {});
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.