private CacheOperationCacheKey(CacheOperation cacheOperation, Method method, Class<?> targetClass) { this.cacheOperation = cacheOperation; this.methodCacheKey = new AnnotatedElementKey(method, targetClass); }
private ExpressionKey createKey(AnnotatedElementKey elementKey, String expression) { return new ExpressionKey(elementKey, expression); }
private EvaluationContext createEvaluationContext(PageContext pageContext) { StandardEvaluationContext context = new StandardEvaluationContext(); context.addPropertyAccessor(new JspPropertyAccessor(pageContext)); context.addPropertyAccessor(new MapAccessor()); context.addPropertyAccessor(new EnvironmentAccessor()); context.setBeanResolver(new BeanFactoryResolver(getRequestContext().getWebApplicationContext())); ConversionService conversionService = getConversionService(pageContext); if (conversionService != null) { context.setTypeConverter(new StandardTypeConverter(conversionService)); } return context; }
@Test public void varArgEmpty() { Method method = ReflectionUtils.findMethod(SampleMethods.class, "hello", Boolean.class, String[].class); MethodBasedEvaluationContext context = createEvaluationContext(method, new Object[] {null}); assertNull(context.lookupVariable("a0")); assertNull(context.lookupVariable("p0")); assertNull(context.lookupVariable("flag")); assertNull(context.lookupVariable("a1")); assertNull(context.lookupVariable("p1")); assertNull(context.lookupVariable("vararg")); }
public Expression getTestExpression(String expression, Method method, Class<?> type) { return getExpression(this.testCache, new AnnotatedElementKey(method, type), expression); }
@Test public void equalsNoTarget() { Method m = ReflectionUtils.findMethod(getClass(), name.getMethodName()); AnnotatedElementKey first = new AnnotatedElementKey(m, null); AnnotatedElementKey second = new AnnotatedElementKey(m, null); assertKeyEquals(first, second); }
private MethodBasedEvaluationContext createEvaluationContext(Method method, Object... args) { return new MethodBasedEvaluationContext(this, method, args, this.paramDiscover); }
@Override public int hashCode() { return this.element.hashCode() * 29 + this.expression.hashCode(); }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof ExpressionKey)) { return false; } ExpressionKey otherKey = (ExpressionKey) other; return (this.element.equals(otherKey.element) && ObjectUtils.nullSafeEquals(this.expression, otherKey.expression)); }
public Car getObject() { return new Car(); }
public TestExpressionEvaluator() { super(mockSpelExpressionParser()); }
@Test public void varArgMultiple() { Method method = ReflectionUtils.findMethod(SampleMethods.class, "hello", Boolean.class, String[].class); MethodBasedEvaluationContext context = createEvaluationContext(method, null, "hello", "hi"); assertNull(context.lookupVariable("a0")); assertNull(context.lookupVariable("p0")); assertNull(context.lookupVariable("flag")); assertArrayEquals(new Object[] {"hello", "hi"}, (Object[]) context.lookupVariable("a1")); assertArrayEquals(new Object[] {"hello", "hi"}, (Object[]) context.lookupVariable("p1")); assertArrayEquals(new Object[] {"hello", "hi"}, (Object[]) context.lookupVariable("vararg")); }
@Override public int hashCode() { return (this.cacheOperation.hashCode() * 31 + this.methodCacheKey.hashCode()); }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof CacheOperationCacheKey)) { return false; } CacheOperationCacheKey otherKey = (CacheOperationCacheKey) other; return (this.cacheOperation.equals(otherKey.cacheOperation) && this.methodCacheKey.equals(otherKey.methodCacheKey)); }
@Test public void nullArgument() { Method method = ReflectionUtils.findMethod(SampleMethods.class, "hello", String.class, Boolean.class); MethodBasedEvaluationContext context = createEvaluationContext(method, null, null); assertNull(context.lookupVariable("a0")); assertNull(context.lookupVariable("p0")); assertNull(context.lookupVariable("foo")); assertNull(context.lookupVariable("a1")); assertNull(context.lookupVariable("p1")); assertNull(context.lookupVariable("flag")); }
@Test public void varArgNull() { Method method = ReflectionUtils.findMethod(SampleMethods.class, "hello", Boolean.class, String[].class); MethodBasedEvaluationContext context = createEvaluationContext(method, null, null); assertNull(context.lookupVariable("a0")); assertNull(context.lookupVariable("p0")); assertNull(context.lookupVariable("flag")); assertNull(context.lookupVariable("a1")); assertNull(context.lookupVariable("p1")); assertNull(context.lookupVariable("vararg")); }
@Test public void varArgSingle() { Method method = ReflectionUtils.findMethod(SampleMethods.class, "hello", Boolean.class, String[].class); MethodBasedEvaluationContext context = createEvaluationContext(method, null, "hello"); assertNull(context.lookupVariable("a0")); assertNull(context.lookupVariable("p0")); assertNull(context.lookupVariable("flag")); assertEquals("hello", context.lookupVariable("a1")); assertEquals("hello", context.lookupVariable("p1")); assertEquals("hello", context.lookupVariable("vararg")); }
@Test public void simpleArguments() { Method method = ReflectionUtils.findMethod(SampleMethods.class, "hello", String.class, Boolean.class); MethodBasedEvaluationContext context = createEvaluationContext(method, "test", true); assertEquals("test", context.lookupVariable("a0")); assertEquals("test", context.lookupVariable("p0")); assertEquals("test", context.lookupVariable("foo")); assertEquals(true, context.lookupVariable("a1")); assertEquals(true, context.lookupVariable("p1")); assertEquals(true, context.lookupVariable("flag")); assertNull(context.lookupVariable("a2")); assertNull(context.lookupVariable("p2")); }