From 9092b47fcebf9aed546ea872c111501eec51fedb Mon Sep 17 00:00:00 2001 From: dhgarrette Date: Wed, 8 Apr 2009 14:33:54 +0000 Subject: [PATCH] Updated to remove warnings. --- .../item/validator/SpringValidatorTests.java | 52 +++++--------- spring-batch-test/.springBeans | 71 +++++++++++-------- .../jmx/SimpleMessageApplicationEvent.java | 1 + 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java index 0d881ef94..cc08fb105 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java @@ -16,21 +16,25 @@ package org.springframework.batch.item.validator; -import junit.framework.TestCase; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.Test; import org.springframework.validation.Errors; import org.springframework.validation.Validator; /** * Tests for {@link SpringValidator}. */ -public class SpringValidatorTests extends TestCase { +public class SpringValidatorTests { - SpringValidator validator = new SpringValidator(); + private SpringValidator validator = new SpringValidator(); - Validator mockValidator; + private Validator mockValidator; - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { mockValidator = new MockSpringValidator(); validator.setValidator(mockValidator); } @@ -38,64 +42,47 @@ public class SpringValidatorTests extends TestCase { /** * Validator property is not set */ + @Test(expected = IllegalArgumentException.class) public void testNullValidator() throws Exception { - validator.setValidator(null); - - try { - validator.afterPropertiesSet(); - fail("null validator must cause exception"); - } - catch (IllegalArgumentException e) { - // expected - } + validator.afterPropertiesSet(); } /** * Validator does not know how to validate object of the given class */ + @Test(expected = ValidationException.class) public void testValidateUnsupportedType() { - try { - validator.validate(Integer.valueOf(1)); // only strings are supported - fail("must not validate unsupported classes"); - } - catch (ValidationException expected) { - assertTrue(true); - } + validator.validate(Integer.valueOf(1)); // only strings are supported } /** * Typical successful validation - no exception is thrown. */ + @Test public void testValidateSuccessfully() { validator.validate(MockSpringValidator.ACCEPT_VALUE); - assertTrue(true); } /** * Typical failed validation - {@link ValidationException} is thrown */ + @Test(expected = ValidationException.class) public void testValidateFailure() { - try { - validator.validate(MockSpringValidator.REJECT_VALUE); - fail("exception should have been thrown on invalid value"); - } - catch (ValidationException e) { - // expected - } + validator.validate(MockSpringValidator.REJECT_VALUE); } /** * Typical failed validation - message contains the item and names of * invalid fields. */ + @Test public void testValidateFailureWithFields() { try { validator.validate(MockSpringValidator.REJECT_MULTI_VALUE); fail("exception should have been thrown on invalid value"); } catch (ValidationException expected) { -// System.out.println(expected.getMessage()); assertTrue("message should contain the item#toString() value", expected.getMessage().contains( "TestBeanToString")); assertTrue("message should contain names of the invalid fields", expected.getMessage().contains("foo")); @@ -103,7 +90,7 @@ public class SpringValidatorTests extends TestCase { } } - static class MockSpringValidator implements Validator { + private static class MockSpringValidator implements Validator { public static final TestBean ACCEPT_VALUE = new TestBean(); public static final TestBean REJECT_VALUE = new TestBean(); @@ -132,7 +119,7 @@ public class SpringValidatorTests extends TestCase { } } - static class TestBean { + private static class TestBean { private String foo; private String bar; @@ -158,6 +145,5 @@ public class SpringValidatorTests extends TestCase { public String toString() { return "TestBeanToString"; } - } } diff --git a/spring-batch-test/.springBeans b/spring-batch-test/.springBeans index 767d5a4d1..f818c21fd 100644 --- a/spring-batch-test/.springBeans +++ b/spring-batch-test/.springBeans @@ -1,29 +1,42 @@ - - - 1 - - - - - - - src/test/resources/data-source-context.xml - src/test/resources/simple-job-launcher-context.xml - src/test/resources/org/springframework/batch/sample/config/common-context.xml - src/test/resources/jobs/sampleFlowJob.xml - src/test/resources/jobs/sampleSimpleJob.xml - src/test/resources/jobs/sample-steps.xml - - - - - true - false - - src/test/resources/data-source-context.xml - src/test/resources/org/springframework/batch/sample/config/common-context.xml - src/test/resources/simple-job-launcher-context.xml - - - - + + + 1 + + + + + + + src/test/resources/data-source-context.xml + src/test/resources/simple-job-launcher-context.xml + src/test/resources/org/springframework/batch/sample/config/common-context.xml + src/test/resources/jobs/sampleFlowJob.xml + src/test/resources/jobs/sampleSimpleJob.xml + src/test/resources/jobs/sample-steps.xml + + + + + true + false + + src/test/resources/data-source-context.xml + src/test/resources/org/springframework/batch/sample/config/common-context.xml + src/test/resources/simple-job-launcher-context.xml + src/test/resources/jobs/sampleSimpleJob.xml + src/test/resources/jobs/sample-steps.xml + + + + + true + false + + src/test/resources/data-source-context.xml + src/test/resources/jobs/sampleFlowJob.xml + src/test/resources/org/springframework/batch/sample/config/common-context.xml + src/test/resources/simple-job-launcher-context.xml + + + + diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/jmx/SimpleMessageApplicationEvent.java b/spring-batch-test/src/test/java/org/springframework/batch/test/jmx/SimpleMessageApplicationEvent.java index ba1a9ea64..a5a239368 100755 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/jmx/SimpleMessageApplicationEvent.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/jmx/SimpleMessageApplicationEvent.java @@ -6,6 +6,7 @@ import org.springframework.context.ApplicationEvent; * @author Dave Syer * */ +@SuppressWarnings("serial") public class SimpleMessageApplicationEvent extends ApplicationEvent { private String message;