From 4ab9fe66020b7955f031e27c4ac3c0c76dc45028 Mon Sep 17 00:00:00 2001 From: David Morley Date: Thu, 14 Apr 2016 06:08:48 -0500 Subject: [PATCH] Clean up SpEL examples --- .../com/baeldung/spring/spel/SpelProgram.java | 2 +- .../test/java/com/baeldung/spel/SpelTest.java | 100 ++++++++++-------- 2 files changed, 54 insertions(+), 48 deletions(-) diff --git a/spring-spel/src/main/java/com/baeldung/spring/spel/SpelProgram.java b/spring-spel/src/main/java/com/baeldung/spring/spel/SpelProgram.java index f399ce4a9c..3ad9e7d05d 100644 --- a/spring-spel/src/main/java/com/baeldung/spring/spel/SpelProgram.java +++ b/spring-spel/src/main/java/com/baeldung/spring/spel/SpelProgram.java @@ -9,7 +9,7 @@ public class SpelProgram { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); SpelConditional spelCollections = (SpelConditional) context.getBean("spelConditional"); - // Here you can choose which bean do you want to load insted of spelConditional: spelCollections, spelLogical, etc. + // Here you can choose which bean do you want to load instead of spelConditional: spelCollections, spelLogical, etc. System.out.println(spelCollections); } diff --git a/spring-spel/src/test/java/com/baeldung/spel/SpelTest.java b/spring-spel/src/test/java/com/baeldung/spel/SpelTest.java index 3ca0a04f5b..5cf18bc1d2 100644 --- a/spring-spel/src/test/java/com/baeldung/spel/SpelTest.java +++ b/spring-spel/src/test/java/com/baeldung/spel/SpelTest.java @@ -9,91 +9,97 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"/applicationContext.xml"}) +@ContextConfiguration(locations = {"classpath:applicationContext.xml"}) public class SpelTest { @Autowired private SpelArithmetic spelArithmetic = new SpelArithmetic(); + @Autowired private SpelCollections spelCollections = new SpelCollections(); + @Autowired private SpelConditional spelConditional = new SpelConditional(); + @Autowired private SpelLogical spelLogical = new SpelLogical(); + @Autowired private SpelRegex spelRegex = new SpelRegex(); + @Autowired private SpelRelational spelRelational = new SpelRelational(); @Test public void testArithmetic() throws Exception { - Assert.assertThat(spelArithmetic.getAdd(), equalTo(20.0)); - Assert.assertThat(spelArithmetic.getAddString(), equalTo("Some string plus other string")); - Assert.assertThat(spelArithmetic.getSubtract(), equalTo(19.0)); - Assert.assertThat(spelArithmetic.getMultiply(), equalTo(20.0)); - Assert.assertThat(spelArithmetic.getDivide(), equalTo(18.0)); - Assert.assertThat(spelArithmetic.getDivideAlphabetic(), equalTo(18.0)); - Assert.assertThat(spelArithmetic.getModulo(), equalTo(7.0)); - Assert.assertThat(spelArithmetic.getModuloAlphabetic(), equalTo(7.0)); - Assert.assertThat(spelArithmetic.getPowerOf(), equalTo(512.0)); - Assert.assertThat(spelArithmetic.getBrackets(), equalTo(17.0)); + assertThat(spelArithmetic.getAdd(), equalTo(20.0)); + assertThat(spelArithmetic.getAddString(), equalTo("Some string plus other string")); + assertThat(spelArithmetic.getSubtract(), equalTo(19.0)); + assertThat(spelArithmetic.getMultiply(), equalTo(20.0)); + assertThat(spelArithmetic.getDivide(), equalTo(18.0)); + assertThat(spelArithmetic.getDivideAlphabetic(), equalTo(18.0)); + assertThat(spelArithmetic.getModulo(), equalTo(7.0)); + assertThat(spelArithmetic.getModuloAlphabetic(), equalTo(7.0)); + assertThat(spelArithmetic.getPowerOf(), equalTo(512.0)); + assertThat(spelArithmetic.getBrackets(), equalTo(17.0)); } @Test public void testCollections() throws Exception { - Assert.assertThat(spelCollections.getDriver1Car().getModel(), equalTo("Model1")); - Assert.assertThat(spelCollections.getDriver2Car().getModel(), equalTo("Model2")); - Assert.assertThat(spelCollections.getFirstCarInPark().getModel(), equalTo("Model1")); - Assert.assertThat(spelCollections.getNumberOfCarsInPark(), equalTo(2)); + assertThat(spelCollections.getDriver1Car().getModel(), equalTo("Model1")); + assertThat(spelCollections.getDriver2Car().getModel(), equalTo("Model2")); + assertThat(spelCollections.getFirstCarInPark().getModel(), equalTo("Model1")); + assertThat(spelCollections.getNumberOfCarsInPark(), equalTo(2)); } @Test public void testConditional() throws Exception { - Assert.assertThat(spelConditional.getTernary(), equalTo("Something went wrong. There was false value")); - Assert.assertThat(spelConditional.getTernary2(), equalTo("Some model")); - Assert.assertThat(spelConditional.getElvis(), equalTo("Some model")); + assertThat(spelConditional.getTernary(), equalTo("Something went wrong. There was false value")); + assertThat(spelConditional.getTernary2(), equalTo("Some model")); + assertThat(spelConditional.getElvis(), equalTo("Some model")); } @Test public void testLogical() throws Exception { - Assert.assertThat(spelLogical.isAnd(), equalTo(true)); - Assert.assertThat(spelLogical.isAndAlphabetic(), equalTo(true)); - Assert.assertThat(spelLogical.isOr(), equalTo(true)); - Assert.assertThat(spelLogical.isOrAlphabetic(), equalTo(true)); - Assert.assertThat(spelLogical.isNot(), equalTo(false)); - Assert.assertThat(spelLogical.isNotAlphabetic(), equalTo(false)); + assertThat(spelLogical.isAnd(), equalTo(true)); + assertThat(spelLogical.isAndAlphabetic(), equalTo(true)); + assertThat(spelLogical.isOr(), equalTo(true)); + assertThat(spelLogical.isOrAlphabetic(), equalTo(true)); + assertThat(spelLogical.isNot(), equalTo(false)); + assertThat(spelLogical.isNotAlphabetic(), equalTo(false)); } @Test public void testRegex() throws Exception { - Assert.assertThat(spelRegex.isValidNumericStringResult(), equalTo(true)); - Assert.assertThat(spelRegex.isInvalidNumericStringResult(), equalTo(false)); - Assert.assertThat(spelRegex.isValidAlphabeticStringResult(), equalTo(true)); - Assert.assertThat(spelRegex.isInvalidAlphabeticStringResult(), equalTo(false)); - Assert.assertThat(spelRegex.isValidFormatOfHorsePower(), equalTo(true)); + assertThat(spelRegex.isValidNumericStringResult(), equalTo(true)); + assertThat(spelRegex.isInvalidNumericStringResult(), equalTo(false)); + assertThat(spelRegex.isValidAlphabeticStringResult(), equalTo(true)); + assertThat(spelRegex.isInvalidAlphabeticStringResult(), equalTo(false)); + assertThat(spelRegex.isValidFormatOfHorsePower(), equalTo(true)); } @Test public void testRelational() throws Exception { - Assert.assertThat(spelRelational.isEqual(), equalTo(true)); - Assert.assertThat(spelRelational.isEqualAlphabetic(), equalTo(true)); - Assert.assertThat(spelRelational.isNotEqual(), equalTo(false)); - Assert.assertThat(spelRelational.isNotEqualAlphabetic(), equalTo(false)); - Assert.assertThat(spelRelational.isLessThan(), equalTo(false)); - Assert.assertThat(spelRelational.isLessThanAlphabetic(), equalTo(false)); - Assert.assertThat(spelRelational.isLessThanOrEqual(), equalTo(true)); - Assert.assertThat(spelRelational.isLessThanOrEqualAlphabetic(), equalTo(true)); - Assert.assertThat(spelRelational.isGreaterThan(), equalTo(false)); - Assert.assertThat(spelRelational.isGreaterThanAlphabetic(), equalTo(false)); - Assert.assertThat(spelRelational.isGreaterThanOrEqual(), equalTo(true)); - Assert.assertThat(spelRelational.isGreaterThanOrEqualAlphabetic(), equalTo(true)); - Assert.assertThat(spelRelational.isAnd(), equalTo(true)); - Assert.assertThat(spelRelational.isAndAlphabetic(), equalTo(true)); - Assert.assertThat(spelRelational.isOr(), equalTo(true)); - Assert.assertThat(spelRelational.isOrAlphabetic(), equalTo(true)); - Assert.assertThat(spelRelational.isNot(), equalTo(false)); - Assert.assertThat(spelRelational.isNotAlphabetic(), equalTo(false)); + assertThat(spelRelational.isEqual(), equalTo(true)); + assertThat(spelRelational.isEqualAlphabetic(), equalTo(true)); + assertThat(spelRelational.isNotEqual(), equalTo(false)); + assertThat(spelRelational.isNotEqualAlphabetic(), equalTo(false)); + assertThat(spelRelational.isLessThan(), equalTo(false)); + assertThat(spelRelational.isLessThanAlphabetic(), equalTo(false)); + assertThat(spelRelational.isLessThanOrEqual(), equalTo(true)); + assertThat(spelRelational.isLessThanOrEqualAlphabetic(), equalTo(true)); + assertThat(spelRelational.isGreaterThan(), equalTo(false)); + assertThat(spelRelational.isGreaterThanAlphabetic(), equalTo(false)); + assertThat(spelRelational.isGreaterThanOrEqual(), equalTo(true)); + assertThat(spelRelational.isGreaterThanOrEqualAlphabetic(), equalTo(true)); + assertThat(spelRelational.isAnd(), equalTo(true)); + assertThat(spelRelational.isAndAlphabetic(), equalTo(true)); + assertThat(spelRelational.isOr(), equalTo(true)); + assertThat(spelRelational.isOrAlphabetic(), equalTo(true)); + assertThat(spelRelational.isNot(), equalTo(false)); + assertThat(spelRelational.isNotAlphabetic(), equalTo(false)); } }