All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.j8unit.StringBasedCharSequence Maven / Gradle / Ivy

Go to download

The core components of J8Unit, i.e., extended test class model, runner classes, additional assertion methods ...

The newest version!
package org.j8unit;

/**
 * 

* Default implementation of the {@link CharSequence} interface by simply reusing the result of {@link #toString()}. * * Its main intention is to allow small fail message enumerations to be used in conjunction with the assertion methods * of {@link Assert}: * *

 * package mypackage;
 * import static mypackage.FailMessages.*;
 * import static org.j8unit.Assert.*;
 * import org.junit.Test;
 *
 * public class MyTest {
 *
 *     static enum FailMessages
 *     implements StringBasedCharSequence {
 *         NULL("illegal null string"),
 *         LENGTH("string has illegal length"),
 *         INVALID("malformed java identifier string"),
 *         // ... FURTHER FAIL MESSAGES HERE ...;
 *
 *         private final String msg;
 *         private FailMessages(final String msg) { this.msg = msg; }
 *         public String toString() { return this.msg; }
 *     }
 *
 *     @Test
 *     public void testNotNullString()
 *     throws Exception {
 *         final String s = "...";
 *         assertNotNull(NULL, s);
 *     }
 *
 *     // ... FURTHER TESTS HERE ...
 *
 * }
 * 
*

* * @since 4.12.1 */ public abstract interface StringBasedCharSequence extends CharSequence { /** * @implSpec The default implementation refers to {@link String#subSequence(int, int)} of the {@link #toString()} * result. * @implSpec The default implementation will throw a {@link NullPointerException} if the result of * {@link #toString()} is {@code null}. */ @Override public default CharSequence subSequence(final int start, final int end) { return toString().subSequence(start, end); } /** * @implSpec The default implementation refers to {@link String#length()} of the {@link #toString()} result. * @implSpec The default implementation will throw a {@link NullPointerException} if the result of * {@link #toString()} is {@code null}. */ @Override public default int length() { return toString().length(); } /** * @implSpec The default implementation refers to {@link String#charAt(int)} of the {@link #toString()} result. * @implSpec The default implementation will throw a {@link NullPointerException} if the result of * {@link #toString()} is {@code null}. */ @Override public default char charAt(final int index) { return toString().charAt(index); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy