Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 2d4d5d54 rédigé par Theo ARGA's avatar Theo ARGA
Parcourir les fichiers

Merge branch 'master' of gitlab.univ-nantes.fr:atlanmod/commons

parents 2222c2ca b59764f6
Branches
Aucune étiquette associée trouvée
1 requête de fusion!3Added mising documentation on methods & use of the licence plugin for maven
Affichage de
avec 271 ajouts et 265 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 PATTERN_FALSE = "\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,208 +8,22 @@ ...@@ -8,208 +8,22 @@
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.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/** /**
* 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 {
/**
* 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)";
/**
* A map of Assertion objects associated with each thread.
*/
public static ConcurrentMap<Thread, Assertion> assertions = new ConcurrentHashMap<>();
final Object actualValue;
/**
* The result of the assertion check.
*/
protected boolean check;
/**
* The message associated with the assertion.
*/
protected String message;
/**
* 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 a BooleanAssertion object for performing assertions on boolean values. * Returns the assertion message.
* *
* @param actual the actual value of the variable * @return the assertion message
*/ */
public static BooleanAssertion assertThat(boolean actual) { String message();
return BooleanAssertion.boolAssertThat(actual);
}
/** /**
* Returns an IntAssertion object for performing assertions on int values. * Returns true if the assertion passed, false otherwise.
*
* @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);
}
/**
* 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);
}
/**
* 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 * @return true if the assertion passed, false otherwise
*/ */
public boolean check() { 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,51 +8,149 @@ ...@@ -8,51 +8,149 @@
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 {
/** /**
* Indicates whether assertions are enabled or not. * Ensure that assertions are enabled using {@code -ea} flag in the JVM
* <p>
* Assertions must be enabled using the {@code -ea} flag in the JVM.
*/ */
public static boolean isActive = false; public static boolean isActive = false;
/**
* An invariant that always returns false.
* <p>
* This invariant is used when assertions are disabled.
*/
public static Invariant NULL_INVARIANT = new NullInvariant(); public static Invariant NULL_INVARIANT = new NullInvariant();
static { static {
// Ensure that assertions are enabled
assert (Assertions.isActive = true); assert (Assertions.isActive = true);
} }
public static <T> Invariant<T> createInv(Predicate<T> predicate) {
return isActive ? obj -> predicate.test(obj) : NULL_INVARIANT;
}
/** /**
* Creates an invariant from a predicate. * Returns a BooleanAssertion object for performing assertions on boolean values.
* <p>
* If assertions are enabled, the invariant will test the predicate on the given object.
* If assertions are disabled, the invariant will always return false.
* *
* @param predicate the predicate to create the invariant from * @param actual the actual value of the variable
* @param <T> the type of the object to test the invariant on
* @return an invariant that tests the predicate on the given object
*/ */
public static <T> Invariant<T> createInv(Predicate<T> predicate) { public static BooleanAssertion assertThat(boolean actual) {
return isActive ? obj -> predicate.test(obj) : NULL_INVARIANT; return BooleanAssertion.boolAssertThat(actual);
} }
/** /**
* An invariant that always returns false. * Returns an IntAssertion object for performing assertions on int values.
* <p> *
* This invariant is used when assertions are disabled. * @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);
}
/**
* 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 {
@Override @Override
public boolean test(Object obj) { public boolean test(Object obj) {
return false; return false;
} }
} }
} }
...@@ -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 final double value; private final double value;
...@@ -76,7 +76,7 @@ public class DoubleAssertion extends Assertion implements DoubleAssertionInterfa ...@@ -76,7 +76,7 @@ public class DoubleAssertion extends Assertion implements DoubleAssertionInterfa
public DoubleAssertionInterface isNotEqualTo(double expected) { public DoubleAssertionInterface isNotEqualTo(double expected) {
if (thresholdCompare(value, expected)) { if (thresholdCompare(value, expected)) {
check = false; check = false;
message += String.format(PATTERNFALSE, value, expected, ("within tolerance : " + tolerance)); message += String.format(PATTERN_FALSE, value, expected, ("within tolerance : " + tolerance));
} }
return this; return this;
} }
......
...@@ -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 final float value; private final float value;
...@@ -76,7 +76,7 @@ public class FloatAssertion extends Assertion implements FloatAssertionInterface ...@@ -76,7 +76,7 @@ public class FloatAssertion extends Assertion implements FloatAssertionInterface
public FloatAssertionInterface isNotEqualTo(float expected) { public FloatAssertionInterface isNotEqualTo(float expected) {
if (thresholdCompare(value, expected)) { if (thresholdCompare(value, expected)) {
check = false; check = false;
message += String.format(PATTERNFALSE, value, expected, ("within tolerance : " + tolerance)); message += String.format(PATTERN_FALSE, value, expected, ("within tolerance : " + tolerance));
} }
......
...@@ -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 final int value; private final 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 final long value; private final 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;
...@@ -37,7 +37,7 @@ public class ObjectAssertion<Myself extends ObjectAssertion<Myself, T>, T> ...@@ -37,7 +37,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.
......
...@@ -15,15 +15,14 @@ import java.util.HashMap; ...@@ -15,15 +15,14 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.atlanmod.commons.Preconditions.requireThat; import static org.atlanmod.commons.assertions.AbstractAssertion.assertion;
import static org.atlanmod.commons.assertions.Assertions.assertThat;
import static org.atlanmod.commons.assertions.Assertion.*;
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,22 +30,22 @@ import static org.junit.jupiter.api.Assertions.*; ...@@ -31,22 +30,22 @@ 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) {
assertEquals(assertion().message(), 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.
...@@ -60,7 +59,7 @@ class AssertTest { ...@@ -60,7 +59,7 @@ class AssertTest {
/** /**
* 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.
...@@ -94,7 +93,7 @@ class AssertTest { ...@@ -94,7 +93,7 @@ class AssertTest {
} }
/** /**
* 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.
...@@ -120,7 +119,7 @@ class AssertTest { ...@@ -120,7 +119,7 @@ class AssertTest {
} }
/** /**
* 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.
...@@ -152,7 +151,7 @@ class AssertTest { ...@@ -152,7 +151,7 @@ class AssertTest {
} }
/** /**
* 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.
...@@ -184,7 +183,7 @@ class AssertTest { ...@@ -184,7 +183,7 @@ class AssertTest {
} }
/** /**
* 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.
...@@ -210,7 +209,7 @@ class AssertTest { ...@@ -210,7 +209,7 @@ class AssertTest {
} }
/** /**
* 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.
...@@ -236,7 +235,7 @@ class AssertTest { ...@@ -236,7 +235,7 @@ class AssertTest {
} }
/** /**
* 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.
...@@ -357,14 +356,7 @@ class AssertTest { ...@@ -357,14 +356,7 @@ 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" + "Expecting value (7) to be null ()\n" + "Expecting value (7) to be 10 ()AbstractAssertion failures in thread " + thread2.getName() + " : \n" + "\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 10 ()", msg);
"\n" +
"Expecting value (7) to be null ()\n" +
"Expecting value (7) to be 10 ()Assertion failures in thread " + thread2.getName() + " : \n" +
"\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 10 ()", msg);
} }
} }
......
...@@ -12,7 +12,7 @@ package org.atlanmod.commons.assertions; ...@@ -12,7 +12,7 @@ package org.atlanmod.commons.assertions;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.atlanmod.commons.assertions.Assertion.assertThat; import static org.atlanmod.commons.assertions.Assertions.assertThat;
import static org.atlanmod.commons.assertions.BidirectionalAssertion.assertThatAssociation; import static org.atlanmod.commons.assertions.BidirectionalAssertion.assertThatAssociation;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter