Polishing

This commit is contained in:
Sam Brannen 2022-12-07 15:39:40 -05:00
parent 098c924e32
commit c899af0e03
1 changed files with 41 additions and 23 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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;
/** /**
* @author Andy Clement * @author Andy Clement
*/ */
public class LiteralExpressionTests { class LiteralExpressionTests {
private final LiteralExpression lEx = new LiteralExpression("somevalue");
@Test @Test
public void testGetValue() throws Exception { void getValue() throws Exception {
LiteralExpression lEx = new LiteralExpression("somevalue"); assertThat(lEx.getValue()).isEqualTo("somevalue");
assertThat(lEx.getValue()).isInstanceOf(String.class).isEqualTo("somevalue"); assertThat(lEx.getValue(String.class)).isEqualTo("somevalue");
assertThat(lEx.getValue(String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); assertThat(lEx.getValue(new Rooty())).isEqualTo("somevalue");
assertThat(lEx.getValue(new Rooty(), String.class)).isEqualTo("somevalue");
}
@Test
void getValueWithSuppliedEvaluationContext() throws Exception {
EvaluationContext ctx = new StandardEvaluationContext(); EvaluationContext ctx = new StandardEvaluationContext();
assertThat(lEx.getValue(ctx)).isInstanceOf(String.class).isEqualTo("somevalue"); assertThat(lEx.getValue(ctx)).isEqualTo("somevalue");
assertThat(lEx.getValue(ctx, String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); assertThat(lEx.getValue(ctx, String.class)).isEqualTo("somevalue");
assertThat(lEx.getValue(new Rooty())).isInstanceOf(String.class).isEqualTo("somevalue"); assertThat(lEx.getValue(ctx, new Rooty())).isEqualTo("somevalue");
assertThat(lEx.getValue(new Rooty(), String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); assertThat(lEx.getValue(ctx, new Rooty(), 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");
@Test
void getExpressionString() {
assertThat(lEx.getExpressionString()).isEqualTo("somevalue"); assertThat(lEx.getExpressionString()).isEqualTo("somevalue");
}
@Test
void isWritable() throws Exception {
assertThat(lEx.isWritable(new StandardEvaluationContext())).isFalse(); assertThat(lEx.isWritable(new StandardEvaluationContext())).isFalse();
assertThat(lEx.isWritable(new Rooty())).isFalse(); assertThat(lEx.isWritable(new Rooty())).isFalse();
assertThat(lEx.isWritable(new StandardEvaluationContext(), new Rooty())).isFalse(); assertThat(lEx.isWritable(new StandardEvaluationContext(), new Rooty())).isFalse();
} }
static class Rooty {}
@Test @Test
public void testSetValue() { void setValue() {
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> assertThatExceptionOfType(EvaluationException.class)
new LiteralExpression("somevalue").setValue(new StandardEvaluationContext(), "flibble")) .isThrownBy(() -> lEx.setValue(new StandardEvaluationContext(), "flibble"))
.satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue")); .satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue"));
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> assertThatExceptionOfType(EvaluationException.class)
new LiteralExpression("somevalue").setValue(new Rooty(), "flibble")) .isThrownBy(() -> lEx.setValue(new Rooty(), "flibble"))
.satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue")); .satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue"));
assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> assertThatExceptionOfType(EvaluationException.class)
new LiteralExpression("somevalue").setValue(new StandardEvaluationContext(), new Rooty(), "flibble")) .isThrownBy(() -> lEx.setValue(new StandardEvaluationContext(), new Rooty(), "flibble"))
.satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue")); .satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue"));
} }
@Test @Test
public void testGetValueType() throws Exception { void getValueType() throws Exception {
LiteralExpression lEx = new LiteralExpression("somevalue");
assertThat(lEx.getValueType()).isEqualTo(String.class); assertThat(lEx.getValueType()).isEqualTo(String.class);
assertThat(lEx.getValueType(new StandardEvaluationContext())).isEqualTo(String.class); assertThat(lEx.getValueType(new StandardEvaluationContext())).isEqualTo(String.class);
assertThat(lEx.getValueType(new Rooty())).isEqualTo(String.class); assertThat(lEx.getValueType(new Rooty())).isEqualTo(String.class);
assertThat(lEx.getValueType(new StandardEvaluationContext(), 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().getType()).isEqualTo(String.class);
assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext()).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 Rooty()).getType()).isEqualTo(String.class);
assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType()).isEqualTo(String.class); assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType()).isEqualTo(String.class);
} }
static class Rooty {}
} }