Skip to content

Commit edabeee

Browse files
author
oborkovskyi
committed
Added tests
1 parent b05648e commit edabeee

4 files changed

Lines changed: 111 additions & 212 deletions

File tree

‎spring-spel/pom.xml‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>com.baeldung</groupId>
8-
<artifactId>guava</artifactId>
8+
<artifactId>spel</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010

1111
<dependencies>
12-
<dependency>
13-
<groupId>com.google.guava</groupId>
14-
<artifactId>guava</artifactId>
15-
<version>19.0</version>
16-
</dependency>
1712
<dependency>
1813
<groupId>junit</groupId>
1914
<artifactId>junit</artifactId>
@@ -26,13 +21,14 @@
2621
</dependency>
2722
<dependency>
2823
<groupId>org.springframework</groupId>
29-
<artifactId>spring-core</artifactId>
24+
<artifactId>spring-context</artifactId>
3025
<version>4.0.6.RELEASE</version>
3126
</dependency>
3227
<dependency>
3328
<groupId>org.springframework</groupId>
34-
<artifactId>spring-context</artifactId>
29+
<artifactId>spring-test</artifactId>
3530
<version>4.0.6.RELEASE</version>
31+
<scope>test</scope>
3632
</dependency>
3733
</dependencies>
3834
<build>

‎spring-spel/src/main/java/com/baeldung/spring/spel/examples/SpelOperators.java‎

Lines changed: 0 additions & 204 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.baeldung.spel;
2+
3+
import com.baeldung.spring.spel.examples.*;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.test.context.ContextConfiguration;
9+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10+
11+
import static org.hamcrest.Matchers.equalTo;
12+
13+
@RunWith(SpringJUnit4ClassRunner.class)
14+
@ContextConfiguration(locations = {"/applicationContext.xml"})
15+
public class SpelTest {
16+
17+
@Autowired
18+
private SpelArithmetic spelArithmetic = new SpelArithmetic();
19+
@Autowired
20+
private SpelCollections spelCollections = new SpelCollections();
21+
@Autowired
22+
private SpelConditional spelConditional = new SpelConditional();
23+
@Autowired
24+
private SpelLogical spelLogical = new SpelLogical();
25+
@Autowired
26+
private SpelRegex spelRegex = new SpelRegex();
27+
@Autowired
28+
private SpelRelational spelRelational = new SpelRelational();
29+
30+
@Test
31+
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));
42+
}
43+
44+
@Test
45+
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));
50+
}
51+
52+
@Test
53+
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"));
57+
}
58+
59+
@Test
60+
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+
}
68+
69+
@Test
70+
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));
76+
}
77+
78+
@Test
79+
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));
98+
}
99+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<beans xmlns="http://www.springframework.org/schema/beans"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:context="http://www.springframework.org/schema/context"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
5+
6+
<context:component-scan base-package="com.baeldung.spring.spel" />
7+
8+
</beans>

0 commit comments

Comments
 (0)