Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: db2451f86fcf4be5b8699e4a229ad288df25b038 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*******************************************************************************
 * Copyright (c) 2012 SAP AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    SAP AG - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.publisher.actions;

import org.eclipse.core.runtime.IStatus;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.internal.matchers.TypeSafeMatcher;

public class StatusMatchers {

	public static Matcher<IStatus> errorStatus() {
		return new TypeSafeMatcher<IStatus>() {

			public void describeTo(Description description) {
				description.appendText("a status with severity ERROR");
			}

			@Override
			public boolean matchesSafely(IStatus item) {
				return item.matches(IStatus.ERROR);
			}
		};
	}

	public static Matcher<IStatus> statusWithMessageWhich(final Matcher<String> messageMatcher) {
		return new TypeSafeMatcher<IStatus>() {

			public void describeTo(Description description) {
				description.appendText("a status with a message which is ");
				description.appendDescriptionOf(messageMatcher);
			}

			@Override
			public boolean matchesSafely(IStatus item) {
				return messageMatcher.matches(item.getMessage());
			}
		};
	}

}

Back to the top