Send test coverage in core up to the high 90s.

This commit is contained in:
dsyer
2008-01-30 08:02:29 +00:00
parent 1cf29b8241
commit 152829ba5f
18 changed files with 472 additions and 159 deletions

View File

@@ -98,7 +98,7 @@ public class Entity implements Serializable {
}
Entity entity = (Entity) other;
if (id == null || entity.getId() == null) {
return entity == this;
return false;
}
return id.equals(entity.getId());
}

View File

@@ -51,14 +51,13 @@ public class JobExecution extends Entity {
* Because a JobExecution isn't valid unless the job is set, this
* constructor is the only valid one from a modelling point of view.
*
* @param job
* the job of which this execution is a part
* @param job the job of which this execution is a part
*/
public JobExecution(JobInstance job, Long id) {
super(id);
this.jobInstance = job;
}
/**
* Constructor for transient (unsaved) instances.
*
@@ -145,34 +144,33 @@ public class JobExecution extends Entity {
this.stepExecutions.add(stepExecution);
return stepExecution;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.batch.core.domain.Entity#toString()
*/
public String toString() {
return super.toString()+", startTime="+startTime+", endTime="+endTime+", job=["+jobInstance+"]";
return super.toString() + ", startTime=" + startTime + ", endTime=" + endTime + ", job=[" + jobInstance + "]";
}
/**
* Test if this {@link JobExecution} indicates that it is running. It should
* be noted that this does not necessarily mean that it has been
* persisted as such yet.
* Test if this {@link JobExecution} indicates that it is running. It should
* be noted that this does not necessarily mean that it has been persisted
* as such yet.
* @return true if the end time is null
*/
public boolean isRunning() {
return endTime==null;
return endTime == null;
}
/**
* Stop the JobExecution, each StepExecution will be iterated through, calling
* setTermianteOnly, signaling to the StepExecutor currently running that it should
* be terminated.
* Signal the {@link JobExecution} to stop. Iterates through the associated
* {@link StepExecution}s, calling {@link StepExecution#setTerminateOnly()}.
*
*/
public void stop(){
for(Iterator it = stepExecutions.iterator();it.hasNext();){
StepExecution stepExecution = (StepExecution)it.next();
public void stop() {
for (Iterator it = stepExecutions.iterator(); it.hasNext();) {
StepExecution stepExecution = (StepExecution) it.next();
stepExecution.setTerminateOnly();
}
}

View File

@@ -196,7 +196,6 @@ public class JobParameters {
}
public int hashCode() {
return new HashCodeBuilder(7, 21).
append(stringMap).
append(longMap).

View File

@@ -139,6 +139,6 @@ public class JobSupport implements BeanNameAware, Job {
}
public String toString() {
return ClassUtils.getShortName(JobSupport.class) + ": [name=" + name + "]";
return ClassUtils.getShortName(getClass()) + ": [name=" + name + "]";
}
}

View File

@@ -169,7 +169,7 @@ public class StepExecution extends Entity {
public boolean equals(Object obj) {
Object stepId = getStepId();
Object jobExecutionId = getJobExecutionId();
if (stepId == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() != null) {
if (stepId == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) {
return super.equals(obj);
}
StepExecution other = (StepExecution) obj;

View File

@@ -57,6 +57,15 @@ public class EntityTests extends TestCase {
assertEquals(new Integer(0), entity.getVersion());
}
/**
* Test method for {@link org.springframework.batch.core.domain.Entity#getVersion()}.
*/
public void testIncrementVersionTwice() {
entity.incrementVersion();
entity.incrementVersion();
assertEquals(new Integer(1), entity.getVersion());
}
/**
* @throws Exception
*/

View File

@@ -27,9 +27,7 @@ import org.springframework.batch.repeat.ExitStatus;
*/
public class JobExecutionTests extends TestCase {
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters()), new Long(12));
private JobExecution context = new JobExecution(new JobInstance(new Long(11), new JobParameters(), new JobSupport("foo")), new Long(12));
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), new JobSupport("foo")), new Long(12));
/**
* Test method for
@@ -117,23 +115,30 @@ public class JobExecutionTests extends TestCase {
}
public void testContextContainsInfo() throws Exception {
assertEquals("foo", context.getJobInstance().getJobName());
assertEquals("foo", execution.getJobInstance().getJobName());
}
public void testAddAndRemoveStepExecution() throws Exception {
assertEquals(0, context.getStepExecutions().size());
context.createStepExecution(new StepInstance(null, null));
assertEquals(1, context.getStepExecutions().size());
assertEquals(0, execution.getStepExecutions().size());
execution.createStepExecution(new StepInstance(null, null));
assertEquals(1, execution.getStepExecutions().size());
}
public void testStop() throws Exception {
StepExecution stepExecution = execution.createStepExecution(null);
assertFalse(stepExecution.isTerminateOnly());
execution.stop();
assertTrue(stepExecution.isTerminateOnly());
}
public void testToString() throws Exception {
assertTrue("JobExecution string does not contain id", context.toString().indexOf("id=") >= 0);
assertTrue("JobExecution string does not contain name: " + context, context.toString().indexOf("foo") >= 0);
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
assertTrue("JobExecution string does not contain name: " + execution, execution.toString().indexOf("foo") >= 0);
}
public void testToStringWithNullJob() throws Exception {
context = new JobExecution();
assertTrue("JobExecution string does not contain id", context.toString().indexOf("id=") >= 0);
assertTrue("JobExecution string does not contain job: " + context, context.toString().indexOf("job=") >= 0);
execution = new JobExecution();
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
assertTrue("JobExecution string does not contain job: " + execution, execution.toString().indexOf("job=") >= 0);
}
}

View File

@@ -72,6 +72,12 @@ public class JobInstanceTests extends TestCase {
public void testGetJob(){
assertEquals("job", instance.getJob().getName());
instance.setJob(null);
assertEquals(null, instance.getJob());
}
public void testCreateJobExecution(){
assertNotNull(instance.createJobExecution());
}
public void testCreateWithNulls(){

View File

@@ -13,151 +13,202 @@ import junit.framework.TestCase;
/**
* @author Lucas Ward
*
*
*/
public class JobParametersTests extends TestCase {
JobParameters parameters;
Map stringMap;
Map longMap;
Map dateMap;
Date date1 = new Date(4321431242L);
Date date2 = new Date(7809089900L);
protected void setUp() throws Exception {
super.setUp();
parameters = getNewParameters();
}
private JobParameters getNewParameters(){
private JobParameters getNewParameters() {
stringMap = new HashMap();
stringMap.put("string.key1", "value1");
stringMap.put("string.key2", "value2");
longMap = new HashMap();
longMap.put("long.key1", new Long(1));
longMap.put("long.key2", new Long(2));
dateMap = new HashMap();
dateMap.put("date.key1", date1 );
dateMap.put("date.key2", date2 );
dateMap.put("date.key1", date1);
dateMap.put("date.key2", date2);
return new JobParameters(stringMap, longMap, dateMap);
}
public void testBadLongConstructorException() throws Exception{
public void testBadLongKeyException() throws Exception {
Map badLongMap = new HashMap();
badLongMap.put("key", "bad long");
try{
badLongMap.put(new Long(0), new Long(1));
try {
new JobParameters(stringMap, badLongMap, dateMap);
fail();
}
catch(IllegalArgumentException ex){
//expected
catch (IllegalArgumentException ex) {
// expected
}
}
public void testBadStringConstructorException() throws Exception{
public void testBadLongConstructorException() throws Exception {
Map badLongMap = new HashMap();
badLongMap.put("key", "bad long");
try {
new JobParameters(stringMap, badLongMap, dateMap);
fail();
}
catch (IllegalArgumentException ex) {
// expected
}
}
public void testBadStringConstructorException() throws Exception {
Map badMap = new HashMap();
badMap.put("key", new Integer(2));
try{
try {
new JobParameters(badMap, longMap, dateMap);
fail();
}
catch(IllegalArgumentException ex){
//expected
catch (IllegalArgumentException ex) {
// expected
}
}
public void testBadDateConstructorException() throws Exception{
public void testBadDateConstructorException() throws Exception {
Map badMap = new HashMap();
badMap.put("key", new java.sql.Date(System.currentTimeMillis()));
try{
try {
new JobParameters(stringMap, longMap, badMap);
fail();
}
catch(IllegalArgumentException ex){
//expected
catch (IllegalArgumentException ex) {
// expected
}
}
public void testGetString(){
public void testGetString() {
assertEquals("value1", parameters.getString("string.key1"));
assertEquals("value2", parameters.getString("string.key2"));
}
public void testGetLong(){
public void testGetStringParameters() {
assertEquals("value1", parameters.getStringParameters().get("string.key1"));
assertEquals("value2", parameters.getStringParameters().get("string.key2"));
}
public void testGetLong() {
assertEquals(new Long(1), parameters.getLong("long.key1"));
assertEquals(new Long(2), parameters.getLong("long.key2"));
}
public void testGetDate(){
public void testGetLongParameters() {
assertEquals(new Long(1), parameters.getLongParameters().get("long.key1"));
assertEquals(new Long(2), parameters.getLongParameters().get("long.key2"));
}
public void testGetDate() {
assertEquals(date1, parameters.getDate("date.key1"));
assertEquals(date2, parameters.getDate("date.key2"));
}
public void testEquals(){
JobParameters testParameters = getNewParameters();
public void testGetDateParameters() {
assertEquals(date1, parameters.getDateParameters().get("date.key1"));
assertEquals(date2, parameters.getDateParameters().get("date.key2"));
}
public void testIsEmptyWhenEmpty() throws Exception {
assertTrue(new JobParameters().isEmpty());
}
public void testIsEmptyWhenNotEmpty() throws Exception {
assertFalse(parameters.isEmpty());
}
public void testEquals() {
JobParameters testParameters = getNewParameters();
assertTrue(testParameters.equals(parameters));
}
public void testToStringOrder(){
public void testEqualsSelf() {
assertTrue(parameters.equals(parameters));
}
public void testEqualsDifferent() {
assertFalse(parameters.equals(new JobParameters()));
}
public void testEqualsWrongType() {
assertFalse(parameters.equals("foo"));
}
public void testEqualsNull() {
assertFalse(parameters.equals(null));
}
public void testToStringOrder() {
Map props = parameters.getParameters();
StringBuilder stringBuilder = new StringBuilder();
for(Iterator it = props.entrySet().iterator();it.hasNext();){
Entry entry = (Entry)it.next();
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
Entry entry = (Entry) it.next();
stringBuilder.append(entry.toString() + ";");
}
String string1 = stringBuilder.toString();
stringMap = new HashMap();
stringMap.put("string.key2", "value2");
stringMap.put("string.key1", "value1");
longMap = new HashMap();
longMap.put("long.key2", new Long(2));
longMap.put("long.key1", new Long(1));
dateMap = new HashMap();
dateMap.put("date.key2", date2 );
dateMap.put("date.key1", date1 );
dateMap.put("date.key2", date2);
dateMap.put("date.key1", date1);
JobParameters testProps = new JobParameters(stringMap, longMap, dateMap);
props = testProps.getParameters();
stringBuilder = new StringBuilder();
for(Iterator it = props.entrySet().iterator();it.hasNext();){
Entry entry = (Entry)it.next();
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
Entry entry = (Entry) it.next();
stringBuilder.append(entry.toString() + ";");
}
String string2 = stringBuilder.toString();
assertEquals(string1, string2);
}
// Not sure how to properly test this since there is no order garuntee, commenting out for now.
//
// public void testToString(){
//
// assertEquals("{string.key1=value1, string.key2=value2}{long.key1=1, long.key2=2}" +
// "{date.key2=Wed Apr 01 03:11:29 CST 1970, date.key1=Thu Feb 19 18:23:51 CST 1970}", parameters.toString());
// }
public void testHashCodeEqualWhenEmpty() throws Exception {
int code = new JobParameters().hashCode();
assertEquals(code, new JobParameters().hashCode());
}
public void testHashCodeEqualWhenNotEmpty() throws Exception {
int code = getNewParameters().hashCode();
assertEquals(code, parameters.hashCode());
}
}

View File

@@ -96,5 +96,20 @@ public class JobSupportTests extends TestCase {
job.setRestartable(true);
assertTrue(job.isRestartable());
}
public void testToString() throws Exception {
String value = job.toString();
assertTrue("Should contain name: "+value, value.indexOf("name=")>=0);
}
public void testRunNotSupported() throws Exception {
try {
job.run(null);
} catch (UnsupportedOperationException e) {
// expected
String message = e.getMessage();
assertTrue("Message should contain JobSupport: "+message, message.contains("JobSupport"));
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* 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.core.domain;
import junit.framework.TestCase;
import org.springframework.batch.support.PropertiesConverter;
/**
* @author Dave Syer
*
*/
public class StepContributionTests extends TestCase {
private StepExecution execution = new StepExecution();
private StepContribution contribution = new StepContribution(execution);
/**
* Test method for {@link org.springframework.batch.core.domain.StepContribution#incrementTaskCount()}.
*/
public void testIncrementTaskCount() {
assertEquals(0, contribution.getTaskCount());
contribution.incrementTaskCount();
assertEquals(1, contribution.getTaskCount());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepContribution#setStatistics(java.util.Properties)}.
*/
public void testSetStatistics() {
assertEquals(null, contribution.getStatistics());
contribution.setStatistics(PropertiesConverter.stringToProperties("foo=bar"));
assertEquals(1, contribution.getStatistics().size());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepContribution#incrementCommitCount()}.
*/
public void testIncrementCommitCount() {
assertEquals(0, contribution.getCommitCount());
contribution.incrementCommitCount();
assertEquals(1, contribution.getCommitCount());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepContribution#isTerminateOnly()}.
*/
public void testIsTerminateOnly() {
assertFalse(contribution.isTerminateOnly());
execution.setTerminateOnly();
assertTrue(contribution.isTerminateOnly());
}
}

View File

@@ -39,6 +39,14 @@ public class StepExecutionTests extends TestCase {
assertNull(new StepExecution().getId());
}
/**
* Test method for
* {@link org.springframework.batch.core.domain.JobExecution#JobExecution()}.
*/
public void testStepExecutionWithNullId() {
assertNull(new StepExecution(null, null).getId());
}
/**
* Test method for
* {@link org.springframework.batch.core.domain.JobExecution#getEndTime()}.
@@ -154,6 +162,32 @@ public class StepExecutionTests extends TestCase {
public void testGetStepId() {
assertEquals(11, execution.getStepId().longValue());
}
public void testGetStep() throws Exception {
assertNotNull(execution.getStep());
}
public void testGetJobExecution() throws Exception {
assertNotNull(execution.getJobExecution());
}
public void testApplyContribution() throws Exception {
StepContribution contribution = execution.createStepContribution();
contribution.incrementCommitCount();
execution.apply(contribution);
assertEquals(new Integer(1), execution.getCommitCount());
}
public void testTerminateOnly() throws Exception {
assertFalse(execution.isTerminateOnly());
execution.setTerminateOnly();
assertTrue(execution.isTerminateOnly());
}
public void testToStringWithNullName() throws Exception {
String value = new StepExecution().toString();
assertTrue("Should contain name=null: "+value, value.indexOf("name=null")>=0);
}
public void testToString() throws Exception {
assertTrue("Should contain task count: " + execution.toString(),
@@ -200,6 +234,23 @@ public class StepExecutionTests extends TestCase {
assertFalse(step.equals(new StepExecution()));
}
public void testEqualsWithSelf() throws Exception {
assertTrue(execution.equals(execution));
}
public void testEqualsWithDifferent() throws Exception {
StepExecution step = newStepExecution(new Long(43), new Long(13));
assertFalse(execution.equals(step));
}
public void testEqualsWithNullStepId() throws Exception {
execution = newStepExecution(null, new Long(31));
assertEquals(null, execution.getStepId());
StepExecution step = newStepExecution(null, new Long(31));
assertEquals(step.getJobExecutionId(), execution.getJobExecutionId());
assertTrue(execution.equals(step));
}
public void testHashCode() throws Exception {
assertTrue("Hash code same as parent", new Entity(execution.getId())
.hashCode() != execution.hashCode());
@@ -217,4 +268,5 @@ public class StepExecutionTests extends TestCase {
StepExecution execution = new StepExecution(step, new JobExecution(job, long2), new Long(4));
return execution;
}
}

View File

@@ -40,6 +40,33 @@ public class StepSupportTests extends TestCase {
*/
public void testGetName() {
assertEquals("step", configuration.getName());
configuration.setName("bar");
assertEquals("bar", configuration.getName());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepSupport#getName()}.
*/
public void testBeanNameAlreadySet() {
assertEquals("step", configuration.getName());
configuration.setBeanName("bar");
assertEquals("step", configuration.getName());
}
/**
* Test method for {@link org.springframework.batch.core.domain.StepSupport#getName()}.
*/
public void testBeanNameOnNew() {
configuration = new StepSupport();
assertEquals(null, configuration.getName());
configuration.setBeanName("bar");
assertEquals("bar", configuration.getName());
}
public void testSaveRestartFlag() throws Exception {
assertEquals(false, configuration.isSaveRestartData());
configuration.setSaveRestartData(true);
assertEquals(true, configuration.isSaveRestartData());
}
/**

View File

@@ -1,32 +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.execution.launch;
/**
* @author Dave Syer
*
*/
public class NoSuchJobExecutionException extends Exception {
/**
* @param message
*/
public NoSuchJobExecutionException(String message) {
super(message);
}
}

View File

@@ -84,8 +84,8 @@ public class SimpleJobLauncher implements JobLauncher, InitializingBean {
try {
logger.info("Job: [" + job + "] launched with the following parameters: [" + jobParameters + "]");
ExitStatus exitStatus = job.run(jobExecution);
// shouldn't need to set the exit status like this, I'm
// leaving it to make the latest change easier
// The exit status should be set by the Job. TODO: remove
// this line...
jobExecution.setExitStatus(exitStatus);
logger.info("Job: [" + job + "] completed successfully with the following parameters: ["
+ jobParameters + "]");
@@ -126,7 +126,8 @@ public class SimpleJobLauncher implements JobLauncher, InitializingBean {
}
/**
* Ensure the required dependencies of a {@link JobRepository} have been set.
* Ensure the required dependencies of a {@link JobRepository} have been
* set.
*/
public void afterPropertiesSet() throws Exception {
Assert.state(jobRepository != null, "A JobRepository has not been set.");

View File

@@ -16,6 +16,9 @@
package org.springframework.batch.execution.launch;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.easymock.MockControl;
@@ -24,50 +27,112 @@ import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.task.TaskExecutor;
/**
* @author Lucas Ward
*
*
*/
public class SimpleJobLauncherTests extends TestCase {
private SimpleJobLauncher jobLauncher;
private MockControl repositoryControl = MockControl.createControl(JobRepository.class);
private Job job = new JobSupport("foo") {
public ExitStatus run(JobExecution execution) throws BatchCriticalException {
public ExitStatus run(JobExecution execution) {
return ExitStatus.FINISHED;
}
};
private JobParameters jobParameters = new JobParameters();
private JobRepository jobRepository;
protected void setUp() throws Exception {
super.setUp();
jobLauncher = new SimpleJobLauncher();
jobLauncher = new SimpleJobLauncher();
jobRepository = (JobRepository) repositoryControl.getMock();
jobLauncher.setJobRepository(jobRepository);
}
public void testRun() throws Exception {
public void testRun() throws Exception{
JobExecution jobExecution = new JobExecution(null);
jobRepository.createJobExecution(job, jobParameters);
repositoryControl.setReturnValue(jobExecution);
repositoryControl.replay();
jobLauncher.run(job, jobParameters);
assertEquals(ExitStatus.FINISHED, jobExecution.getExitStatus());
repositoryControl.verify();
}
public void testTaskExecutor() throws Exception {
final List list = new ArrayList();
jobLauncher.setTaskExecutor(new TaskExecutor() {
public void execute(Runnable task) {
list.add("execute");
task.run();
}
});
testRun();
assertEquals(1, list.size());
}
public void testRunWithException() throws Exception {
job = new JobSupport() {
public ExitStatus run(JobExecution execution) {
execution.setExitStatus(ExitStatus.FAILED);
throw new RuntimeException("foo");
}
};
try {
testRun();
fail("Expected RuntimeException");
}
catch (RuntimeException e) {
assertEquals("foo", e.getMessage());
}
}
public void testRunWithError() throws Exception {
job = new JobSupport() {
public ExitStatus run(JobExecution execution) {
execution.setExitStatus(ExitStatus.FAILED);
throw new Error("foo");
}
};
try {
testRun();
fail("Expected Error");
}
catch (RuntimeException e) {
assertEquals("foo", e.getCause().getMessage());
}
}
public void testInitialiseWithoutRepository() throws Exception {
try {
new SimpleJobLauncher().afterPropertiesSet();
fail("Expected IllegalArgumentException");
}
catch (IllegalStateException e) {
// expected
assertTrue("Message did not contain repository: " + e.getMessage(), e.getMessage().toLowerCase().contains(
"repository"));
}
}
public void testInitialiseWithRepository() throws Exception {
jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(jobRepository);
jobLauncher.afterPropertiesSet(); // no error
}
}

View File

@@ -23,6 +23,7 @@ import java.util.Properties;
import org.springframework.util.DefaultPropertiesPersister;
import org.springframework.util.PropertiesPersister;
import org.springframework.util.StringUtils;
/**
* Utility to convert a Properties object to a String and back. Ideally this
@@ -48,7 +49,10 @@ public final class PropertiesConverter {
/**
* Parse a String to a Properties object. If string is null, an empty
* Properties object will be returned.
* Properties object will be returned. The input String is a set of
* name=value pairs, delimited by either newline or comma (for brevity). If
* the input String contains a newline it is assumed that the separator is
* newline, otherwise comma.
*
* @param stringToParse String to parse.
* @return Properties parsed from each string.
@@ -61,6 +65,11 @@ public final class PropertiesConverter {
return new Properties();
}
if (!stringToParse.contains("\n")) {
return StringUtils.splitArrayElementsIntoProperties(StringUtils
.commaDelimitedListToStringArray(stringToParse), "=");
}
StringReader stringReader = new StringReader(stringToParse);
Properties properties = new Properties();

View File

@@ -36,7 +36,7 @@ public class PropertiesConverterTests extends TestCase {
/**
* Check that Properties can be converted to String and back correctly.
*/
public void testRegularConversion() {
public void testTwoWayRegularConversion() {
Properties storedProps = new Properties();
storedProps.setProperty("key1", "value1");
@@ -47,6 +47,48 @@ public class PropertiesConverterTests extends TestCase {
assertEquals(storedProps, props);
}
/**
* Check that Properties can be comma delimited.
*/
public void testRegularConversionWithComma() {
Properties storedProps = new Properties();
storedProps.setProperty("key1", "value1");
storedProps.setProperty("key2", "value2");
props = PropertiesConverter.stringToProperties("key1=value1,key2=value2");
assertEquals(storedProps, props);
}
/**
* Check that Properties can be comma delimited with extra whitespace.
*/
public void testRegularConversionWithCommaAndWhitespace() {
Properties storedProps = new Properties();
storedProps.setProperty("key1", "value1");
storedProps.setProperty("key2", "value2");
props = PropertiesConverter.stringToProperties("key1=value1, key2=value2");
assertEquals(storedProps, props);
}
/**
* Check that Properties can be newline delimited.
*/
public void testRegularConversionWithCommaAndNewline() {
Properties storedProps = new Properties();
storedProps.setProperty("key1", "value1");
storedProps.setProperty("key2", "value2");
props = PropertiesConverter.stringToProperties("key1=value1\n key2=value2");
assertEquals(storedProps, props);
}
/**
* Converting a String to Properties and back does not return equal String!
* See {@link PropertiesConverter} javadoc for more details.