In a xml config file I have a delimiter property configured as unicode escape seq like this:
<adapter name="Adapter2">
<property name="adapter.delimiter" value="\u0009"/>
</adapter>
There is also method getting any property in Adapter class:
String getProperty(String propertyName)
For getProperty(“adapter.delimiter”) it returns already escaped string “\t”
What I need is to convert property \u0009 into char to be able to provide the \t char to any further methods.
- How to verify that the method really returns tab char in unit test?
This does not work (I am not sure if the code or unit test is wrong):
public char getDelimiter() throws VTBaseException {
String delimiterProperty = getProperty("adapter.delimiter");
if (delimiterProperty == null || "".equals(delimiterProperty)) {
//default
return DEFAULT_DELIMITER;
} else if (delimiterProperty.length() == 1) {
return delimiterProperty.charAt(0);
} else {
throw new VTBaseException();
}
}
Unit test:
@Test
public void testReturnDelimiterProperty()
throws Exception
{
VTAdapter adapter = manager.getAdapter("Adapter2");
assertEquals(',', adapter.getDelimiter());//passes if property not set
adapter = world.getAdapterList().getAdapter("Adapter1");
assertEquals("\t", adapter.getDelimiter());//fails with exception bellow
}
junit.framework.AssertionFailedError: expected:< > but was:< >
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.failNotEquals(Assert.java:283)
at junit.framework.Assert.assertEquals(Assert.java:64)
at junit.framework.Assert.assertEquals(Assert.java:71)
at
Outputs a tab: