Problem: To write the JUnit test cases for our methods, you need to create two test methods: testLeapYear: This method should test if the isLeapYear method returns true for a given leap year. For example, you can choose the year 2020 and verify if the method returns true for it. If it does, the test will pass. If it doesn't, the test will fail. testNotLeapYear: This method should test if the isLeapYear method returns false for a given non-leap year. For example, you can choose the year 1900 and verify if the method returns false for it. If it does, the test will pass. If it doesn't, the test will fail. ---------------------------------------------------------------------------------------------------------------------------------------------------------   import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class LeapYearTest {   // Test case to check if a year is a leap year   @Test   public void testLeapYear() {     //create a variable of int type called "year" and assign it with value "2020"     //create a variable of boolean type, call it "expectedResult" and assign it with value "true"     //Call the method isLeapYear() and pass "year" as an argument to it,store the result in a variable of boolean type called "actualResult"     //Verify if the actual result is equal to the expected result using assertTrue()       }   // Test case to check if a year is not a leap year   @Test   public void testNotLeapYear() {        //create a variable of int type,call it "year" and assign it with value "1900"        //create a variable of boolean type, call it "expectedResult" and assign it with value "false"        //Call the method isLeapYear() and pass "year" as an argument to it, store the result in a variable of boolean type called "actualResult"             //Verify if the actual result is equal to the expected result using assertTrue()      }      //Do not modify this code   // Method to check if a year is a leap year or not   private static boolean isLeapYear(int year) {     // Check if the year is divisible by 400 or divisible by 4 and not divisible by 100         return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  • Problem: To write the JUnit test cases for our methods, you need to create two test methods:

    1. testLeapYear: This method should test if the isLeapYear method returns true for a given leap year. For example, you can choose the year 2020 and verify if the method returns true for it. If it does, the test will pass. If it doesn't, the test will fail.

    2. testNotLeapYear: This method should test if the isLeapYear method returns false for a given non-leap year. For example, you can choose the year 1900 and verify if the method returns false for it. If it does, the test will pass. If it doesn't, the test will fail.

---------------------------------------------------------------------------------------------------------------------------------------------------------

 
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

public class LeapYearTest {

  // Test case to check if a year is a leap year
  @Test
  public void testLeapYear() {
    //create a variable of int type called "year" and assign it with value "2020"

    //create a variable of boolean type, call it "expectedResult" and assign it with value "true"

    //Call the method isLeapYear() and pass "year" as an argument to it,store the result in a variable of boolean type called "actualResult"

    //Verify if the actual result is equal to the expected result using assertTrue()
   
  }

  // Test case to check if a year is not a leap year
  @Test
  public void testNotLeapYear() {

       //create a variable of int type,call it "year" and assign it with value "1900"

       //create a variable of boolean type, call it "expectedResult" and assign it with value "false"

       //Call the method isLeapYear() and pass "year" as an argument to it, store the result in a variable of boolean type called "actualResult"

    
       //Verify if the actual result is equal to the expected result using assertTrue()
  
  }
  
  //Do not modify this code
  // Method to check if a year is a leap year or not
  private static boolean isLeapYear(int year) {
    // Check if the year is divisible by 400 or divisible by 4 and not divisible by 100
        return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
    }

}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Code is not working for me. I used the same code but i keep getting error

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education