Solved

Junit

Posted on 2014-01-04
2
444 Views
Last Modified: 2014-01-04
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
0
Comment
Question by:roy_sanu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
Amitkumar Panchal earned 500 total points
ID: 39756380
You have just verified based on the values set in Split.

You should also call process() method in your test case and check the expected exceptions if any.


Refer : http://www.mkyong.com/unittest/junit-4-tutorial-2-expected-exception-test/
0
 

Author Comment

by:roy_sanu
ID: 39757053
Thank you for good comments, it is working fine
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate jars 4 57
CSV file parsing thru Java 13 39
maven not picking latest jar instead picking old jar from .m2 12 43
Html split(text) 2 27
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question