roy_sanu
asked on
Junit
public Split process(Split split) throws Exception {
if (split.getFrom().equals(split.geTo())) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("The 'FROM and TO Member ID' should not be matched: (");
stringBuffer.append(split.getMidFrom());
stringBuffer.append(",");
stringBuffer.append(split.getMidTo());
stringBuffer.append(")");
throw new ValidationException(stringBuffer.toString());
}
if (null == split.getFrom() || "".equals(split.getFrom().trim())) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("'FROM ID' is missing from the record: (");
stringBuffer.append(split.getMidFrom());
stringBuffer.append(",");
stringBuffer.append(split.getMidTo());
stringBuffer.append(")");
throw new ValidationException(stringBuffer.toString());
}
if (null == split.getTo() || "".equals(split.getTo().trim())) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("'TO ID' is missing from the record: (");
stringBuffer.append(split.getFrom());
stringBuffer.append(",");
stringBuffer.append(split.getTo());
stringBuffer.append(")");
throw new ValidationException(stringBuffer.toString());
}
return split;
}
is this correct way to write junit
public class SplitProcessorTest {
private Split split;
@Before
public void beforeTest() {
split = new Split ();
}
@Test
public void SplitdNotsameTest() throws Exception {
split.setFrom ("Test1");
split.setTo("Test1");
try{
assertNotSame("("The 'FROM and TO ID' should not be matched: ", split.getFrom(),split.getTo());
}catch(AssertionError exception){ }
}
@Test
public void SplitfromNullTest() throws Exception {
split.setFrom(" ");
split.setTo("Test1");
try{
assertNull("From member id is missing from the record",null == split.getFrom() || "".equals(split.getFrom().trim()));
}catch(AssertionError exception){ }
}
@Test
public void SplitTonullTest() throws Exception {
split.setMidTo(" ");
try{
assertNull("To member id is missing from the record",null == split.getTo() || "".equals(split.getTo().trim()));
}catch(AssertionError exception){ }
}
}
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER