IN PROGRESS - BATCH-672: modified remaining tests to use JUnit4.

This commit is contained in:
trisberg
2008-07-23 21:02:55 +00:00
parent 20fcba8b06
commit 67dfbbbc7a
19 changed files with 347 additions and 295 deletions

View File

@@ -29,7 +29,7 @@ import org.springframework.batch.item.support.DelegatingItemReader;
* @author Lucas Ward
*
*/
public class ExceptionThrowingItemReaderProxy extends DelegatingItemReader<Object> {
public class ExceptionThrowingItemReaderProxy<T> extends DelegatingItemReader<T> {
private int counter = 0;
private int throwExceptionOnRecordNumber = 4;
@@ -45,7 +45,7 @@ public class ExceptionThrowingItemReaderProxy extends DelegatingItemReader<Objec
return throwExceptionOnRecordNumber;
}
public Object read() throws Exception {
public T read() throws Exception {
counter++;
if (counter == throwExceptionOnRecordNumber) {

View File

@@ -76,9 +76,6 @@ public class OrderItemReader extends AbstractItemReader<Order> {
return result;
}
/**
* @see org.springframework.batch.execution.io.FieldSetCallback#execute(StepExecution)
*/
private void process(FieldSet fieldSet) {
// finish processing if we hit the end of file
if (fieldSet == null) {

View File

@@ -41,7 +41,7 @@ public class StagingItemReader<T> extends JdbcDaoSupport implements ItemStream,
private LobHandler lobHandler = new DefaultLobHandler();
private Object lock = new Object();
private final Object lock = new Object();
private volatile boolean initialized = false;
@@ -97,7 +97,7 @@ public class StagingItemReader<T> extends JdbcDaoSupport implements ItemStream,
new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Long(rs.getLong(1));
return rs.getLong(1);
}
}
@@ -142,7 +142,7 @@ public class StagingItemReader<T> extends JdbcDaoSupport implements ItemStream,
if (keys.hasNext()) {
Assert.state(TransactionSynchronizationManager.isActualTransactionActive(),
"Transaction not active for this thread.");
Long next = (Long) keys.next();
Long next = keys.next();
getBuffer().add(next);
key = next;
logger.debug("Retrieved key from list: " + key);
@@ -175,7 +175,7 @@ public class StagingItemReader<T> extends JdbcDaoSupport implements ItemStream,
public Long next() {
if (iter.hasNext()) {
return (Long) iter.next();
return iter.next();
}
return null;
}

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.sample.mapping;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.batch.item.file.mapping.FieldSet;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
@@ -10,7 +10,7 @@ import org.springframework.batch.item.file.mapping.FieldSetMapper;
*
* @author Robert Kasanicky
*/
public abstract class AbstractFieldSetMapperTests extends TestCase {
public abstract class AbstractFieldSetMapperTests {
/**
* @return <code>FieldSet</code> used for mapping
@@ -34,6 +34,7 @@ public abstract class AbstractFieldSetMapperTests extends TestCase {
* Regular usage scenario.
* Assumes the domain object implements sensible <code>equals(Object other)</code>
*/
@Test
public void testRegularUse() {
assertEquals(expectedDomainObject(), fieldSetMapper().mapLine(fieldSet(), -1));
}

View File

@@ -1,13 +1,14 @@
package org.springframework.batch.sample.mapping;
import java.math.BigDecimal;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.batch.item.file.mapping.DefaultFieldSet;
import org.springframework.batch.item.file.mapping.FieldSet;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.support.AggregateItemReader;
import org.springframework.batch.sample.domain.Trade;
import org.springframework.batch.sample.mapping.TradeFieldSetMapper;
import java.math.BigDecimal;
public class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests{
@@ -39,10 +40,12 @@ public class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests{
return new TradeFieldSetMapper();
}
@Test
public void testBeginRecord() throws Exception {
assertEquals(AggregateItemReader.BEGIN_RECORD, fieldSetMapper().mapLine(new DefaultFieldSet(new String[] {"BEGIN"}), -1));
}
@Test
public void testEndRecord() throws Exception {
assertEquals(AggregateItemReader.END_RECORD, fieldSetMapper().mapLine(new DefaultFieldSet(new String[] {"END"}), -1));
}

View File

@@ -15,14 +15,11 @@
*/
package org.springframework.batch.sample.quartz;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.easymock.EasyMock.createNiceMock;
import static org.junit.Assert.assertEquals;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.junit.Before;
import org.junit.Test;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
@@ -38,11 +35,16 @@ import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.repository.NoSuchJobException;
import org.springframework.batch.sample.tasklet.JobSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author Dave Syer
*
*/
public class JobLauncherDetailsTests extends TestCase {
public class JobLauncherDetailsTests {
private JobLauncherDetails details = new JobLauncherDetails();
@@ -50,7 +52,8 @@ public class JobLauncherDetailsTests extends TestCase {
private List<Serializable> list = new ArrayList<Serializable>();
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
details.setJobLauncher(new JobLauncher() {
public JobExecution run(org.springframework.batch.core.Job job, JobParameters jobParameters)
throws JobExecutionAlreadyRunningException, JobRestartException {
@@ -66,10 +69,6 @@ public class JobLauncherDetailsTests extends TestCase {
});
}
/**
* @return
*
*/
private JobExecutionContext createContext(JobDetail jobDetail) {
firedBundle = new TriggerFiredBundle(jobDetail, new SimpleTrigger(), null, false, new Date(), new Date(), new Date(), new Date());
return new StubJobExecutionContext();
@@ -79,6 +78,7 @@ public class JobLauncherDetailsTests extends TestCase {
* Test method for
* {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}.
*/
@Test
public void testExecuteWithNoJobParameters() {
JobDetail jobDetail = new JobDetail();
JobExecutionContext context = createContext(jobDetail);
@@ -92,6 +92,7 @@ public class JobLauncherDetailsTests extends TestCase {
* Test method for
* {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}.
*/
@Test
public void testExecuteWithJobName() {
JobDetail jobDetail = new JobDetail();
jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO");
@@ -105,6 +106,7 @@ public class JobLauncherDetailsTests extends TestCase {
* Test method for
* {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}.
*/
@Test
public void testExecuteWithSomeJobParameters() {
JobDetail jobDetail = new JobDetail();
jobDetail.getJobDataMap().put("foo", "bar");
@@ -119,6 +121,7 @@ public class JobLauncherDetailsTests extends TestCase {
* Test method for
* {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}.
*/
@Test
public void testExecuteWithJobNameAndParameters() {
JobDetail jobDetail = new JobDetail();
jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO");
@@ -135,6 +138,7 @@ public class JobLauncherDetailsTests extends TestCase {
* Test method for
* {@link org.springframework.batch.sample.quartz.JobLauncherDetails#executeInternal(org.quartz.JobExecutionContext)}.
*/
@Test
public void testExecuteWithJobNameAndComplexParameters() {
JobDetail jobDetail = new JobDetail();
jobDetail.getJobDataMap().put(JobLauncherDetails.JOB_NAME, "FOO");
@@ -149,15 +153,11 @@ public class JobLauncherDetailsTests extends TestCase {
}
private final class StubJobExecutionContext extends JobExecutionContext {
/**
* @param scheduler
* @param firedBundle
* @param job
*/
private StubJobExecutionContext() {
super((Scheduler) MockControl.createNiceControl(Scheduler.class).getMock(), firedBundle, (Job) MockControl.createNiceControl(Job.class)
.getMock());
super(createNiceMock(Scheduler.class), firedBundle, createNiceMock(Job.class));
}
}
}

View File

@@ -1,29 +1,31 @@
package org.springframework.batch.sample.tasklet;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.springframework.batch.repeat.ExitStatus;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.springframework.batch.repeat.ExitStatus;
/**
* Tests for {@link ConfigurableSystemProcessExitCodeMapper}
*/
public class ConfigurableSystemProcessExitCodeMapperTests extends TestCase {
public class ConfigurableSystemProcessExitCodeMapperTests {
private ConfigurableSystemProcessExitCodeMapper mapper = new ConfigurableSystemProcessExitCodeMapper();
/**
* Regular usage scenario - mapping adheres to injected values
*/
@Test
public void testMapping() {
Map<Object, ExitStatus> mappings = new HashMap<Object, ExitStatus>() {{
put(new Integer(0), ExitStatus.FINISHED);
put(new Integer(1), ExitStatus.FAILED);
put(new Integer(2), ExitStatus.CONTINUABLE);
put(new Integer(3), ExitStatus.NOOP);
put(new Integer(4), ExitStatus.UNKNOWN);
put(0, ExitStatus.FINISHED);
put(1, ExitStatus.FAILED);
put(2, ExitStatus.CONTINUABLE);
put(3, ExitStatus.NOOP);
put(4, ExitStatus.UNKNOWN);
put(ConfigurableSystemProcessExitCodeMapper.ELSE_KEY, ExitStatus.UNKNOWN);
}};
@@ -33,7 +35,7 @@ public class ConfigurableSystemProcessExitCodeMapperTests extends TestCase {
for (Map.Entry<Object, ExitStatus> entry : mappings.entrySet()) {
if (entry.getKey().equals(ConfigurableSystemProcessExitCodeMapper.ELSE_KEY)) continue;
int exitCode = ((Integer)entry.getKey()).intValue();
int exitCode = (Integer) entry.getKey();
assertSame(entry.getValue(), mapper.getExitStatus(exitCode));
}
@@ -45,6 +47,7 @@ public class ConfigurableSystemProcessExitCodeMapperTests extends TestCase {
/**
* Else clause is required in the injected map - setter checks its presence.
*/
@Test
public void testSetMappingsMissingElseClause() {
Map<Object, ExitStatus> missingElse = new HashMap<Object, ExitStatus>();
try {

View File

@@ -1,29 +1,33 @@
package org.springframework.batch.sample.tasklet;
import java.util.ArrayList;
import static org.junit.Assert.*;
import junit.framework.TestCase;
import java.util.ArrayList;
import org.springframework.batch.core.UnexpectedJobExecutionException;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.batch.repeat.context.RepeatContextSupport;
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
import org.springframework.batch.sample.item.reader.ExceptionThrowingItemReaderProxy;
import org.junit.After;
import org.junit.Test;
public class ExceptionThrowingItemReaderProxyTests extends TestCase {
public class ExceptionThrowingItemReaderProxyTests {
//expected call count before exception is thrown (exception should be thrown in next iteration)
private static final int ITER_COUNT = 5;
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
RepeatSynchronizationManager.clear();
}
@Test
public void testProcess() throws Exception {
//create module and set item processor and iteration count
ExceptionThrowingItemReaderProxy itemReader = new ExceptionThrowingItemReaderProxy();
itemReader.setItemReader(new ListItemReader(new ArrayList<String>() {{
ExceptionThrowingItemReaderProxy<String> itemReader = new ExceptionThrowingItemReaderProxy<String>();
itemReader.setItemReader(new ListItemReader<String>(new ArrayList<String>() {{
add("a");
add("b");
add("c");

View File

@@ -1,14 +1,14 @@
package org.springframework.batch.sample.tasklet;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.sample.tasklet.SimpleSystemProcessExitCodeMapper;
/**
* Tests for {@link SimpleSystemProcessExitCodeMapper}.
*/
public class SimpleSystemProcessExitCodeMapperTests extends TestCase {
public class SimpleSystemProcessExitCodeMapperTests {
private SimpleSystemProcessExitCodeMapper mapper = new SimpleSystemProcessExitCodeMapper();
@@ -16,6 +16,7 @@ public class SimpleSystemProcessExitCodeMapperTests extends TestCase {
* 0 -> ExitStatus.FINISHED
* else -> ExitStatus.FAILED
*/
@Test
public void testMapping() {
assertEquals(ExitStatus.FINISHED, mapper.getExitStatus(0));
assertEquals(ExitStatus.FAILED, mapper.getExitStatus(1));

View File

@@ -1,35 +1,34 @@
package org.springframework.batch.sample.tasklet;
import java.io.File;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.sample.tasklet.SystemCommandException;
import org.springframework.batch.sample.tasklet.SystemCommandTasklet;
import org.springframework.batch.sample.tasklet.SystemProcessExitCodeMapper;
import org.springframework.util.Assert;
import java.io.File;
/**
* Tests for {@link SystemCommandTasklet}.
*/
public class SystemCommandTaskletIntegrationTests extends TestCase {
public class SystemCommandTaskletIntegrationTests {
private static final Log log = LogFactory.getLog(SystemCommandTaskletIntegrationTests.class);
private SystemCommandTasklet tasklet = new SystemCommandTasklet();
private StepExecution stepExecution = new StepExecution("systemCommandStep", new JobExecution(new JobInstance(
new Long(1), new JobParameters(), "systemCommandJob")));
1L, new JobParameters(), "systemCommandJob")));
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
tasklet.setEnvironmentParams(null); // inherit from parent process
tasklet.setWorkingDirectory(null); // inherit from parent process
tasklet.setSystemProcessExitCodeMapper(new TestExitCodeMapper());
@@ -41,9 +40,10 @@ public class SystemCommandTaskletIntegrationTests extends TestCase {
tasklet.beforeStep(stepExecution);
}
/**
/*
* Regular usage scenario - successful execution of system command.
*/
@Test
public void testExecute() throws Exception {
String command = "java -version";
tasklet.setCommand(command);
@@ -55,9 +55,10 @@ public class SystemCommandTaskletIntegrationTests extends TestCase {
assertEquals(ExitStatus.FINISHED, exitStatus);
}
/**
/*
* Failed execution scenario - error exit code returned by system command.
*/
@Test
public void testExecuteFailure() throws Exception {
String command = "java org.springframework.batch.sample.tasklet.UnknownClass";
tasklet.setCommand(command);
@@ -69,9 +70,10 @@ public class SystemCommandTaskletIntegrationTests extends TestCase {
assertEquals(ExitStatus.FAILED, exitStatus);
}
/**
/*
* Failed execution scenario - execution time exceeds timeout.
*/
@Test
public void testExecuteTimeout() throws Exception {
String command = "sleep 3";
tasklet.setCommand(command);
@@ -88,9 +90,10 @@ public class SystemCommandTaskletIntegrationTests extends TestCase {
}
}
/**
/*
* Job interrupted scenario.
*/
@Test
public void testInterruption() throws Exception {
String command = "sleep 5";
tasklet.setCommand(command);
@@ -109,9 +112,10 @@ public class SystemCommandTaskletIntegrationTests extends TestCase {
}
}
/**
/*
* Command property value is required to be set.
*/
@Test
public void testCommandNotSet() throws Exception {
tasklet.setCommand(null);
try {
@@ -132,9 +136,10 @@ public class SystemCommandTaskletIntegrationTests extends TestCase {
}
}
/**
/*
* Timeout must be set to non-zero value.
*/
@Test
public void testTimeoutNotSet() throws Exception {
tasklet.setCommand("not-empty placeholder");
tasklet.setTimeout(0);
@@ -147,10 +152,11 @@ public class SystemCommandTaskletIntegrationTests extends TestCase {
}
}
/**
/*
* Working directory property must point to an existing location and it must
* be a directory
*/
@Test
public void testWorkingDirectory() throws Exception {
File notExistingFile = new File("not-existing-path");
Assert.state(!notExistingFile.exists());

View File

@@ -1,31 +1,34 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springmodules.validation.valang.functions.Function;
import java.util.Date;
import org.easymock.MockControl;
import org.springmodules.validation.valang.functions.Function;
import junit.framework.TestCase;
public class FutureDateFunctionTests extends TestCase {
public class FutureDateFunctionTests {
private FutureDateFunction function;
private MockControl argumentControl;
private Function argument;
@Before
public void setUp() {
argumentControl = MockControl.createControl(Function.class);
argument = (Function) argumentControl.getMock();
argument = createMock(Function.class);
//create function
function = new FutureDateFunction(new Function[] {argument}, 0, 0);
}
@Test
public void testFunctionWithNonDateValue() {
//set-up mock argument - set return value to non Date value
argument.getResult(null);
argumentControl.setReturnValue(this);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(this);
replay(argument);
//call tested method - exception is expected because non date value
try {
@@ -34,28 +37,31 @@ public class FutureDateFunctionTests extends TestCase {
} catch (Exception e) {
assertTrue(true);
}
}
@Test
public void testFunctionWithFutureDate() throws Exception {
//set-up mock argument - set return value to future Date
argument.getResult(null);
argumentControl.setReturnValue(new Date(Long.MAX_VALUE));
argumentControl.replay();
expect(argument.getResult(null)).andReturn(new Date(Long.MAX_VALUE));
replay(argument);
//vefify result - should be true because of future date
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
}
@Test
public void testFunctionWithPastDate() throws Exception {
//set-up mock argument - set return value to future Date
argument.getResult(null);
argumentControl.setReturnValue(new Date(0));
argumentControl.replay();
expect(argument.getResult(null)).andReturn(new Date(0));
replay(argument);
//vefify result - should be false because of past date
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}

View File

@@ -1,42 +1,40 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
import org.easymock.MockControl;
import org.springmodules.validation.valang.functions.Function;
import junit.framework.TestCase;
public class TotalOrderItemsFunctionTests extends TestCase {
public class TotalOrderItemsFunctionTests {
private TotalOrderItemsFunction function;
private MockControl argument1Control;
private Function argument1;
private MockControl argument2Control;
private Function argument2;
@Before
public void setUp() {
//create mock for first argument - set count to 3
argument1Control = MockControl.createControl(Function.class);
argument1 = (Function) argument1Control.getMock();
argument1.getResult(null);
argument1Control.setReturnValue(new Integer(3));
argument1Control.replay();
Function argument1 = createMock(Function.class);
expect(argument1.getResult(null)).andReturn(3);
replay(argument1);
argument2Control = MockControl.createControl(Function.class);
argument2 = (Function) argument2Control.getMock();
argument2 = createMock(Function.class);
//create function
function = new TotalOrderItemsFunction(new Function[] {argument1, argument2}, 0, 0);
}
@Test
public void testFunctionWithNonListValue() {
argument2.getResult(null);
argument2Control.setReturnValue(this);
argument2Control.replay();
expect(argument2.getResult(null)).andReturn(this);
replay(argument2);
//call tested method - exception is expected because non list value
try {
@@ -45,8 +43,10 @@ public class TotalOrderItemsFunctionTests extends TestCase {
} catch (Exception e) {
assertTrue(true);
}
}
@Test
public void testFunctionWithCorrectItemCount() throws Exception {
//create list with correct item count
@@ -55,14 +55,15 @@ public class TotalOrderItemsFunctionTests extends TestCase {
List<LineItem> list = new ArrayList<LineItem>();
list.add(item);
argument2.getResult(null);
argument2Control.setReturnValue(list);
argument2Control.replay();
expect(argument2.getResult(null)).andReturn(list);
replay(argument2);
//vefify result
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
}
@Test
public void testFunctionWithIncorrectItemCount() throws Exception {
//create list with incorrect item count
@@ -71,12 +72,12 @@ public class TotalOrderItemsFunctionTests extends TestCase {
List<LineItem> list = new ArrayList<LineItem>();
list.add(item);
argument2.getResult(null);
argument2Control.setReturnValue(list);
argument2Control.replay();
expect(argument2.getResult(null)).andReturn(list);
replay(argument2);
//vefify result
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}

View File

@@ -1,29 +1,33 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.sample.domain.LineItem;
import org.easymock.MockControl;
import org.springmodules.validation.valang.functions.Function;
import junit.framework.TestCase;
public class ValidateDiscountsFunctionTests extends TestCase {
public class ValidateDiscountsFunctionTests {
private ValidateDiscountsFunction function;
private MockControl argumentControl;
private Function argument;
@Before
public void setUp() {
argumentControl = MockControl.createControl(Function.class);
argument = (Function) argumentControl.getMock();
argument = createMock(Function.class);
//create function
function = new ValidateDiscountsFunction(new Function[] {argument}, 0, 0);
}
@Test
public void testDiscountPercentageMin() throws Exception {
//create line item with correct discount percentage and zero discount amount
@@ -36,12 +40,11 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all discount percentages are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with negative percentage
item = new LineItem();
@@ -50,9 +53,11 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid discount percentage
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testDiscountPercentageMax() throws Exception {
//create line item with correct discount percentage and zero discount amount
@@ -65,12 +70,11 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all discount percentages are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with discount percentage above 100
item = new LineItem();
@@ -79,9 +83,11 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid discount percentage
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testDiscountPriceMin() throws Exception {
//create line item with correct discount amount and zero discount percentage
@@ -95,12 +101,11 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all discount amounts are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with negative discount amount
item = new LineItem();
@@ -110,9 +115,11 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid discount amount
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testDiscountPriceMax() throws Exception {
//create line item with correct discount amount and zero discount percentage
@@ -126,12 +133,11 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all discount amounts are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with discount amount above item price
item = new LineItem();
@@ -141,9 +147,11 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid discount amount
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testBothDiscountValuesNonZero() throws Exception {
//create line item with non-zero discount amount and non-zero discount percentage
@@ -156,11 +164,12 @@ public class ValidateDiscountsFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items);
replay(argument);
//verify result - should be false - only one of the discount values is empty
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}

View File

@@ -1,30 +1,34 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.easymock.MockControl;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import junit.framework.TestCase;
public class ValidateHandlingPricesFunctionTests extends TestCase {
public class ValidateHandlingPricesFunctionTests {
private ValidateHandlingPricesFunction function;
private MockControl argumentControl;
private Function argument;
@Before
public void setUp() {
argumentControl = MockControl.createControl(Function.class);
argument = (Function) argumentControl.getMock();
argument = createMock(Function.class);
//create function
function = new ValidateHandlingPricesFunction(new Function[] {argument}, 0, 0);
}
@Test
public void testHandlingPriceMin() throws Exception {
//create line item with correct handling price
@@ -36,12 +40,11 @@ public class ValidateHandlingPricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all handling prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with negative handling price
item = new LineItem();
@@ -49,9 +52,11 @@ public class ValidateHandlingPricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid handling price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testHandlingPriceMax() throws Exception {
//create line item with correct handling price
@@ -63,12 +68,11 @@ public class ValidateHandlingPricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all handling prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with handling price above allowed max
item = new LineItem();
@@ -76,6 +80,8 @@ public class ValidateHandlingPricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid handling price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}

View File

@@ -1,29 +1,30 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
public class ValidateIdsFunctionTests extends TestCase {
public class ValidateIdsFunctionTests {
private ValidateIdsFunction function;
private MockControl argumentControl;
private Function argument;
@Before
public void setUp() {
argumentControl = MockControl.createControl(Function.class);
argument = (Function) argumentControl.getMock();
argument = createMock(Function.class);
//create function
function = new ValidateIdsFunction(new Function[] {argument}, 0, 0);
}
@Test
public void testIdMin() throws Exception {
//create line item with correct item id
@@ -35,12 +36,11 @@ public class ValidateIdsFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all ids are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with negative id
item = new LineItem();
@@ -48,9 +48,11 @@ public class ValidateIdsFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid id
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testIdMax() throws Exception {
//create line item with correct item id
@@ -62,12 +64,11 @@ public class ValidateIdsFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all item ids are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with item id above allowed max
item = new LineItem();
@@ -75,6 +76,8 @@ public class ValidateIdsFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid item id
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}

View File

@@ -1,30 +1,33 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.easymock.MockControl;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import junit.framework.TestCase;
public class ValidatePricesFunctionTests extends TestCase {
public class ValidatePricesFunctionTests {
private ValidatePricesFunction function;
private MockControl argumentControl;
private Function argument;
@Before
public void setUp() {
argumentControl = MockControl.createControl(Function.class);
argument = (Function) argumentControl.getMock();
argument = createMock(Function.class);
//create function
function = new ValidatePricesFunction(new Function[] {argument}, 0, 0);
}
@Test
public void testItemPriceMin() throws Exception {
//create line item with correct item price
@@ -36,12 +39,11 @@ public class ValidatePricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all item prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with negative item price
item = new LineItem();
@@ -49,9 +51,10 @@ public class ValidatePricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid item price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testItemPriceMax() throws Exception {
//create line item with correct item price
@@ -63,12 +66,11 @@ public class ValidatePricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all item prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with item price above allowed max
item = new LineItem();
@@ -76,7 +78,7 @@ public class ValidatePricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid item price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}

View File

@@ -1,29 +1,32 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import java.util.ArrayList;
import java.util.List;
import org.easymock.MockControl;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import junit.framework.TestCase;
public class ValidateQuantitiesFunctionTests extends TestCase {
public class ValidateQuantitiesFunctionTests {
private ValidateQuantitiesFunction function;
private MockControl argumentControl;
private Function argument;
@Before
public void setUp() {
argumentControl = MockControl.createControl(Function.class);
argument = (Function) argumentControl.getMock();
argument = createMock(Function.class);
//create function
function = new ValidateQuantitiesFunction(new Function[] {argument}, 0, 0);
}
@Test
public void testQuantityMin() throws Exception {
//create line item with correct item quantity
@@ -35,12 +38,11 @@ public class ValidateQuantitiesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all quantities are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with negative quantity
item = new LineItem();
@@ -48,9 +50,10 @@ public class ValidateQuantitiesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid quantity
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testQuantityMax() throws Exception {
//create line item with correct item quantity
@@ -62,12 +65,11 @@ public class ValidateQuantitiesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all item quantities are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with item quantity above allowed max
item = new LineItem();
@@ -75,6 +77,6 @@ public class ValidateQuantitiesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid item quantity
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}

View File

@@ -1,30 +1,33 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.easymock.MockControl;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import junit.framework.TestCase;
public class ValidateShippingPricesFunctionTests extends TestCase {
public class ValidateShippingPricesFunctionTests {
private ValidateShippingPricesFunction function;
private MockControl argumentControl;
private Function argument;
@Before
public void setUp() {
argumentControl = MockControl.createControl(Function.class);
argument = (Function) argumentControl.getMock();
argument = createMock(Function.class);
//create function
function = new ValidateShippingPricesFunction(new Function[] {argument}, 0, 0);
}
@Test
public void testShippingPriceMin() throws Exception {
//create line item with correct shipping price
@@ -36,12 +39,11 @@ public class ValidateShippingPricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all shipping prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with negative shipping price
item = new LineItem();
@@ -49,9 +51,11 @@ public class ValidateShippingPricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid shipping price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testShippingPriceMax() throws Exception {
//create line item with correct shipping price
@@ -63,12 +67,11 @@ public class ValidateShippingPricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all shipping prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with shipping price above allowed max
item = new LineItem();
@@ -76,6 +79,7 @@ public class ValidateShippingPricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid shipping price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}

View File

@@ -1,30 +1,32 @@
package org.springframework.batch.sample.validation.valang.custom;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.easymock.MockControl;
import org.springframework.batch.sample.domain.LineItem;
import org.springmodules.validation.valang.functions.Function;
import junit.framework.TestCase;
public class ValidateTotalPricesFunctionTests extends TestCase {
public class ValidateTotalPricesFunctionTests {
private ValidateTotalPricesFunction function;
private MockControl argumentControl;
private Function argument;
@Before
public void setUp() {
argumentControl = MockControl.createControl(Function.class);
argument = (Function) argumentControl.getMock();
argument = createMock(Function.class);
//create function
function = new ValidateTotalPricesFunction(new Function[] {argument}, 0, 0);
}
@Test
public void testTotalPriceMin() throws Exception {
//create line item with correct total price
@@ -42,12 +44,11 @@ public class ValidateTotalPricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all total prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertTrue((Boolean) function.doGetResult(null));
//now add line item with negative item price
item = new LineItem();
@@ -55,9 +56,10 @@ public class ValidateTotalPricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid total price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testTotalPriceMax() throws Exception {
//create line item with correct total price
@@ -75,12 +77,11 @@ public class ValidateTotalPricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all total prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertEquals(true, function.doGetResult(null));
//now add line item with total price above allowed max
item = new LineItem();
@@ -88,9 +89,11 @@ public class ValidateTotalPricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has invalid total price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
@Test
public void testTotalPriceCalculation() throws Exception {
//create line item
@@ -108,12 +111,11 @@ public class ValidateTotalPricesFunctionTests extends TestCase {
items.add(item);
//set return value for mock argument
argument.getResult(null);
argumentControl.setReturnValue(items,2);
argumentControl.replay();
expect(argument.getResult(null)).andReturn(items).times(2);
replay(argument);
//verify result - should be true - all total prices are correct
assertTrue(((Boolean)function.doGetResult(null)).booleanValue());
assertEquals(true, function.doGetResult(null));
//now add line item with incorrect total price
item = new LineItem();
@@ -128,6 +130,8 @@ public class ValidateTotalPricesFunctionTests extends TestCase {
items.add(item);
//verify result - should be false - second item has incorrect total price
assertFalse(((Boolean)function.doGetResult(null)).booleanValue());
assertFalse((Boolean) function.doGetResult(null));
}
}