Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:50:20+00:00 2026-05-23T16:50:20+00:00

I have a piece of code in Java that zips the contents of a

  • 0

I have a piece of code in Java that zips the contents of a directory into a zip file.

The signature of the method is as follows:

/**
 * Zips the contents of the directory into the zip file.
 * @param directory the directory to zip
 * @param zipFilename the file name to zip into
 */
public static void doZIP(String directory, String zipFileName)
{
    //do the zipping
}

Now I have to write a JUnit test case for the above method. What exactly should I test, and how?

NOTE : I am not looking for answers on how to write a JUnit test case.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:50:21+00:00Added an answer on May 23, 2026 at 4:50 pm

    Create a temporary directory and write some files into the directory. Then call the method with the temp directory as argument and a given zip file name. Test that the zip file exists. Then test that you can open it with ZipFile and find the expected zip entries in the zip file.

    The method doesn’t specify its contract very well. For example, it doesn’t say what it does if the directory doesn’t exist, or if it’s impossible to write the zip file, so it’s hard to test these aspects. But normally, it’s the developer of a method which writes the unit test for it, because he knows what the corner-cases are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of Java code that reads strings from CSV file.
Here is the piece of code that I have used for Java 5.0 TreeSet<Integer>
I have a piece of code VERY similar to this one http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching I the
I have a situation where there is a small piece of Java code that
I have a piece of java code which reads strings from a file and
I have a piece of Java code that is checking it is between two
I have the following piece of Java code that I would like to convert
I have this piece of code that converts an ArrayList of StringBuilders into an
I am using iTextSharp in VB.net. I have this piece of code from java
Context I have this piece of Java Code btn.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.