Link to home
Start Free TrialLog in
Avatar of roy_sanu
roy_sanuFlag for India

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;
	}

Open in new window


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){ }
    		  }
    	
    
    
    
    	
}	
    

Open in new window


thanks
ASKER CERTIFIED SOLUTION
Avatar of Am P
Am P
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of roy_sanu

ASKER

Thank you for good comments, it is working fine