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

net.sf.cotta.test.assertion.CodeBlockAssert Maven / Gradle / Ivy

The newest version!
package net.sf.cotta.test.assertion;

import org.junit.Assert;

public class CodeBlockAssert {
  protected CodeBlock block;

  public CodeBlockAssert(CodeBlock block) {
    this.block = block;
  }

  public  ExceptionAssert throwsException(Class expected) {
    try {
      block.execute();
    } catch (Throwable e) {
      if (expected.equals(e.getClass())) {
        return new ExceptionAssert(e);
      }
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      } else {
        throw new RuntimeException("Error occurred during code block:" + e.getMessage(), e);
      }
    }
    StringBuilder buffer = new StringBuilder("Exception should have been thrown: " + expected);
    Assert.fail(buffer.toString());
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy