Question

how would you write a junit test for this import java.io.File; public class CheckEmptyDirectoryExample { public...

how would you write a junit test for this 
import java.io.File;

public class CheckEmptyDirectoryExample
{
    public static void main(String[] args)
    {   
 
File file = new File("C:\\folder");
                
        if(file.isDirectory()){
                        
                if(file.list().length>0){
                                
                        System.out.println("Directory is not empty!");
                                
                }else{
                                
                        System.out.println("Directory is empty!");
                                
                }
                        
        }else{
                        
                System.out.println("This is not a directory");
                        
        }
    }
0 0
Add a comment Improve this question Transcribed image text
Answer #1

we can't write the Junit for the above code as it is not returning anything and we are not able to pass anything as it is harcoded directly

first we need to change the code to take the path from the command line arguments than only we can write the test cases for it

Add a comment
Know the answer?
Add Answer to:
how would you write a junit test for this import java.io.File; public class CheckEmptyDirectoryExample { public...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT