/* * Copyright (c) 2015 - present Facebook, Inc. * All rights reserved. */ package utils.matchers; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; import java.util.ArrayList; import java.util.List; import utils.InferResults; public class ResultContainsExactly extends BaseMatcher { Matcher containsAll; Matcher containsOnly; private ResultContainsExactly(List patterns) { containsAll = ResultContainsTheseErrors.contains(patterns); containsOnly = ResultContainsOnlyTheseErrors.containsOnly(patterns); } @Override public boolean matches(Object o) { return containsAll.matches(o) && containsOnly.matches(o); } @Override public void describeTo(Description description) { containsAll.describeTo(description); } @Override public void describeMismatch(Object item, Description description) { if (!containsAll.matches(item)) { containsAll.describeMismatch(item, description); } if (!containsOnly.matches(item)) { containsOnly.describeMismatch(item, description); } } public static Matcher containsExactly(List patterns) { return new ResultContainsExactly(patterns); } public static Matcher containsExactly( String type, String file, String[] methods) { ArrayList patterns = new ArrayList<>(); for (String method : methods) { patterns.add(new ErrorPattern(type, file, method)); } return new ResultContainsExactly(patterns); } }