RESOLVED - issue BATCH-259: FlatFileParsingException should include line number in its toString()

http://opensource.atlassian.com/projects/spring/browse/BATCH-259

Add missing unit test for exception
This commit is contained in:
dsyer
2007-12-18 17:38:03 +00:00
parent c3caf6e63a
commit d037885933
5 changed files with 44 additions and 47 deletions

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.io.exception;
import junit.framework.TestCase;
public abstract class AbstractBatchCriticalExceptionTests extends TestCase {
public void testExceptionString() throws Exception {
Exception exception = getException("foo");
assertEquals("foo", exception.getMessage());
}
public void testExceptionThrowable() throws Exception {
Exception exception = getException(new RuntimeException("foo"));
assertEquals("foo", exception.getCause().getMessage().substring(0, 3));
}
public void testExceptionStringThrowable() throws Exception {
Exception exception = getException("foo", new IllegalStateException());
assertEquals("foo", exception.getMessage().substring(0, 3));
}
public abstract Exception getException(String msg) throws Exception;
public abstract Exception getException(Throwable exception) throws Exception;
public abstract Exception getException(String msg, Throwable t) throws Exception;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.io.exception;
import org.springframework.batch.io.exception.BatchConfigurationException;
public class BatchConfigurationExceptionTests extends AbstractBatchCriticalExceptionTests {
public class BatchConfigurationExceptionTests extends AbstractExceptionTests {
public Exception getException(String msg) throws Exception {
return new BatchConfigurationException(msg);

View File

@@ -17,7 +17,7 @@
package org.springframework.batch.io.exception;
public class BatchCriticalExceptionTests extends AbstractBatchCriticalExceptionTests {
public class BatchCriticalExceptionTests extends AbstractExceptionTests {
public Exception getException(String msg) throws Exception {
return new BatchCriticalException(msg);

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.io.exception;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.io.exception.BatchEnvironmentException;
public class BatchEnvironmentExceptionTests extends AbstractBatchCriticalExceptionTests {
public class BatchEnvironmentExceptionTests extends AbstractExceptionTests {
public Exception getException(String msg) throws Exception {
return new BatchEnvironmentException(msg);

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.io.exception;
public class FlatFileParsingExceptionTests extends AbstractExceptionTests {
public Exception getException(String msg) throws Exception {
return new FlatFileParsingException(msg, "bar");
}
public Exception getException(Throwable t) throws Exception {
return new FlatFileParsingException(t, "bar");
}
public Exception getException(String msg, Throwable t) throws Exception {
return new FlatFileParsingException(msg, t, "bar", 100);
}
public void testMessageInputLineCount() throws Exception {
FlatFileParsingException exception = new FlatFileParsingException("foo", "bar", 100);
assertEquals("foo", exception.getMessage());
assertEquals("bar", exception.getInput());
assertEquals(100, exception.getLineNumber());
}
}