diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/BatchStatus.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/BatchStatus.java index 4df8cdf0d..aea63978e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/BatchStatus.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/BatchStatus.java @@ -18,8 +18,6 @@ package org.springframework.batch.core.domain; import java.io.Serializable; -import org.springframework.util.Assert; - /** * Typesafe enumeration representing the status of an artifact within the * batch environment. See Effective Java Programming by Joshua Bloch for more @@ -67,11 +65,13 @@ public class BatchStatus implements Serializable{ * Given a string representation of a status, return the appropriate BatchStatus. * * @param statusAsString: string representation of a status - * @return Valid BatchStatus + * @return a valid BatchStatus or null if the input is null * @throws IllegalArgumentException if no status matches provided string. */ public static BatchStatus getStatus(String statusAsString) { - Assert.notNull(statusAsString, "Cannot match null to valid status."); + if (statusAsString==null) { + return null; + } final String upperCaseStatusAsString = statusAsString.toUpperCase(); for (int i = 0; i < VALUES.length; i++) { if (VALUES[i].toString().equals(upperCaseStatusAsString)) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/BatchStatusTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/BatchStatusTests.java index 319280e0b..0041aa97d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/BatchStatusTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/BatchStatusTests.java @@ -24,62 +24,60 @@ import junit.framework.TestCase; /** * @author Dave Syer - * + * */ public class BatchStatusTests extends TestCase { /** - * Test method for {@link org.springframework.batch.core.domain.BatchStatus#toString()}. + * Test method for + * {@link org.springframework.batch.core.domain.BatchStatus#toString()}. */ public void testToString() { assertEquals("FAILED", BatchStatus.FAILED.toString()); } /** - * Test method for {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}. + * Test method for + * {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}. */ public void testGetStatus() { assertEquals(BatchStatus.FAILED, BatchStatus.getStatus(BatchStatus.FAILED.toString())); } /** - * Test method for {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}. + * Test method for + * {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}. */ public void testGetStatusWrongCode() { - try{ + try { BatchStatus.getStatus("foo"); fail(); } - catch(IllegalArgumentException ex){ - //expected + catch (IllegalArgumentException ex) { + // expected } } - + /** - * Test method for {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}. + * Test method for + * {@link org.springframework.batch.core.domain.BatchStatus#getStatus(java.lang.String)}. */ public void testGetStatusNullCode() { - try{ - BatchStatus.getStatus(null); - fail(); - } - catch(IllegalArgumentException ex){ - //expected - } + assertNull(BatchStatus.getStatus(null)); } - public void testSerialization() throws Exception{ - + public void testSerialization() throws Exception { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream (bout); + ObjectOutputStream out = new ObjectOutputStream(bout); - out.writeObject (BatchStatus.COMPLETED); - out.flush (); + out.writeObject(BatchStatus.COMPLETED); + out.flush(); - ByteArrayInputStream bin = new ByteArrayInputStream (bout.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bin); + ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bin); - BatchStatus status = (BatchStatus) in.readObject (); - assertEquals(BatchStatus.COMPLETED, status); + BatchStatus status = (BatchStatus) in.readObject(); + assertEquals(BatchStatus.COMPLETED, status); } }