You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/07/04 20:43:52 UTC
[tomcat] 02/02: Expand code coverage for ArrayELResolver
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 17242464af539a92e347aff726c3f95f290e71c1
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jul 4 21:42:59 2019 +0100
Expand code coverage for ArrayELResolver
---
test/javax/el/TestArrayELResolver.java | 170 ++++++++++++++++++++++++++++++++-
1 file changed, 166 insertions(+), 4 deletions(-)
diff --git a/test/javax/el/TestArrayELResolver.java b/test/javax/el/TestArrayELResolver.java
index cea9b97..1280fb1 100644
--- a/test/javax/el/TestArrayELResolver.java
+++ b/test/javax/el/TestArrayELResolver.java
@@ -85,6 +85,21 @@ public class TestArrayELResolver {
}
/**
+ * Tests that a null result is returned when the base is null.
+ */
+ @Test
+ public void testGetType06() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ Class<?> result = resolver.getType(context, null, "index");
+
+ Assert.assertNull(result);
+ Assert.assertFalse(context.isPropertyResolved());
+ }
+
+ /**
* Tests that a null context results in an NPE as per EL Javadoc.
*/
@Test(expected = NullPointerException.class)
@@ -118,11 +133,83 @@ public class TestArrayELResolver {
Assert.assertTrue(context.isPropertyResolved());
}
+ @Test
+ public void testGetValueCoercion01() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ String[] base = new String[] { "element" };
+ Object result = resolver.getValue(context, base, Character.valueOf((char) 0));
+
+ Assert.assertEquals("element", result);
+ Assert.assertTrue(context.isPropertyResolved());
+ }
+
+ @Test
+ public void testGetValueCoercion02a() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ String[] base = new String[] { "element" };
+ Object result = resolver.getValue(context, base, Boolean.FALSE);
+
+ Assert.assertEquals("element", result);
+ Assert.assertTrue(context.isPropertyResolved());
+ }
+
+ @Test
+ public void testGetValueCoercion02b() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ String[] base = new String[] { "element" };
+ Object result = resolver.getValue(context, base, Boolean.TRUE);
+
+ Assert.assertNull(result);
+ Assert.assertTrue(context.isPropertyResolved());
+ }
+
+ @Test
+ public void testGetValueCoercion03() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ String[] base = new String[] { "element" };
+ Object result = resolver.getValue(context, base, "0");
+
+ Assert.assertEquals("element", result);
+ Assert.assertTrue(context.isPropertyResolved());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetValueCoercion04() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ String[] base = new String[] { "element" };
+ resolver.getValue(context, base, new Object());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetValueCoercion05() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ String[] base = new String[] { "element" };
+ resolver.getValue(context, base, null);
+ }
+
/**
* Tests a coercion cannot be performed as the key is not integer.
*/
@Test(expected = IllegalArgumentException.class)
- public void testGetValue04() {
+ public void testGetValueCoercion06() {
ArrayELResolver resolver = new ArrayELResolver();
ELContext context = new StandardELContext(
ELManager.getExpressionFactory());
@@ -132,7 +219,7 @@ public class TestArrayELResolver {
}
/**
- * Tests that the key is out of bounds and null will be returned.
+ * Tests that if the key is out of bounds null will be returned.
*/
@Test
public void testGetValue05() {
@@ -261,6 +348,19 @@ public class TestArrayELResolver {
Assert.assertEquals(Integer.valueOf(base[1]), Integer.valueOf(4));
}
+ /*
+ * Null base should be a NO-OP rather than an exception
+ */
+ @Test
+ public void testSetValue09() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ resolver.setValue(context, null, Integer.valueOf(1), Integer.valueOf(4));
+ Assert.assertFalse(context.isPropertyResolved());
+ }
+
/**
* Tests that a null context results in an NPE as per EL Javadoc.
*/
@@ -322,19 +422,29 @@ public class TestArrayELResolver {
*/
@Test(expected = PropertyNotFoundException.class)
public void testIsReadOnly04() {
+ doTestIsReadOutOfBounds(1);
+ }
+
+ @Test(expected = PropertyNotFoundException.class)
+ public void testIsReadOnly05() {
+ doTestIsReadOutOfBounds(-1);
+ }
+
+ private void doTestIsReadOutOfBounds(int index) {
ArrayELResolver resolver = new ArrayELResolver();
ELContext context = new StandardELContext(
ELManager.getExpressionFactory());
String[] base = new String[] { "element" };
- resolver.isReadOnly(context, base, Integer.valueOf(1));
+ resolver.isReadOnly(context, base, Integer.valueOf(index));
+ Assert.assertTrue(context.isPropertyResolved());
}
/**
* Tests that a result is returned even when a coercion cannot be performed.
*/
@Test
- public void testIsReadOnly05() {
+ public void testIsReadOnly06() {
ArrayELResolver resolver = new ArrayELResolver();
ELContext context = new StandardELContext(
ELManager.getExpressionFactory());
@@ -353,6 +463,25 @@ public class TestArrayELResolver {
Assert.assertTrue(context.isPropertyResolved());
}
+ @Test
+ public void testIsReadOnly07() {
+ ArrayELResolver resolver = new ArrayELResolver();
+ ELContext context = new StandardELContext(
+ ELManager.getExpressionFactory());
+
+ boolean result = resolver.isReadOnly(context, null, null);
+
+ Assert.assertFalse(result);
+ Assert.assertFalse(context.isPropertyResolved());
+
+ resolver = new ArrayELResolver(true);
+
+ result = resolver.isReadOnly(context, null, null);
+
+ Assert.assertTrue(result);
+ Assert.assertFalse(context.isPropertyResolved());
+ }
+
private void doNegativeTest(Object base, Object trigger,
MethodUnderTest method, boolean checkResult) {
ArrayELResolver resolver = new ArrayELResolver();
@@ -389,4 +518,37 @@ public class TestArrayELResolver {
GET_VALUE, SET_VALUE, GET_TYPE
}
+
+ @Test
+ public void testGetFeatureDescriptiors() {
+ // Should always return null
+ ArrayELResolver resolver = new ArrayELResolver();
+ Assert.assertNull(resolver.getFeatureDescriptors(null, null));
+ }
+
+
+ @Test
+ public void testGetCommonPropertyType01() {
+ // null base, null response
+ ArrayELResolver resolver = new ArrayELResolver();
+ Assert.assertNull(resolver.getCommonPropertyType(null, null));
+ }
+
+
+ @Test
+ public void testGetCommonPropertyType02() {
+ // non-array base, null response
+ ArrayELResolver resolver = new ArrayELResolver();
+ Assert.assertNull(resolver.getCommonPropertyType(null, new Object()));
+ }
+
+
+ @Test
+ public void testGetCommonPropertyType03() {
+ // array base, Integer response
+ ArrayELResolver resolver = new ArrayELResolver();
+ Class<?> clazz = resolver.getCommonPropertyType(null, new Object[]{});
+ Assert.assertNotNull(clazz);
+ Assert.assertEquals(clazz, Integer.class);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org