Skip to content

Commit 4ab9fe6

Browse files
committed
Clean up SpEL examples
1 parent 2ce4f5a commit 4ab9fe6

2 files changed

Lines changed: 54 additions & 48 deletions

File tree

‎spring-spel/src/main/java/com/baeldung/spring/spel/SpelProgram.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static void main(String[] args) {
99
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
1010
SpelConditional spelCollections = (SpelConditional) context.getBean("spelConditional");
1111

12-
// Here you can choose which bean do you want to load insted of spelConditional: spelCollections, spelLogical, etc.
12+
// Here you can choose which bean do you want to load instead of spelConditional: spelCollections, spelLogical, etc.
1313

1414
System.out.println(spelCollections);
1515
}

‎spring-spel/src/test/java/com/baeldung/spel/SpelTest.java‎

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,91 +9,97 @@
99
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1010

1111
import static org.hamcrest.Matchers.equalTo;
12+
import static org.junit.Assert.assertThat;
1213

1314
@RunWith(SpringJUnit4ClassRunner.class)
14-
@ContextConfiguration(locations = {"/applicationContext.xml"})
15+
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
1516
public class SpelTest {
1617

1718
@Autowired
1819
private SpelArithmetic spelArithmetic = new SpelArithmetic();
20+
1921
@Autowired
2022
private SpelCollections spelCollections = new SpelCollections();
23+
2124
@Autowired
2225
private SpelConditional spelConditional = new SpelConditional();
26+
2327
@Autowired
2428
private SpelLogical spelLogical = new SpelLogical();
29+
2530
@Autowired
2631
private SpelRegex spelRegex = new SpelRegex();
32+
2733
@Autowired
2834
private SpelRelational spelRelational = new SpelRelational();
2935

3036
@Test
3137
public void testArithmetic() throws Exception {
32-
Assert.assertThat(spelArithmetic.getAdd(), equalTo(20.0));
33-
Assert.assertThat(spelArithmetic.getAddString(), equalTo("Some string plus other string"));
34-
Assert.assertThat(spelArithmetic.getSubtract(), equalTo(19.0));
35-
Assert.assertThat(spelArithmetic.getMultiply(), equalTo(20.0));
36-
Assert.assertThat(spelArithmetic.getDivide(), equalTo(18.0));
37-
Assert.assertThat(spelArithmetic.getDivideAlphabetic(), equalTo(18.0));
38-
Assert.assertThat(spelArithmetic.getModulo(), equalTo(7.0));
39-
Assert.assertThat(spelArithmetic.getModuloAlphabetic(), equalTo(7.0));
40-
Assert.assertThat(spelArithmetic.getPowerOf(), equalTo(512.0));
41-
Assert.assertThat(spelArithmetic.getBrackets(), equalTo(17.0));
38+
assertThat(spelArithmetic.getAdd(), equalTo(20.0));
39+
assertThat(spelArithmetic.getAddString(), equalTo("Some string plus other string"));
40+
assertThat(spelArithmetic.getSubtract(), equalTo(19.0));
41+
assertThat(spelArithmetic.getMultiply(), equalTo(20.0));
42+
assertThat(spelArithmetic.getDivide(), equalTo(18.0));
43+
assertThat(spelArithmetic.getDivideAlphabetic(), equalTo(18.0));
44+
assertThat(spelArithmetic.getModulo(), equalTo(7.0));
45+
assertThat(spelArithmetic.getModuloAlphabetic(), equalTo(7.0));
46+
assertThat(spelArithmetic.getPowerOf(), equalTo(512.0));
47+
assertThat(spelArithmetic.getBrackets(), equalTo(17.0));
4248
}
4349

4450
@Test
4551
public void testCollections() throws Exception {
46-
Assert.assertThat(spelCollections.getDriver1Car().getModel(), equalTo("Model1"));
47-
Assert.assertThat(spelCollections.getDriver2Car().getModel(), equalTo("Model2"));
48-
Assert.assertThat(spelCollections.getFirstCarInPark().getModel(), equalTo("Model1"));
49-
Assert.assertThat(spelCollections.getNumberOfCarsInPark(), equalTo(2));
52+
assertThat(spelCollections.getDriver1Car().getModel(), equalTo("Model1"));
53+
assertThat(spelCollections.getDriver2Car().getModel(), equalTo("Model2"));
54+
assertThat(spelCollections.getFirstCarInPark().getModel(), equalTo("Model1"));
55+
assertThat(spelCollections.getNumberOfCarsInPark(), equalTo(2));
5056
}
5157

5258
@Test
5359
public void testConditional() throws Exception {
54-
Assert.assertThat(spelConditional.getTernary(), equalTo("Something went wrong. There was false value"));
55-
Assert.assertThat(spelConditional.getTernary2(), equalTo("Some model"));
56-
Assert.assertThat(spelConditional.getElvis(), equalTo("Some model"));
60+
assertThat(spelConditional.getTernary(), equalTo("Something went wrong. There was false value"));
61+
assertThat(spelConditional.getTernary2(), equalTo("Some model"));
62+
assertThat(spelConditional.getElvis(), equalTo("Some model"));
5763
}
5864

5965
@Test
6066
public void testLogical() throws Exception {
61-
Assert.assertThat(spelLogical.isAnd(), equalTo(true));
62-
Assert.assertThat(spelLogical.isAndAlphabetic(), equalTo(true));
63-
Assert.assertThat(spelLogical.isOr(), equalTo(true));
64-
Assert.assertThat(spelLogical.isOrAlphabetic(), equalTo(true));
65-
Assert.assertThat(spelLogical.isNot(), equalTo(false));
66-
Assert.assertThat(spelLogical.isNotAlphabetic(), equalTo(false));
67+
assertThat(spelLogical.isAnd(), equalTo(true));
68+
assertThat(spelLogical.isAndAlphabetic(), equalTo(true));
69+
assertThat(spelLogical.isOr(), equalTo(true));
70+
assertThat(spelLogical.isOrAlphabetic(), equalTo(true));
71+
assertThat(spelLogical.isNot(), equalTo(false));
72+
assertThat(spelLogical.isNotAlphabetic(), equalTo(false));
6773
}
6874

6975
@Test
7076
public void testRegex() throws Exception {
71-
Assert.assertThat(spelRegex.isValidNumericStringResult(), equalTo(true));
72-
Assert.assertThat(spelRegex.isInvalidNumericStringResult(), equalTo(false));
73-
Assert.assertThat(spelRegex.isValidAlphabeticStringResult(), equalTo(true));
74-
Assert.assertThat(spelRegex.isInvalidAlphabeticStringResult(), equalTo(false));
75-
Assert.assertThat(spelRegex.isValidFormatOfHorsePower(), equalTo(true));
77+
assertThat(spelRegex.isValidNumericStringResult(), equalTo(true));
78+
assertThat(spelRegex.isInvalidNumericStringResult(), equalTo(false));
79+
assertThat(spelRegex.isValidAlphabeticStringResult(), equalTo(true));
80+
assertThat(spelRegex.isInvalidAlphabeticStringResult(), equalTo(false));
81+
assertThat(spelRegex.isValidFormatOfHorsePower(), equalTo(true));
7682
}
7783

7884
@Test
7985
public void testRelational() throws Exception {
80-
Assert.assertThat(spelRelational.isEqual(), equalTo(true));
81-
Assert.assertThat(spelRelational.isEqualAlphabetic(), equalTo(true));
82-
Assert.assertThat(spelRelational.isNotEqual(), equalTo(false));
83-
Assert.assertThat(spelRelational.isNotEqualAlphabetic(), equalTo(false));
84-
Assert.assertThat(spelRelational.isLessThan(), equalTo(false));
85-
Assert.assertThat(spelRelational.isLessThanAlphabetic(), equalTo(false));
86-
Assert.assertThat(spelRelational.isLessThanOrEqual(), equalTo(true));
87-
Assert.assertThat(spelRelational.isLessThanOrEqualAlphabetic(), equalTo(true));
88-
Assert.assertThat(spelRelational.isGreaterThan(), equalTo(false));
89-
Assert.assertThat(spelRelational.isGreaterThanAlphabetic(), equalTo(false));
90-
Assert.assertThat(spelRelational.isGreaterThanOrEqual(), equalTo(true));
91-
Assert.assertThat(spelRelational.isGreaterThanOrEqualAlphabetic(), equalTo(true));
92-
Assert.assertThat(spelRelational.isAnd(), equalTo(true));
93-
Assert.assertThat(spelRelational.isAndAlphabetic(), equalTo(true));
94-
Assert.assertThat(spelRelational.isOr(), equalTo(true));
95-
Assert.assertThat(spelRelational.isOrAlphabetic(), equalTo(true));
96-
Assert.assertThat(spelRelational.isNot(), equalTo(false));
97-
Assert.assertThat(spelRelational.isNotAlphabetic(), equalTo(false));
86+
assertThat(spelRelational.isEqual(), equalTo(true));
87+
assertThat(spelRelational.isEqualAlphabetic(), equalTo(true));
88+
assertThat(spelRelational.isNotEqual(), equalTo(false));
89+
assertThat(spelRelational.isNotEqualAlphabetic(), equalTo(false));
90+
assertThat(spelRelational.isLessThan(), equalTo(false));
91+
assertThat(spelRelational.isLessThanAlphabetic(), equalTo(false));
92+
assertThat(spelRelational.isLessThanOrEqual(), equalTo(true));
93+
assertThat(spelRelational.isLessThanOrEqualAlphabetic(), equalTo(true));
94+
assertThat(spelRelational.isGreaterThan(), equalTo(false));
95+
assertThat(spelRelational.isGreaterThanAlphabetic(), equalTo(false));
96+
assertThat(spelRelational.isGreaterThanOrEqual(), equalTo(true));
97+
assertThat(spelRelational.isGreaterThanOrEqualAlphabetic(), equalTo(true));
98+
assertThat(spelRelational.isAnd(), equalTo(true));
99+
assertThat(spelRelational.isAndAlphabetic(), equalTo(true));
100+
assertThat(spelRelational.isOr(), equalTo(true));
101+
assertThat(spelRelational.isOrAlphabetic(), equalTo(true));
102+
assertThat(spelRelational.isNot(), equalTo(false));
103+
assertThat(spelRelational.isNotAlphabetic(), equalTo(false));
98104
}
99105
}

0 commit comments

Comments
 (0)