]> git.basschouten.com Git - openhab-addons.git/blob
7c8dc53e66c9de67d1ae7019c9f61ddb26461d52
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.voice.voicerss.internal;
14
15 import org.hamcrest.Description;
16 import org.hamcrest.Matcher;
17 import org.hamcrest.TypeSafeMatcher;
18 import org.openhab.core.audio.AudioFormat;
19
20 /**
21  * Hamcrest {@link Matcher} to assert a compatible {@link AudioFormat}.
22  *
23  * @author Andreas Brenk - Initial contribution
24  */
25 public class CompatibleAudioFormatMatcher extends TypeSafeMatcher<AudioFormat> {
26
27     private final AudioFormat audioFormat;
28
29     public CompatibleAudioFormatMatcher(AudioFormat audioFormat) {
30         this.audioFormat = audioFormat;
31     }
32
33     @Override
34     protected boolean matchesSafely(AudioFormat actual) {
35         return audioFormat.isCompatible(actual);
36     }
37
38     @Override
39     public void describeTo(Description description) {
40         description.appendText("an audio format compatible to ").appendValue(audioFormat);
41     }
42
43     /**
44      * Creates a matcher that matches when the examined object is
45      * compatible to the specified <code>audioFormat</code>.
46      *
47      * @param audioFormat the audio format which must be compatible
48      */
49     public static Matcher<AudioFormat> compatibleAudioFormat(AudioFormat audioFormat) {
50         return new CompatibleAudioFormatMatcher(audioFormat);
51     }
52 }