Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider c886f596 rédigé par Gerson Sunyé's avatar Gerson Sunyé
Parcourir les fichiers

Class renames

parent 9aaa7727
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #73414 réussi
Affichage de
avec 348 ajouts et 350 suppressions
/*
* Copyright (c) 2017-23 Atlanmod.
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v2.0 which accompanies
* this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/
*/
package org.atlanmod.commons.assertions;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* The AbstractAssertion class provides a set of methods for performing assertions on various types of values.
* Assertions are used to check that certain conditions are met during the execution of a program.
*/
public abstract class AbstractAssertion implements Assertion {
final Object actualValue;
/**
* A map of AbstractAssertion objects associated with each thread.
*/
public static ConcurrentMap<Thread, AbstractAssertion> assertions = new ConcurrentHashMap<>();
/**
* The result of the assertion check.
*/
protected boolean check;
/**
* The message associated with the assertion.
*/
protected String message;
/**
* The pattern used to format assertion messages.
*/
static final String PATTERN = "\nExpecting value (%s) to be %s (%s)";
/**
* The pattern used to format assertion messages when the assertion fails.
*/
static final String PATTERNFALSE = "\nExpecting value (%s) not to be %s (%s)";
/**
* Constructs a new AbstractAssertion object and associates it with the current thread.
*/
AbstractAssertion(Object actualValue) {
this.actualValue = actualValue;
check = true;
message = String.format("AbstractAssertion failures in thread %s : \n", Thread.currentThread().getName());
if (Assertions.isActive)
assertions.put(Thread.currentThread(), this);
}
/**
* Returns the current AbstractAssertion object associated with the current thread.
*/
public static AbstractAssertion assertion() {
if (Assertions.isActive && assertions.containsKey(Thread.currentThread()))
return assertions.get(Thread.currentThread());
else
return null;
}
/**
* Returns the message associated with the assertion.
*/
public String message() {
String msg = this.message;
AbstractAssertion.assertions.remove(Thread.currentThread());
return msg;
}
/**
* Returns the result of the assertion check.
*
* @return true if the assertion passed, false otherwise
*/
public boolean check() {
return check;
}
@Override
public String toString() {
return Objects.requireNonNull(assertion()).message();
}
public <T> void checkInvariant(Invariant<T> inv) {
if (!inv.test((T) actualValue)) {
check = false;
message += String.format("\nExpecting actual (%s) to respect invariant (%s), but it does not", actualValue, inv);
}
}
}
\ No newline at end of file
...@@ -8,215 +8,22 @@ ...@@ -8,215 +8,22 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
import java.util.Collection;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.io.File;
/** /**
* The Assertion class provides a set of methods for performing assertions on various types of values. * An interface for implementing assertion instances.
* Assertions are used to check that certain conditions are met during the execution of a program.
*/ */
public class Assertion implements AssertionInterface { public interface Assertion {
final Object actualValue;
/**
* A map of Assertion objects associated with each thread.
*/
public static ConcurrentMap<Thread, Assertion> assertions = new ConcurrentHashMap<>();
/**
* The result of the assertion check.
*/
protected boolean check;
/**
* The message associated with the assertion.
*/
protected String message;
/**
* The pattern used to format assertion messages.
*/
static final String PATTERN = "\nExpecting value (%s) to be %s (%s)";
/**
* The pattern used to format assertion messages when the assertion fails.
*/
static final String PATTERNFALSE = "\nExpecting value (%s) not to be %s (%s)";
/**
* Constructs a new Assertion object and associates it with the current thread.
*/
Assertion(Object actualValue) {
this.actualValue = actualValue;
check = true;
message = String.format("Assertion failures in thread %s : \n", Thread.currentThread().getName());
if (Assertions.isActive)
assertions.put(Thread.currentThread(), this);
}
/**
* Returns the current Assertion object associated with the current thread.
*/
public static Assertion assertion() {
if (Assertions.isActive && assertions.containsKey(Thread.currentThread()))
return assertions.get(Thread.currentThread());
else
return null;
}
/**
* Returns the message associated with the assertion.
*/
public String message() {
String msg = this.message;
Assertion.assertions.remove(Thread.currentThread());
return msg;
}
/**
* Returns the result of the assertion check.
*
* @return true if the assertion passed, false otherwise
*/
public boolean check() {
return check;
}
/**
* Returns a BooleanAssertion object for performing assertions on boolean values.
*
* @param actual the actual value of the variable
*/
public static BooleanAssertion assertThat(boolean actual) {
return BooleanAssertion.boolAssertThat(actual);
}
/**
* Returns an IntAssertion object for performing assertions on int values.
*
* @param actual the actual value of the variable
*/
public static IntAssertion assertThat(int actual) {
return IntAssertion.intAssertThat(actual);
}
/** /**
* Returns a LongAssertion object for performing assertions on long values. * Returns the assertion message.
* *
* @param actual the actual value of the variable * @return the assertion message
*/ */
public static LongAssertion assertThat(long actual) { String message();
return LongAssertion.longAssertThat(actual);
}
/** /**
* Returns a ComparableAssertion object for performing assertions on Comparable values. * Returns true if the assertion passed, false otherwise.
* *
* @param actual the actual value of the variable * @return true if the assertion passed, false otherwise
*/
public static ComparableAssertion<?, Comparable> assertThat(Comparable<?> actual) {
return ComparableAssertion.comparableAssertThat(actual);
}
/**
* Returns a DoubleAssertion object for performing assertions on double values.
*
* @param actual the actual value of the variable
*/
public static DoubleAssertion assertThat(double actual) {
return DoubleAssertion.doubleAssertThat(actual);
}
/**
* Returns a DateAssertion object for performing assertions on Date values.
*
* @param actual the actual value of the variable
*/
public static DateAssertion assertThat(Date actual) {
return DateAssertion.dateAssertThat(actual);
}
/**
* Returns a FloatAssertion object for performing assertions on float values.
*
* @param actual the actual value of the variable
*/
public static FloatAssertion assertThat(float actual) {
return FloatAssertion.floatAssertThat(actual);
}
/**
* Returns a StringAssertion object for performing assertions on String values.
*
* @param actual the actual value of the variable
*/
public static StringAssertion assertThat(String actual) {
return StringAssertion.stringAssertThat(actual);
}
/**
* Returns a CollectionAssertion object for performing assertions on Collection values.
*
* @param actual the actual value of the variable
*/
public static <T> CollectionAssertion<?, Collection<? extends T>> assertThat(Collection<?> actual) {
return CollectionAssertion.collectionAssertThat(actual);
}
/**
* Returns an ObjectAssertion object for performing assertions on Object values.
*
* @param actual the actual value of the variable
*/
public static <T> ObjectAssertion<?, T> assertThat(Object actual) {
return ObjectAssertion.ObjectAssertThat(actual);
}
/**
* Return a UnidirectionalAssertion object for performing assertions on UnidirectionalWrapper values.
*
* @param actual the actual value
*/
public static UnidirectionalAssertion<?, UnidirectionalWrapper> assertThat(UnidirectionalWrapper<?> actual) {
return UnidirectionalAssertion.assertThatAssociation(actual);
}
/**
* Return a BidirectionalAssertion object for performing assertions on BidirectionalWrapper values.
*
* @param actual the actual value
*/
public static BidirectionalAssertion<?, BidirectionalWrapper> assertThat(BidirectionalWrapper<?> actual) {
return BidirectionalAssertion.assertThatAssociation(actual);
}
/**
* Return a FileAssertion object for performing assertions on File values.
*
* @param actual the actual value
*/ */
public static FileAssertion assertThat(File actual) { boolean check();
return FileAssertion.FileAssertThat(actual); }
}
@Override
public String toString() {
return Objects.requireNonNull(assertion()).message();
}
public <T> void checkInvariant(Invariant<T> inv) {
if (!inv.test((T) actualValue)) {
check = false;
message += String.format("\nExpecting actual (%s) to respect invariant (%s), but it does not", actualValue, inv);
}
}
}
\ No newline at end of file
/*
* Copyright (c) 2017-23 Atlanmod.
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v2.0 which accompanies
* this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/
*/
package org.atlanmod.commons.assertions;
/**
* An interface for implementing assertion instances.
*/
public interface AssertionInterface {
/**
* Returns the assertion message.
*
* @return the assertion message
*/
String message();
/**
* Returns true if the assertion passed, false otherwise.
*
* @return true if the assertion passed, false otherwise
*/
boolean check();
}
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
import java.io.File;
import java.util.Collection;
import java.util.Date;
import java.util.function.Predicate; import java.util.function.Predicate;
public class Assertions { public class Assertions {
...@@ -20,10 +23,126 @@ public class Assertions { ...@@ -20,10 +23,126 @@ public class Assertions {
static { static {
assert (Assertions.isActive = true); assert (Assertions.isActive = true);
} }
public static <T> Invariant<T> createInv(Predicate<T> predicate) { public static <T> Invariant<T> createInv(Predicate<T> predicate) {
return isActive ? obj -> predicate.test(obj) : NULL_INVARIANT;
}
/**
* Returns a BooleanAssertion object for performing assertions on boolean values.
*
* @param actual the actual value of the variable
*/
public static BooleanAssertion assertThat(boolean actual) {
return BooleanAssertion.boolAssertThat(actual);
}
/**
* Returns an IntAssertion object for performing assertions on int values.
*
* @param actual the actual value of the variable
*/
public static IntAssertion assertThat(int actual) {
return IntAssertion.intAssertThat(actual);
}
/**
* Returns a LongAssertion object for performing assertions on long values.
*
* @param actual the actual value of the variable
*/
public static LongAssertion assertThat(long actual) {
return LongAssertion.longAssertThat(actual);
}
return isActive ? obj -> predicate.test(obj) : NULL_INVARIANT; /**
* Returns a ComparableAssertion object for performing assertions on Comparable values.
*
* @param actual the actual value of the variable
*/
public static ComparableAssertion<?, Comparable> assertThat(Comparable<?> actual) {
return ComparableAssertion.comparableAssertThat(actual);
}
/**
* Returns a DoubleAssertion object for performing assertions on double values.
*
* @param actual the actual value of the variable
*/
public static DoubleAssertion assertThat(double actual) {
return DoubleAssertion.doubleAssertThat(actual);
}
/**
* Returns a DateAssertion object for performing assertions on Date values.
*
* @param actual the actual value of the variable
*/
public static DateAssertion assertThat(Date actual) {
return DateAssertion.dateAssertThat(actual);
}
/**
* Returns a FloatAssertion object for performing assertions on float values.
*
* @param actual the actual value of the variable
*/
public static FloatAssertion assertThat(float actual) {
return FloatAssertion.floatAssertThat(actual);
}
/**
* Returns a StringAssertion object for performing assertions on String values.
*
* @param actual the actual value of the variable
*/
public static StringAssertion assertThat(String actual) {
return StringAssertion.stringAssertThat(actual);
}
/**
* Returns a CollectionAssertion object for performing assertions on Collection values.
*
* @param actual the actual value of the variable
*/
public static <T> CollectionAssertion<?, Collection<? extends T>> assertThat(Collection<?> actual) {
return CollectionAssertion.collectionAssertThat(actual);
}
/**
* Returns an ObjectAssertion object for performing assertions on Object values.
*
* @param actual the actual value of the variable
*/
public static <T> ObjectAssertion<?, T> assertThat(Object actual) {
return ObjectAssertion.ObjectAssertThat(actual);
}
/**
* Return a UnidirectionalAssertion object for performing assertions on UnidirectionalWrapper values.
*
* @param actual the actual value
*/
public static UnidirectionalAssertion<?, UnidirectionalWrapper> assertThat(UnidirectionalWrapper<?> actual) {
return UnidirectionalAssertion.assertThatAssociation(actual);
}
/**
* Return a BidirectionalAssertion object for performing assertions on BidirectionalWrapper values.
*
* @param actual the actual value
*/
public static BidirectionalAssertion<?, BidirectionalWrapper> assertThat(BidirectionalWrapper<?> actual) {
return BidirectionalAssertion.assertThatAssociation(actual);
}
/**
* Return a FileAssertion object for performing assertions on File values.
*
* @param actual the actual value
*/
public static FileAssertion assertThat(File actual) {
return FileAssertion.FileAssertThat(actual);
} }
static private class NullInvariant implements Invariant { static private class NullInvariant implements Invariant {
......
...@@ -12,7 +12,7 @@ package org.atlanmod.commons.assertions; ...@@ -12,7 +12,7 @@ package org.atlanmod.commons.assertions;
* The BooleanAssertion class provides a set of methods for performing assertions on boolean values. * The BooleanAssertion class provides a set of methods for performing assertions on boolean values.
* Assertions are used to check that certain conditions are met during the execution of a program. * Assertions are used to check that certain conditions are met during the execution of a program.
*/ */
public class BooleanAssertion extends Assertion implements BooleanAssertionInterface { public class BooleanAssertion extends AbstractAssertion implements BooleanAssertionInterface {
/** /**
* The actual value of the boolean variable being asserted. * The actual value of the boolean variable being asserted.
......
...@@ -12,7 +12,7 @@ package org.atlanmod.commons.assertions; ...@@ -12,7 +12,7 @@ package org.atlanmod.commons.assertions;
* The BooleanAssertionInterface interface provides a set of methods for performing assertions on boolean values. * The BooleanAssertionInterface interface provides a set of methods for performing assertions on boolean values.
* Assertions are used to check that certain conditions are met during the execution of a program. * Assertions are used to check that certain conditions are met during the execution of a program.
*/ */
public interface BooleanAssertionInterface extends AssertionInterface { public interface BooleanAssertionInterface extends Assertion {
/** /**
* Returns a new BooleanAssertion object with the specified actual value. * Returns a new BooleanAssertion object with the specified actual value.
......
...@@ -14,7 +14,7 @@ import java.time.Year; ...@@ -14,7 +14,7 @@ import java.time.Year;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Date; import java.util.Date;
public class DateAssertion extends Assertion implements DateAssertionInterface { public class DateAssertion extends AbstractAssertion implements DateAssertionInterface {
/** /**
* The actual date being asserted. * The actual date being asserted.
......
...@@ -13,7 +13,7 @@ import java.time.Month; ...@@ -13,7 +13,7 @@ import java.time.Month;
import java.time.Year; import java.time.Year;
import java.util.Date; import java.util.Date;
public interface DateAssertionInterface extends AssertionInterface { public interface DateAssertionInterface extends Assertion {
/** /**
* Asserts that the actual date is equal to the expected date. * Asserts that the actual date is equal to the expected date.
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
public class DoubleAssertion extends Assertion implements DoubleAssertionInterface { public class DoubleAssertion extends AbstractAssertion implements DoubleAssertionInterface {
private double value; private double value;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
public interface DoubleAssertionInterface extends AssertionInterface { public interface DoubleAssertionInterface extends Assertion {
static DoubleAssertionInterface doubleAssertThat(double actual) { static DoubleAssertionInterface doubleAssertThat(double actual) {
return null; return null;
......
...@@ -11,7 +11,7 @@ package org.atlanmod.commons.assertions; ...@@ -11,7 +11,7 @@ package org.atlanmod.commons.assertions;
import java.io.File; import java.io.File;
/** /**
* Assertion class for files. * AbstractAssertion class for files.
*/ */
public class FileAssertion extends ObjectAssertion { public class FileAssertion extends ObjectAssertion {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
public class FloatAssertion extends Assertion implements FloatAssertionInterface { public class FloatAssertion extends AbstractAssertion implements FloatAssertionInterface {
private float value; private float value;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
public interface FloatAssertionInterface extends AssertionInterface { public interface FloatAssertionInterface extends Assertion {
static FloatAssertionInterface floatAssertThat(float actual) { static FloatAssertionInterface floatAssertThat(float actual) {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
public class IntAssertion extends Assertion implements IntAssertionInterface { public class IntAssertion extends AbstractAssertion implements IntAssertionInterface {
private int value; private int value;
...@@ -20,7 +20,7 @@ public class IntAssertion extends Assertion implements IntAssertionInterface { ...@@ -20,7 +20,7 @@ public class IntAssertion extends Assertion implements IntAssertionInterface {
public static IntAssertion intAssertThat(int actual) { public static IntAssertion intAssertThat(int actual) {
new IntAssertion(actual); new IntAssertion(actual);
return (IntAssertion) Assertion.assertion(); return (IntAssertion) AbstractAssertion.assertion();
} }
/** /**
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
public interface IntAssertionInterface extends AssertionInterface { public interface IntAssertionInterface extends Assertion {
static IntAssertionInterface intAssertThat(int actual) { static IntAssertionInterface intAssertThat(int actual) {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
public class LongAssertion extends Assertion implements LongAssertionInterface { public class LongAssertion extends AbstractAssertion implements LongAssertionInterface {
private long value; private long value;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
package org.atlanmod.commons.assertions; package org.atlanmod.commons.assertions;
public interface LongAssertionInterface extends AssertionInterface { public interface LongAssertionInterface extends Assertion {
static LongAssertionInterface longAssertThat(long actual) { static LongAssertionInterface longAssertThat(long actual) {
return null; return null;
......
...@@ -18,7 +18,7 @@ import java.lang.reflect.Modifier; ...@@ -18,7 +18,7 @@ import java.lang.reflect.Modifier;
import java.util.Objects; import java.util.Objects;
public class ObjectAssertion<Myself extends ObjectAssertion<Myself, T>, T> public class ObjectAssertion<Myself extends ObjectAssertion<Myself, T>, T>
extends Assertion { extends AbstractAssertion {
final T actualValue; final T actualValue;
...@@ -33,7 +33,7 @@ public class ObjectAssertion<Myself extends ObjectAssertion<Myself, T>, T> ...@@ -33,7 +33,7 @@ public class ObjectAssertion<Myself extends ObjectAssertion<Myself, T>, T>
new ObjectAssertion(actual); new ObjectAssertion(actual);
return (ObjectAssertion) Assertion.assertion(); return (ObjectAssertion) AbstractAssertion.assertion();
} }
/** /**
......
...@@ -14,7 +14,7 @@ package org.atlanmod.commons.assertions; ...@@ -14,7 +14,7 @@ package org.atlanmod.commons.assertions;
* @param <Myself> the type of the subclass that extends ObjectAssertionInterface * @param <Myself> the type of the subclass that extends ObjectAssertionInterface
* @param <T> the type of the object being asserted * @param <T> the type of the object being asserted
*/ */
public interface ObjectAssertionInterface<Myself extends ObjectAssertionInterface, T> extends AssertionInterface { public interface ObjectAssertionInterface<Myself extends ObjectAssertionInterface, T> extends Assertion {
/** /**
* Checks if the assertion is true. * Checks if the assertion is true.
......
...@@ -17,13 +17,13 @@ import java.util.concurrent.TimeUnit; ...@@ -17,13 +17,13 @@ import java.util.concurrent.TimeUnit;
import static org.atlanmod.commons.Preconditions.requireThat; import static org.atlanmod.commons.Preconditions.requireThat;
import static org.atlanmod.commons.assertions.Assertion.*; import static org.atlanmod.commons.assertions.AbstractAssertion.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
/** /**
* This class contains tests for the Assertion classes and its various methods. * This class contains tests for the AbstractAssertion classes and its various methods.
* It tests the Assertion class for different types of data such as boolean, collections, comparable, double, float, int, long, object, and string. * It tests the AbstractAssertion class for different types of data such as boolean, collections, comparable, double, float, int, long, object, and string.
* It also tests the Assertion class for multi-threading scenarios. * It also tests the AbstractAssertion class for multi-threading scenarios.
* *
* @author naomod * @author naomod
*/ */
...@@ -31,36 +31,35 @@ import static org.junit.jupiter.api.Assertions.*; ...@@ -31,36 +31,35 @@ import static org.junit.jupiter.api.Assertions.*;
class AssertTest { class AssertTest {
/** /**
* Tests the Assertion class constructor and its `check` and `message` methods. * Tests the AbstractAssertion class constructor and its `check` and `message` methods.
* <p> * <p>
* It checks that a new Assertion object is created successfully and that its `check` method returns true. * It checks that a new AbstractAssertion object is created successfully and that its `check` method returns true.
* It also checks that the `message` method returns the expected message when called on a new Assertion object. * It also checks that the `message` method returns the expected message when called on a new AbstractAssertion object.
*/ */
@Test @Test
public void AssertionTest() { public void AssertionTest() {
assertTrue(new Assertion(1).check()); AbstractAssertion assertion = new AbstractAssertion(1) {};
assertTrue(assertion().message().equals(String.format("Assertion failures in thread %s : \n", Thread.currentThread().getName()))); assertTrue(assertion.check());
assertTrue(assertion().message().equals(String.format("AbstractAssertion failures in thread %s : \n", Thread.currentThread().getName())));
} }
/** /**
* Tests the Assertion class for boolean data. * Tests the AbstractAssertion class for boolean data.
* <p> * <p>
* It checks that the `isTrue` method returns true when called on a `true` boolean value. * It checks that the `isTrue` method returns true when called on a `true` boolean value.
* It also checks that the `isFalse` method returns true when called on a `false` boolean value. * It also checks that the `isFalse` method returns true when called on a `false` boolean value.
*/ */
@Test @Test
public void BooleanAssertionTest() { public void BooleanAssertionTest() {
assertTrue(assertThat(true).isTrue().check()); assertTrue(Assertions.assertThat(true).isTrue().check());
assertTrue(assertThat(false).isFalse().check()); assertTrue(Assertions.assertThat(false).isFalse().check());
} }
/** /**
* Tests the Assertion class for collection data. * Tests the AbstractAssertion class for collection data.
* <p> * <p>
* It checks that the `contains` method returns true when called on a collection that contains the specified element. * It checks that the `contains` method returns true when called on a collection that contains the specified element.
* It also checks that the `doesNotContain` method returns true when called on a collection that does not contain the specified element. * It also checks that the `doesNotContain` method returns true when called on a collection that does not contain the specified element.
...@@ -83,18 +82,18 @@ class AssertTest { ...@@ -83,18 +82,18 @@ class AssertTest {
set2.add(1); set2.add(1);
set2.add(2); set2.add(2);
assertTrue(assertThat(set).contains(1).check()); assertTrue(Assertions.assertThat(set).contains(1).check());
assertTrue(assertThat(set).doesNotContain(10).check()); assertTrue(Assertions.assertThat(set).doesNotContain(10).check());
assertTrue(assertThat(set).isNotEmpty().check()); assertTrue(Assertions.assertThat(set).isNotEmpty().check());
assertTrue(assertThat(set).contains(set2).check()); assertTrue(Assertions.assertThat(set).contains(set2).check());
assertTrue(assertThat(set2).doesNotContain(set).check()); assertTrue(Assertions.assertThat(set2).doesNotContain(set).check());
assertFalse(assertThat(set).isEmpty().check()); assertFalse(Assertions.assertThat(set).isEmpty().check());
} }
/** /**
* Tests the Assertion class for comparable data. * Tests the AbstractAssertion class for comparable data.
* <p> * <p>
* It checks that the `isGreaterThan` method returns true when called on a value greater than the specified value. * It checks that the `isGreaterThan` method returns true when called on a value greater than the specified value.
* It checks that the `isGreaterThanOrEqualTo` method returns true when called on a value greater than or equal to the specified value. * It checks that the `isGreaterThanOrEqualTo` method returns true when called on a value greater than or equal to the specified value.
...@@ -107,20 +106,20 @@ class AssertTest { ...@@ -107,20 +106,20 @@ class AssertTest {
Integer j = 1; Integer j = 1;
Integer k = 2; Integer k = 2;
assertTrue(assertThat(i).isEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isEqualTo(j).check());
assertTrue(assertThat(i).isNotEqualTo(k).check()); assertTrue(Assertions.assertThat(i).isNotEqualTo(k).check());
assertTrue(assertThat(i).isGreaterThan(-1).check()); assertTrue(Assertions.assertThat(i).isGreaterThan(-1).check());
assertTrue(assertThat(i).isGreaterOrEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isGreaterOrEqualTo(j).check());
assertTrue(assertThat(i).isLessThan(k).check()); assertTrue(Assertions.assertThat(i).isLessThan(k).check());
assertTrue(assertThat(i).isLessOrEqualTo(i).check()); assertTrue(Assertions.assertThat(i).isLessOrEqualTo(i).check());
assertTrue(assertThat(i).isIn(-10, 10).check()); assertTrue(Assertions.assertThat(i).isIn(-10, 10).check());
assertTrue(assertThat(i).isNotIn(-10, -5).check()); assertTrue(Assertions.assertThat(i).isNotIn(-10, -5).check());
} }
/** /**
* Tests the Assertion class for double data. * Tests the AbstractAssertion class for double data.
* <p> * <p>
* It checks that the `isEqualTo` method returns true when called on two double values that are equal within a certain tolerance. * It checks that the `isEqualTo` method returns true when called on two double values that are equal within a certain tolerance.
* It checks that the `isNotEqualTo` method returns true when called on two double values that are not equal within a certain tolerance. * It checks that the `isNotEqualTo` method returns true when called on two double values that are not equal within a certain tolerance.
...@@ -137,22 +136,22 @@ class AssertTest { ...@@ -137,22 +136,22 @@ class AssertTest {
double j = 1.0; double j = 1.0;
double k = 2.0; double k = 2.0;
assertTrue(assertThat(i).isEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isEqualTo(j).check());
assertTrue(assertThat(i).isNotEqualTo(k).check()); assertTrue(Assertions.assertThat(i).isNotEqualTo(k).check());
assertTrue(assertThat(i).isGreaterThan(-1).check()); assertTrue(Assertions.assertThat(i).isGreaterThan(-1).check());
assertTrue(assertThat(i).isGreaterOrEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isGreaterOrEqualTo(j).check());
assertTrue(assertThat(i).isLessThan(k).check()); assertTrue(Assertions.assertThat(i).isLessThan(k).check());
assertTrue(assertThat(i).isLessOrEqualTo(i).check()); assertTrue(Assertions.assertThat(i).isLessOrEqualTo(i).check());
assertTrue(assertThat(i).isIn(-10, 10).check()); assertTrue(Assertions.assertThat(i).isIn(-10, 10).check());
assertTrue(assertThat(i).isNotIn(-10, -5).check()); assertTrue(Assertions.assertThat(i).isNotIn(-10, -5).check());
assertTrue(assertThat(i).usingToleranceOf(10.0).isEqualTo(2.0).check()); assertTrue(Assertions.assertThat(i).usingToleranceOf(10.0).isEqualTo(2.0).check());
} }
/** /**
* Tests the Assertion class for float data. * Tests the AbstractAssertion class for float data.
* <p> * <p>
* It checks that the `isEqualTo` method returns true when called on two float values that are equal within a certain tolerance. * It checks that the `isEqualTo` method returns true when called on two float values that are equal within a certain tolerance.
* It checks that the `isNotEqualTo` method returns true when called on two float values that are not equal within a certain tolerance. * It checks that the `isNotEqualTo` method returns true when called on two float values that are not equal within a certain tolerance.
...@@ -169,22 +168,22 @@ class AssertTest { ...@@ -169,22 +168,22 @@ class AssertTest {
float j = 1.0f; float j = 1.0f;
float k = 2.0f; float k = 2.0f;
assertTrue(assertThat(i).isEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isEqualTo(j).check());
assertTrue(assertThat(i).isNotEqualTo(k).check()); assertTrue(Assertions.assertThat(i).isNotEqualTo(k).check());
assertTrue(assertThat(i).isGreaterThan(-1).check()); assertTrue(Assertions.assertThat(i).isGreaterThan(-1).check());
assertTrue(assertThat(i).isGreaterOrEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isGreaterOrEqualTo(j).check());
assertTrue(assertThat(i).isLessThan(k).check()); assertTrue(Assertions.assertThat(i).isLessThan(k).check());
assertTrue(assertThat(i).isLessOrEqualTo(i).check()); assertTrue(Assertions.assertThat(i).isLessOrEqualTo(i).check());
assertTrue(assertThat(i).isIn(-10, 10).check()); assertTrue(Assertions.assertThat(i).isIn(-10, 10).check());
assertTrue(assertThat(i).isNotIn(-10, -5).check()); assertTrue(Assertions.assertThat(i).isNotIn(-10, -5).check());
assertTrue(assertThat(i).usingToleranceOf(10.0f).isEqualTo(2.0f).check()); assertTrue(Assertions.assertThat(i).usingToleranceOf(10.0f).isEqualTo(2.0f).check());
} }
/** /**
* Tests the Assertion class for integer data. * Tests the AbstractAssertion class for integer data.
* <p> * <p>
* It checks that the `isEqualTo` method returns true when called on two integer values that are equal. * It checks that the `isEqualTo` method returns true when called on two integer values that are equal.
* It checks that the `isNotEqualTo` method returns true when called on two integer values that are not equal. * It checks that the `isNotEqualTo` method returns true when called on two integer values that are not equal.
...@@ -199,18 +198,18 @@ class AssertTest { ...@@ -199,18 +198,18 @@ class AssertTest {
int j = 1; int j = 1;
int k = 2; int k = 2;
assertTrue(assertThat(i).isEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isEqualTo(j).check());
assertTrue(assertThat(i).isNotEqualTo(k).check()); assertTrue(Assertions.assertThat(i).isNotEqualTo(k).check());
assertTrue(assertThat(i).isGreaterThan(-1).check()); assertTrue(Assertions.assertThat(i).isGreaterThan(-1).check());
assertTrue(assertThat(i).isGreaterOrEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isGreaterOrEqualTo(j).check());
assertTrue(assertThat(i).isLessThan(k).check()); assertTrue(Assertions.assertThat(i).isLessThan(k).check());
assertTrue(assertThat(i).isLessOrEqualTo(i).check()); assertTrue(Assertions.assertThat(i).isLessOrEqualTo(i).check());
assertTrue(assertThat(i).isIn(-10, 10).check()); assertTrue(Assertions.assertThat(i).isIn(-10, 10).check());
assertTrue(assertThat(i).isNotIn(-10, -5).check()); assertTrue(Assertions.assertThat(i).isNotIn(-10, -5).check());
} }
/** /**
* Tests the Assertion class for long integer data. * Tests the AbstractAssertion class for long integer data.
* <p> * <p>
* It checks that the `isEqualTo` method returns true when called on two long integer values that are equal. * It checks that the `isEqualTo` method returns true when called on two long integer values that are equal.
* It checks that the `isNotEqualTo` method returns true when called on two long integer values that are not equal. * It checks that the `isNotEqualTo` method returns true when called on two long integer values that are not equal.
...@@ -225,18 +224,18 @@ class AssertTest { ...@@ -225,18 +224,18 @@ class AssertTest {
long j = 1; long j = 1;
long k = 2; long k = 2;
assertTrue(assertThat(i).isEqualTo(j).check()); assertTrue(Assertions.assertThat(i).isEqualTo(j).check());
assertTrue(assertThat(i).isNotEqualTo(k).check()); assertTrue(Assertions.assertThat(i).isNotEqualTo(k).check());
assertTrue(assertThat(i).isGreaterThan(-1).check()); assertTrue(Assertions.assertThat(i).isGreaterThan(-1).check());
assertTrue(assertThat(i).isGreaterOrEqualThan(j).check()); assertTrue(Assertions.assertThat(i).isGreaterOrEqualThan(j).check());
assertTrue(assertThat(i).isLessThan(k).check()); assertTrue(Assertions.assertThat(i).isLessThan(k).check());
assertTrue(assertThat(i).isLessOrEqualThan(i).check()); assertTrue(Assertions.assertThat(i).isLessOrEqualThan(i).check());
assertTrue(assertThat(i).isIn(-10, 10).check()); assertTrue(Assertions.assertThat(i).isIn(-10, 10).check());
assertTrue(assertThat(i).isNotIn(-10, -5).check()); assertTrue(Assertions.assertThat(i).isNotIn(-10, -5).check());
} }
/** /**
* Tests the Assertion class for object data. * Tests the AbstractAssertion class for object data.
* <p> * <p>
* It checks that the `isEqualTo` method returns true when called on two objects that are equal. * It checks that the `isEqualTo` method returns true when called on two objects that are equal.
* It checks that the `isNotEqualTo` method returns true when called on two objects that are not equal. * It checks that the `isNotEqualTo` method returns true when called on two objects that are not equal.
...@@ -251,12 +250,12 @@ class AssertTest { ...@@ -251,12 +250,12 @@ class AssertTest {
Color obj4 = null; Color obj4 = null;
Color obj5 = obj1; Color obj5 = obj1;
assertTrue(assertThat(obj1).isEqualTo(obj2).check()); assertTrue(Assertions.assertThat(obj1).isEqualTo(obj2).check());
assertTrue(assertThat(obj1).isInstanceOf(Color.class).check()); assertTrue(Assertions.assertThat(obj1).isInstanceOf(Color.class).check());
assertTrue(assertThat(obj1).isNotEqualTo(obj3).check()); assertTrue(Assertions.assertThat(obj1).isNotEqualTo(obj3).check());
assertTrue(assertThat(obj1).isNotNull().check()); assertTrue(Assertions.assertThat(obj1).isNotNull().check());
assertTrue(assertThat(obj4).isNull().check()); assertTrue(Assertions.assertThat(obj4).isNull().check());
assertTrue(assertThat(obj1).isSameInstanceAs(obj5).check()); assertTrue(Assertions.assertThat(obj1).isSameInstanceAs(obj5).check());
} }
...@@ -269,28 +268,28 @@ class AssertTest { ...@@ -269,28 +268,28 @@ class AssertTest {
String str4 = "ab"; String str4 = "ab";
String str5 = "john-abe-the-third"; String str5 = "john-abe-the-third";
assertTrue(assertThat(str5).contains(str4).check()); assertTrue(Assertions.assertThat(str5).contains(str4).check());
assertTrue(assertThat(str1).doesNotcontain(str5).check()); assertTrue(Assertions.assertThat(str1).doesNotcontain(str5).check());
assertTrue(assertThat(str5).startsWith("john").check()); assertTrue(Assertions.assertThat(str5).startsWith("john").check());
assertTrue(assertThat(str5).endsWith("third").check()); assertTrue(Assertions.assertThat(str5).endsWith("third").check());
assertTrue(assertThat(str2).doesNotEndWith(str3).check()); assertTrue(Assertions.assertThat(str2).doesNotEndWith(str3).check());
assertTrue(assertThat(str2).doesNotStartWith(str3).check()); assertTrue(Assertions.assertThat(str2).doesNotStartWith(str3).check());
assertTrue(assertThat(str1).matches("a*").check()); assertTrue(Assertions.assertThat(str1).matches("a*").check());
assertTrue(assertThat(str1).doesNotMatch("b*").check()); assertTrue(Assertions.assertThat(str1).doesNotMatch("b*").check());
assertTrue(assertThat(str1).isNotEmpty().check()); assertTrue(Assertions.assertThat(str1).isNotEmpty().check());
assertFalse(assertThat(str1).isEmpty().check()); assertFalse(Assertions.assertThat(str1).isEmpty().check());
assertTrue(assertThat(str1).hasLength(2).check()); assertTrue(Assertions.assertThat(str1).hasLength(2).check());
assertTrue(assertThat(str1).hasLength(new Long(2)).check()); assertTrue(Assertions.assertThat(str1).hasLength(Long.valueOf(2)).check());
assertTrue(assertThat(str1).doesNotHaveLength(10).check()); assertTrue(Assertions.assertThat(str1).doesNotHaveLength(10).check());
assertTrue(assertThat(str1).doesNotHaveLength(new Long(20)).check()); assertTrue(Assertions.assertThat(str1).doesNotHaveLength(Long.valueOf(20)).check());
assertTrue(assertThat(str1).ignoringCase().contains(str3).check()); assertTrue(Assertions.assertThat(str1).ignoringCase().contains(str3).check());
assertTrue(assertThat(str1).ignoringCase().startsWith("a").check()); assertTrue(Assertions.assertThat(str1).ignoringCase().startsWith("a").check());
assertTrue(assertThat(str1).ignoringCase().endsWith("A").check()); assertTrue(Assertions.assertThat(str1).ignoringCase().endsWith("A").check());
assertTrue(assertThat(str1).ignoringCase().doesNotcontain(str5).check()); assertTrue(Assertions.assertThat(str1).ignoringCase().doesNotcontain(str5).check());
assertTrue(assertThat(str2).ignoringCase().doesNotEndWith(str5).check()); assertTrue(Assertions.assertThat(str2).ignoringCase().doesNotEndWith(str5).check());
assertTrue(assertThat(str2).ignoringCase().doesNotStartWith(str5).check()); assertTrue(Assertions.assertThat(str2).ignoringCase().doesNotStartWith(str5).check());
} }
...@@ -307,14 +306,14 @@ class AssertTest { ...@@ -307,14 +306,14 @@ class AssertTest {
Thread thread1 = new Thread(() -> { Thread thread1 = new Thread(() -> {
Integer a = 7; Integer a = 7;
Integer b = 10; Integer b = 10;
assert assertThat(a).isNull().isEqualTo(b).check() : assertion().message(); assert Assertions.assertThat(a).isNull().isEqualTo(b).check() : assertion().message();
}); });
Thread thread2 = new Thread(() -> { Thread thread2 = new Thread(() -> {
Integer a = 7; Integer a = 7;
Integer b = 10; Integer b = 10;
assert assertThat(a).isInstanceOf(Long.TYPE).isNull().isEqualTo(b).check() : assertion().message(); assert Assertions.assertThat(a).isInstanceOf(Long.TYPE).isNull().isEqualTo(b).check() : assertion().message();
System.out.println("thread2"); System.out.println("thread2");
}); });
...@@ -357,10 +356,10 @@ class AssertTest { ...@@ -357,10 +356,10 @@ class AssertTest {
String msg = exceptions.get(thread1).getMessage(); String msg = exceptions.get(thread1).getMessage();
msg += exceptions.get(thread2).getMessage(); msg += exceptions.get(thread2).getMessage();
assertEquals("Assertion failures in thread " + thread1.getName() + " : \n" + assertEquals("AbstractAssertion failures in thread " + thread1.getName() + " : \n" +
"\n" + "\n" +
"Expecting value (7) to be null ()\n" + "Expecting value (7) to be null ()\n" +
"Expecting value (7) to be 10 ()Assertion failures in thread " + thread2.getName() + " : \n" + "Expecting value (7) to be 10 ()AbstractAssertion failures in thread " + thread2.getName() + " : \n" +
"\n" + "\n" +
"Expecting 7 to an instance of java.lang.Class , but it is an instance of (java.lang.Integer)\n" + "Expecting 7 to an instance of java.lang.Class , but it is an instance of (java.lang.Integer)\n" +
"Expecting value (7) to be null ()\n" + "Expecting value (7) to be null ()\n" +
......
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