|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -29,52 +29,70 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -29,52 +29,70 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
|
/** |
|
|
|
|
* @author Andy Clement |
|
|
|
|
*/ |
|
|
|
|
public class LiteralExpressionTests { |
|
|
|
|
class LiteralExpressionTests { |
|
|
|
|
|
|
|
|
|
private final LiteralExpression lEx = new LiteralExpression("somevalue"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getValue() throws Exception { |
|
|
|
|
assertThat(lEx.getValue()).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(String.class)).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(new Rooty())).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(new Rooty(), String.class)).isEqualTo("somevalue"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testGetValue() throws Exception { |
|
|
|
|
LiteralExpression lEx = new LiteralExpression("somevalue"); |
|
|
|
|
assertThat(lEx.getValue()).isInstanceOf(String.class).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); |
|
|
|
|
void getValueWithSuppliedEvaluationContext() throws Exception { |
|
|
|
|
EvaluationContext ctx = new StandardEvaluationContext(); |
|
|
|
|
assertThat(lEx.getValue(ctx)).isInstanceOf(String.class).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(ctx, String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(new Rooty())).isInstanceOf(String.class).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(new Rooty(), String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(ctx, new Rooty())).isInstanceOf(String.class).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(ctx, new Rooty(),String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(ctx)).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(ctx, String.class)).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(ctx, new Rooty())).isEqualTo("somevalue"); |
|
|
|
|
assertThat(lEx.getValue(ctx, new Rooty(), String.class)).isEqualTo("somevalue"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getExpressionString() { |
|
|
|
|
assertThat(lEx.getExpressionString()).isEqualTo("somevalue"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void isWritable() throws Exception { |
|
|
|
|
assertThat(lEx.isWritable(new StandardEvaluationContext())).isFalse(); |
|
|
|
|
assertThat(lEx.isWritable(new Rooty())).isFalse(); |
|
|
|
|
assertThat(lEx.isWritable(new StandardEvaluationContext(), new Rooty())).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class Rooty {} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSetValue() { |
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> |
|
|
|
|
new LiteralExpression("somevalue").setValue(new StandardEvaluationContext(), "flibble")) |
|
|
|
|
void setValue() { |
|
|
|
|
assertThatExceptionOfType(EvaluationException.class) |
|
|
|
|
.isThrownBy(() -> lEx.setValue(new StandardEvaluationContext(), "flibble")) |
|
|
|
|
.satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue")); |
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> |
|
|
|
|
new LiteralExpression("somevalue").setValue(new Rooty(), "flibble")) |
|
|
|
|
assertThatExceptionOfType(EvaluationException.class) |
|
|
|
|
.isThrownBy(() -> lEx.setValue(new Rooty(), "flibble")) |
|
|
|
|
.satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue")); |
|
|
|
|
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> |
|
|
|
|
new LiteralExpression("somevalue").setValue(new StandardEvaluationContext(), new Rooty(), "flibble")) |
|
|
|
|
assertThatExceptionOfType(EvaluationException.class) |
|
|
|
|
.isThrownBy(() -> lEx.setValue(new StandardEvaluationContext(), new Rooty(), "flibble")) |
|
|
|
|
.satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testGetValueType() throws Exception { |
|
|
|
|
LiteralExpression lEx = new LiteralExpression("somevalue"); |
|
|
|
|
void getValueType() throws Exception { |
|
|
|
|
assertThat(lEx.getValueType()).isEqualTo(String.class); |
|
|
|
|
assertThat(lEx.getValueType(new StandardEvaluationContext())).isEqualTo(String.class); |
|
|
|
|
assertThat(lEx.getValueType(new Rooty())).isEqualTo(String.class); |
|
|
|
|
assertThat(lEx.getValueType(new StandardEvaluationContext(), new Rooty())).isEqualTo(String.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getValueTypeDescriptor() throws Exception { |
|
|
|
|
assertThat(lEx.getValueTypeDescriptor().getType()).isEqualTo(String.class); |
|
|
|
|
assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext()).getType()).isEqualTo(String.class); |
|
|
|
|
assertThat(lEx.getValueTypeDescriptor(new Rooty()).getType()).isEqualTo(String.class); |
|
|
|
|
assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType()).isEqualTo(String.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class Rooty {} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|