|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
29 | 29 | /**
|
30 | 30 | * @author Andy Clement
|
31 | 31 | */
|
32 |
| -public class LiteralExpressionTests { |
| 32 | +class LiteralExpressionTests { |
| 33 | + |
| 34 | + private final LiteralExpression lEx = new LiteralExpression("somevalue"); |
| 35 | + |
| 36 | + |
| 37 | + @Test |
| 38 | + void getValue() throws Exception { |
| 39 | + assertThat(lEx.getValue()).isEqualTo("somevalue"); |
| 40 | + assertThat(lEx.getValue(String.class)).isEqualTo("somevalue"); |
| 41 | + assertThat(lEx.getValue(new Rooty())).isEqualTo("somevalue"); |
| 42 | + assertThat(lEx.getValue(new Rooty(), String.class)).isEqualTo("somevalue"); |
| 43 | + } |
33 | 44 |
|
34 | 45 | @Test
|
35 |
| - public void testGetValue() throws Exception { |
36 |
| - LiteralExpression lEx = new LiteralExpression("somevalue"); |
37 |
| - assertThat(lEx.getValue()).isInstanceOf(String.class).isEqualTo("somevalue"); |
38 |
| - assertThat(lEx.getValue(String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); |
| 46 | + void getValueWithSuppliedEvaluationContext() throws Exception { |
39 | 47 | EvaluationContext ctx = new StandardEvaluationContext();
|
40 |
| - assertThat(lEx.getValue(ctx)).isInstanceOf(String.class).isEqualTo("somevalue"); |
41 |
| - assertThat(lEx.getValue(ctx, String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); |
42 |
| - assertThat(lEx.getValue(new Rooty())).isInstanceOf(String.class).isEqualTo("somevalue"); |
43 |
| - assertThat(lEx.getValue(new Rooty(), String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); |
44 |
| - assertThat(lEx.getValue(ctx, new Rooty())).isInstanceOf(String.class).isEqualTo("somevalue"); |
45 |
| - assertThat(lEx.getValue(ctx, new Rooty(),String.class)).isInstanceOf(String.class).isEqualTo("somevalue"); |
| 48 | + assertThat(lEx.getValue(ctx)).isEqualTo("somevalue"); |
| 49 | + assertThat(lEx.getValue(ctx, String.class)).isEqualTo("somevalue"); |
| 50 | + assertThat(lEx.getValue(ctx, new Rooty())).isEqualTo("somevalue"); |
| 51 | + assertThat(lEx.getValue(ctx, new Rooty(), String.class)).isEqualTo("somevalue"); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void getExpressionString() { |
46 | 56 | assertThat(lEx.getExpressionString()).isEqualTo("somevalue");
|
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void isWritable() throws Exception { |
47 | 61 | assertThat(lEx.isWritable(new StandardEvaluationContext())).isFalse();
|
48 | 62 | assertThat(lEx.isWritable(new Rooty())).isFalse();
|
49 | 63 | assertThat(lEx.isWritable(new StandardEvaluationContext(), new Rooty())).isFalse();
|
50 | 64 | }
|
51 | 65 |
|
52 |
| - static class Rooty {} |
53 |
| - |
54 | 66 | @Test
|
55 |
| - public void testSetValue() { |
56 |
| - assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> |
57 |
| - new LiteralExpression("somevalue").setValue(new StandardEvaluationContext(), "flibble")) |
| 67 | + void setValue() { |
| 68 | + assertThatExceptionOfType(EvaluationException.class) |
| 69 | + .isThrownBy(() -> lEx.setValue(new StandardEvaluationContext(), "flibble")) |
58 | 70 | .satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue"));
|
59 |
| - assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> |
60 |
| - new LiteralExpression("somevalue").setValue(new Rooty(), "flibble")) |
| 71 | + assertThatExceptionOfType(EvaluationException.class) |
| 72 | + .isThrownBy(() -> lEx.setValue(new Rooty(), "flibble")) |
61 | 73 | .satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue"));
|
62 |
| - assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> |
63 |
| - new LiteralExpression("somevalue").setValue(new StandardEvaluationContext(), new Rooty(), "flibble")) |
| 74 | + assertThatExceptionOfType(EvaluationException.class) |
| 75 | + .isThrownBy(() -> lEx.setValue(new StandardEvaluationContext(), new Rooty(), "flibble")) |
64 | 76 | .satisfies(ex -> assertThat(ex.getExpressionString()).isEqualTo("somevalue"));
|
65 | 77 | }
|
66 | 78 |
|
67 | 79 | @Test
|
68 |
| - public void testGetValueType() throws Exception { |
69 |
| - LiteralExpression lEx = new LiteralExpression("somevalue"); |
| 80 | + void getValueType() throws Exception { |
70 | 81 | assertThat(lEx.getValueType()).isEqualTo(String.class);
|
71 | 82 | assertThat(lEx.getValueType(new StandardEvaluationContext())).isEqualTo(String.class);
|
72 | 83 | assertThat(lEx.getValueType(new Rooty())).isEqualTo(String.class);
|
73 | 84 | assertThat(lEx.getValueType(new StandardEvaluationContext(), new Rooty())).isEqualTo(String.class);
|
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + void getValueTypeDescriptor() throws Exception { |
74 | 89 | assertThat(lEx.getValueTypeDescriptor().getType()).isEqualTo(String.class);
|
75 | 90 | assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext()).getType()).isEqualTo(String.class);
|
76 | 91 | assertThat(lEx.getValueTypeDescriptor(new Rooty()).getType()).isEqualTo(String.class);
|
77 | 92 | assertThat(lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType()).isEqualTo(String.class);
|
78 | 93 | }
|
79 | 94 |
|
| 95 | + |
| 96 | + static class Rooty {} |
| 97 | + |
80 | 98 | }
|
0 commit comments