Interface ToStringContract<T>

Type Parameters:
T - The type being tested.
All Superinterfaces:
ContractSupport<T>, ProviderSupport<T>, SupportedMethods
All Known Subinterfaces:
CollectionContract<E,C>, IterableContract<E,I>, ListContract<E,L>, ObjectContract<T>, SequencedCollectionContract<E,C>, WithString

public interface ToStringContract<T> extends ContractSupport<T>

This interface tests if a class has implemented the toString() method correctly. This contract class can be used individually by a test class, but it is normally used through the ObjectContract class:

public class MyClassTest extends ObjectContract<MyClass> {
}

If a test is using the ObjectContract class, but the class being tested does not implement the toString method based upon the specification in the Object class, then it can be omitted from the tests using the doesNotSupportMethod() method:

public class MyClassTest extends ObjectContract<MyClass> {
    public MyClassTest() {
        doesNotSupportMethod(ObjectMethods.ToString);
    }
}
Since:
1.0
Author:
evanbergstrom
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Tests that the toString() method returns different values for instances that are not equal.
    default void
    Tests that the toString() method returns the same value for two strings that are equal.
    default void
    Tests that the toString() method consistently returns the same string value over multiple invocations on the same instance.
    default void
    Tests that the toString() method has been overridden.

    Methods inherited from interface org.soliscode.test.contract.support.ProviderSupport

    provider

    Methods inherited from interface org.soliscode.test.SupportedMethods

    supportsMethod
  • Method Details

    • testToStringIsConsistent

      @Test default void testToStringIsConsistent()
      Tests that the toString() method consistently returns the same string value over multiple invocations on the same instance.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also:
    • testToStringForEqualValues

      @Test default void testToStringForEqualValues()
      Tests that the toString() method returns the same value for two strings that are equal.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also:
    • testToStringForDifferentValues

      @Test default void testToStringForDifferentValues()
      Tests that the toString() method returns different values for instances that are not equal.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also:
    • testToStringOverridden

      @Test default void testToStringOverridden()
      Tests that the toString() method has been overridden.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also: