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

org.fuwjin.util.AssertThat Maven / Gradle / Ivy

package org.fuwjin.util;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

public abstract class AssertThat {
   public class Assertion {
      private final T cause;

      public Assertion(final T cause) {
         this.cause = cause;
      }

      public Assertion withMessage(final String message) {
         assertEquals(message, cause.getMessage());
         return this;
      }
   }

   public abstract void when() throws Throwable;

   public Assertion willThrow(final Class exception) {
      X cause = null;
      try {
         when();
      } catch(final Throwable e) {
         assertThat(e, is(exception));
         cause = exception.cast(e);
      }
      assertNotNull("Operation completed successfully", cause);
      return new Assertion(cause);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy