Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 4ad79769 rédigé par Reda ESSEKKAKI's avatar Reda ESSEKKAKI
Parcourir les fichiers

corrected some parameters in DateAssertion.java methods

parent 753c5534
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!2Implementation of Assertions in commons-assertions module.
package org.atlanmod.commons.assertions;
import java.time.Duration;
import java.time.Month;
import java.time.Year;
import java.time.ZoneId;
import java.util.Date;
......@@ -190,15 +192,14 @@ public class DateAssertion extends Assertion implements DateAssertionInterface {
return this;
}
/**
* Asserts that the year of the Date object is equal to the given year.
*
* @param year the year to compare with
*/
@Override
public DateAssertion hasYear(int year) {
int currentYear = this.actual.toInstant().atZone(ZoneId.systemDefault()).getYear();
public DateAssertion hasYear(Year year) {
Year currentYear = Year.of(this.actual.toInstant().atZone(ZoneId.systemDefault()).getYear());
if (!(currentYear == year)) {
check = false;
......@@ -213,8 +214,8 @@ public class DateAssertion extends Assertion implements DateAssertionInterface {
* @param month the month to compare with
*/
@Override
public DateAssertion hasMonth(int month) {
int currentMonth = this.actual.toInstant().atZone(ZoneId.systemDefault()).getMonthValue();
public DateAssertion hasMonth(Month month) {
Month currentMonth = Month.of(this.actual.toInstant().atZone(ZoneId.systemDefault()).getMonthValue());
if (currentMonth != month) {
check = false;
......@@ -224,13 +225,18 @@ public class DateAssertion extends Assertion implements DateAssertionInterface {
}
/**
* Asserts that the day of the Date object is equal to the given day.
* Asserts that the day of the Date object is equal to the given day of the month.
*
* @param day the day to compare with
* @param day the day of the month to compare with
* @throws IllegalArgumentException if the day parameter is not within the valid range
*/
@Override
public DateAssertion hasDay(int day) {
int currentDay = this.actual.toInstant().atZone(ZoneId.systemDefault()).getDayOfYear();
if (day < 1 || day > 31) {
throw new IllegalArgumentException("Invalid day value. Day must be between 1 and 31.");
}
int currentDay = this.actual.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().getDayOfMonth();
if (currentDay != day) {
check = false;
......@@ -239,13 +245,19 @@ public class DateAssertion extends Assertion implements DateAssertionInterface {
return this;
}
/**
* Asserts that the hour of the Date object is equal to the given hour.
*
* @param hour the hour to compare with
* @param hour the hour to compare with (valid range: 0 to 23)
* @throws IllegalArgumentException if the hour parameter is not within the valid range
*/
@Override
public DateAssertion hasHour(int hour) {
if (hour < 0 || hour > 23) {
throw new IllegalArgumentException("Invalid hour value. Hour must be between 0 and 23.");
}
int currentHour = this.actual.toInstant().atZone(ZoneId.systemDefault()).getHour();
if (currentHour != hour) {
......@@ -255,22 +267,29 @@ public class DateAssertion extends Assertion implements DateAssertionInterface {
return this;
}
/**
* Asserts that the minute of the Date object is equal to the given minute.
*
* @param minute the minute to compare with
* @param minute the minute to compare with (valid range: 0 to 59)
* @throws IllegalArgumentException if the minute parameter is not within the valid range
*/
@Override
public DateAssertion hasMinute(int minute) {
if (minute < 0 || minute > 59) {
throw new IllegalArgumentException("Invalid minute value. Minute must be between 0 and 59.");
}
int currentMinute = this.actual.toInstant().atZone(ZoneId.systemDefault()).getMinute();
if (currentMinute != minute) {
check = false;
message += String.format("\nExpecting day to be %s but it was %s", minute, currentMinute);
message += String.format("\nExpecting minute to be %s but it was %s", minute, currentMinute);
}
return this;
}
/**
* Asserts that the Date object has the given timestamp.
*
......
package org.atlanmod.commons.assertions;
import java.time.Duration;
import java.time.Month;
import java.time.Year;
import java.util.Date;
public interface DateAssertionInterface extends AssertionInterface {
......@@ -99,14 +101,14 @@ public interface DateAssertionInterface extends AssertionInterface {
*
* @param year the expected year
*/
DateAssertion hasYear(int year);
DateAssertion hasYear(Year year);
/**
* Asserts that the date has the specified month.
*
* @param month the expected month
*/
DateAssertion hasMonth(int month);
DateAssertion hasMonth(Month month);
/**
* Asserts that the date has the specified day.
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter