parent
cad5f6716f
commit
662eef14da
@ -0,0 +1,98 @@
|
||||
package com.smartlibrary.voice;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@DisplayName("语音服务测试")
|
||||
class VoiceServiceTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("测试XunFeiConfig默认配置")
|
||||
void testXunFeiConfigDefault() {
|
||||
XunFeiConfig config = new XunFeiConfig();
|
||||
assertNotNull(config.getAppId());
|
||||
assertNotNull(config.getApiKey());
|
||||
assertNotNull(config.getApiSecret());
|
||||
assertTrue(config.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试XunFeiConfig自定义配置")
|
||||
void testXunFeiConfigCustom() {
|
||||
XunFeiConfig config = new XunFeiConfig("testApp", "testKey", "testSecret");
|
||||
assertEquals("testApp", config.getAppId());
|
||||
assertEquals("testKey", config.getApiKey());
|
||||
assertEquals("testSecret", config.getApiSecret());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试XunFeiConfig从文件加载")
|
||||
void testXunFeiConfigLoadFromFile() {
|
||||
XunFeiConfig config = XunFeiConfig.loadFromFile();
|
||||
assertNotNull(config);
|
||||
assertTrue(config.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试VoiceException异常")
|
||||
void testVoiceException() {
|
||||
VoiceException ex = new VoiceException("测试错误");
|
||||
assertEquals("测试错误", ex.getMessage());
|
||||
|
||||
Exception cause = new RuntimeException("原因");
|
||||
VoiceException ex2 = new VoiceException("带原因的错误", cause);
|
||||
assertEquals("带原因的错误", ex2.getMessage());
|
||||
assertEquals(cause, ex2.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试XunFeiSpeechService实例化")
|
||||
void testXunFeiSpeechServiceInstance() {
|
||||
XunFeiSpeechService service = new XunFeiSpeechService();
|
||||
assertNotNull(service);
|
||||
assertFalse(service.isRecording());
|
||||
assertFalse(service.isPlaying());
|
||||
service.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试录音支持检测")
|
||||
void testRecordingSupported() {
|
||||
// 只测试方法能正常调用,不依赖硬件
|
||||
boolean supported = XunFeiSpeechService.isRecordingSupported();
|
||||
// 结果取决于系统是否有麦克风
|
||||
assertTrue(supported || !supported);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试语音识别空数据处理")
|
||||
void testIATEmptyData() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
XunFeiIATService.recognize(null);
|
||||
});
|
||||
|
||||
assertThrows(Exception.class, () -> {
|
||||
XunFeiIATService.recognize(new byte[100]);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试TTS空文本不抛异常")
|
||||
void testTTSEmptyText() {
|
||||
XunFeiSpeechService service = new XunFeiSpeechService();
|
||||
// 空文本应该触发回调错误,不抛异常
|
||||
service.speak(null);
|
||||
service.speak("");
|
||||
service.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("测试XunFeiConfig toString")
|
||||
void testXunFeiConfigToString() {
|
||||
XunFeiConfig config = new XunFeiConfig();
|
||||
String str = config.toString();
|
||||
assertNotNull(str);
|
||||
assertTrue(str.contains("XunFeiConfig"));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue