Migrate tests to JUnit 5 (#8519)
Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -12,14 +12,15 @@
|
||||
*/
|
||||
package org.openhab.voice.mactts.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -36,8 +37,8 @@ public class MacTTSVoiceTest {
|
||||
* Test MacTTSVoice(String) constructor
|
||||
*/
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
public void testConstructor() throws IOException {
|
||||
assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("say -v ?");
|
||||
@@ -46,9 +47,7 @@ public class MacTTSVoiceTest {
|
||||
|
||||
String nextLine = bufferedReader.readLine();
|
||||
MacTTSVoice voiceMacOS = new MacTTSVoice(nextLine);
|
||||
Assert.assertNotNull("The MacTTSVoice(String) constructor failed", voiceMacOS);
|
||||
} catch (IOException e) {
|
||||
Assert.fail("testConstructor() failed with IOException: " + e.getMessage());
|
||||
assertNotNull(voiceMacOS, "The MacTTSVoice(String) constructor failed");
|
||||
} finally {
|
||||
IOUtils.closeQuietly(bufferedReader);
|
||||
}
|
||||
@@ -58,8 +57,8 @@ public class MacTTSVoiceTest {
|
||||
* Test VoiceMacOS.getUID()
|
||||
*/
|
||||
@Test
|
||||
public void getUIDTest() {
|
||||
Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
public void getUIDTest() throws IOException {
|
||||
assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("say -v ?");
|
||||
@@ -68,10 +67,7 @@ public class MacTTSVoiceTest {
|
||||
|
||||
String nextLine = bufferedReader.readLine();
|
||||
MacTTSVoice macTTSVoice = new MacTTSVoice(nextLine);
|
||||
Assert.assertTrue("The VoiceMacOS UID has an incorrect format",
|
||||
(0 == macTTSVoice.getUID().indexOf("mactts:")));
|
||||
} catch (IOException e) {
|
||||
Assert.fail("getUIDTest() failed with IOException: " + e.getMessage());
|
||||
assertTrue(0 == macTTSVoice.getUID().indexOf("mactts:"), "The VoiceMacOS UID has an incorrect format");
|
||||
} finally {
|
||||
IOUtils.closeQuietly(bufferedReader);
|
||||
}
|
||||
@@ -81,8 +77,8 @@ public class MacTTSVoiceTest {
|
||||
* Test MacTTSVoice.getLabel()
|
||||
*/
|
||||
@Test
|
||||
public void getLabelTest() {
|
||||
Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
public void getLabelTest() throws IOException {
|
||||
assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("say -v ?");
|
||||
@@ -91,9 +87,7 @@ public class MacTTSVoiceTest {
|
||||
|
||||
String nextLine = bufferedReader.readLine();
|
||||
MacTTSVoice voiceMacOS = new MacTTSVoice(nextLine);
|
||||
Assert.assertNotNull("The MacTTSVoice label has an incorrect format", voiceMacOS.getLabel());
|
||||
} catch (IOException e) {
|
||||
Assert.fail("getLabelTest() failed with IOException: " + e.getMessage());
|
||||
assertNotNull(voiceMacOS.getLabel(), "The MacTTSVoice label has an incorrect format");
|
||||
} finally {
|
||||
IOUtils.closeQuietly(bufferedReader);
|
||||
}
|
||||
@@ -103,8 +97,8 @@ public class MacTTSVoiceTest {
|
||||
* Test MacTTSVoice.getLocale()
|
||||
*/
|
||||
@Test
|
||||
public void getLocaleTest() {
|
||||
Assume.assumeTrue("Mac OS X" == System.getProperty("os.name"));
|
||||
public void getLocaleTest() throws IOException {
|
||||
assumeTrue("Mac OS X" == System.getProperty("os.name"));
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("say -v ?");
|
||||
@@ -113,9 +107,7 @@ public class MacTTSVoiceTest {
|
||||
|
||||
String nextLine = bufferedReader.readLine();
|
||||
MacTTSVoice voiceMacOS = new MacTTSVoice(nextLine);
|
||||
Assert.assertNotNull("The MacTTSVoice locale has an incorrect format", voiceMacOS.getLocale());
|
||||
} catch (IOException e) {
|
||||
Assert.fail("getLocaleTest() failed with IOException: " + e.getMessage());
|
||||
assertNotNull(voiceMacOS.getLocale(), "The MacTTSVoice locale has an incorrect format");
|
||||
} finally {
|
||||
IOUtils.closeQuietly(bufferedReader);
|
||||
}
|
||||
|
||||
@@ -12,12 +12,13 @@
|
||||
*/
|
||||
package org.openhab.voice.mactts.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.core.audio.AudioFormat;
|
||||
import org.openhab.core.audio.AudioStream;
|
||||
import org.openhab.core.voice.TTSException;
|
||||
@@ -35,10 +36,10 @@ public class TTSServiceMacOSTest {
|
||||
*/
|
||||
@Test
|
||||
public void getAvailableVoicesTest() {
|
||||
Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
|
||||
MacTTSService ttsServiceMacOS = new MacTTSService();
|
||||
Assert.assertFalse("The getAvailableVoicesTest() failed", ttsServiceMacOS.getAvailableVoices().isEmpty());
|
||||
assertFalse(ttsServiceMacOS.getAvailableVoices().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,34 +47,28 @@ public class TTSServiceMacOSTest {
|
||||
*/
|
||||
@Test
|
||||
public void getSupportedFormatsTest() {
|
||||
Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
|
||||
MacTTSService ttsServiceMacOS = new MacTTSService();
|
||||
Assert.assertFalse("The getSupportedFormatsTest() failed", ttsServiceMacOS.getSupportedFormats().isEmpty());
|
||||
assertFalse(ttsServiceMacOS.getSupportedFormats().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test TTSServiceMacOS.synthesize(String,Voice,AudioFormat)
|
||||
*/
|
||||
@Test
|
||||
public void synthesizeTest() {
|
||||
Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
public void synthesizeTest() throws IOException, TTSException {
|
||||
assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
|
||||
|
||||
MacTTSService ttsServiceMacOS = new MacTTSService();
|
||||
Set<Voice> voices = ttsServiceMacOS.getAvailableVoices();
|
||||
Set<AudioFormat> audioFormats = ttsServiceMacOS.getSupportedFormats();
|
||||
try (AudioStream audioStream = ttsServiceMacOS.synthesize("Hello", voices.iterator().next(),
|
||||
audioFormats.iterator().next())) {
|
||||
Assert.assertNotNull("The test synthesizeTest() created null AudioSource", audioStream);
|
||||
Assert.assertNotNull("The test synthesizeTest() created an AudioSource w/o AudioFormat",
|
||||
audioStream.getFormat());
|
||||
Assert.assertNotNull("The test synthesizeTest() created an AudioSource w/o InputStream", audioStream);
|
||||
Assert.assertTrue("The test synthesizeTest() returned an AudioSource with no data",
|
||||
(-1 != audioStream.read(new byte[2])));
|
||||
} catch (TTSException e) {
|
||||
Assert.fail("synthesizeTest() failed with TTSException: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Assert.fail("synthesizeTest() failed with IOException: " + e.getMessage());
|
||||
assertNotNull(audioStream, "created null AudioSource");
|
||||
assertNotNull(audioStream.getFormat(), "created an AudioSource w/o AudioFormat");
|
||||
assertNotNull(audioStream, "created an AudioSource w/o InputStream");
|
||||
assertTrue(-1 != audioStream.read(new byte[2]), "returned an AudioSource with no data");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user