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

org.mule.functional.junit4.matchers.ThrowableExceptionInfoMatcher Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */
package org.mule.functional.junit4.matchers;

import org.mule.runtime.api.exception.MuleException;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import java.util.Map;

/**
 * Matcher to check the additional {@code info} of a MuleException.
 *
 * @param  the type of {@link MuleException} to match
 */
public class ThrowableExceptionInfoMatcher extends TypeSafeMatcher {

  private Matcher> matcher;

  public ThrowableExceptionInfoMatcher(Matcher> matcher) {
    this.matcher = matcher;
  }

  @Override
  protected boolean matchesSafely(T item) {
    return matcher.matches(item.getInfo());
  }

  @Override
  public void describeTo(Description description) {
    description.appendText("exception with info ");
    description.appendDescriptionOf(matcher);
  }

  @Factory
  public static  Matcher hasInfo(final Matcher> matcher) {
    return new ThrowableExceptionInfoMatcher<>(matcher);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy