This repository has been archived by the owner on May 7, 2020. It is now read-only.
/
SinkStub.java
98 lines (83 loc) · 2.94 KB
/
SinkStub.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Copyright (c) 2014,2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.smarthome.core.voice.internal;
import java.io.IOException;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.smarthome.core.audio.AudioFormat;
import org.eclipse.smarthome.core.audio.AudioSink;
import org.eclipse.smarthome.core.audio.AudioStream;
import org.eclipse.smarthome.core.audio.UnsupportedAudioFormatException;
import org.eclipse.smarthome.core.library.types.PercentType;
/**
* An {@link AudioSink} stub used for the tests. Since the tests do not cover all the voice's features,
* some of the methods are not needed. That's why their implementation is left empty.
*
* @author Mihaela Memova - initial contribution
* @author Velin Yordanov - migrated from groovy to java
* @author Christoph Weitkamp - Added parameter to adjust the volume
*
*/
public class SinkStub implements AudioSink {
private boolean isStreamProcessed;
private PercentType volume;
private static final Set<AudioFormat> SUPPORTED_AUDIO_FORMATS = Collections
.unmodifiableSet(Stream.of(AudioFormat.MP3, AudioFormat.WAV).collect(Collectors.toSet()));
private static final Set<Class<? extends AudioStream>> SUPPORTED_AUDIO_STREAMS = Collections
.singleton(AudioStream.class);
private static final String SINK_STUB_ID = "sinkStubID";
private static final String SINK_STUB_LABEL = "sinkStubLabel";
@Override
public String getId() {
return SINK_STUB_ID;
}
@Override
public String getLabel(Locale locale) {
return SINK_STUB_LABEL;
}
public boolean getIsStreamProcessed() {
return isStreamProcessed;
}
@Override
public void process(AudioStream audioStream) throws UnsupportedAudioFormatException {
isStreamProcessed = true;
}
@Override
public Set<AudioFormat> getSupportedFormats() {
return SUPPORTED_AUDIO_FORMATS;
}
@Override
public PercentType getVolume() throws IOException {
// this method will no be used in the tests
return volume;
}
@Override
public void setVolume(PercentType volume) throws IOException {
// this method will not be used in the tests
this.volume = volume;
}
public boolean isStreamProcessed() {
return isStreamProcessed;
}
@Override
public String toString() {
return getId();
}
@Override
public Set<Class<? extends AudioStream>> getSupportedStreams() {
return SUPPORTED_AUDIO_STREAMS;
}
}