Skip to content

Commit 8051728

Browse files
committed
added test file
1 parent 00f367a commit 8051728

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

speech/grpc/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ limitations under the License.
111111

112112
<!-- // [START dependency] -->
113113
<dependencies>
114+
<dependency>
115+
<groupId>junit</groupId>
116+
<artifactId>junit</artifactId>
117+
<version>4.12</version>
118+
<scope>test</scope>
119+
</dependency>
114120
<dependency>
115121
<groupId>commons-cli</groupId>
116122
<artifactId>commons-cli</artifactId>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.speech.grpc.demos;
18+
19+
import com.google.cloud.speech.v1.AudioRequest;
20+
import static org.junit.Assert.assertSame;
21+
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.junit.runners.JUnit4;
26+
27+
import java.io.IOException;
28+
import java.net.URI;
29+
import java.nio.file.Path;
30+
import java.nio.file.Paths;
31+
import java.util.List;
32+
33+
/**
34+
* Unit tests for {@link AudioRequestFactory}.
35+
*/
36+
@RunWith(JUnit4.class)
37+
public class AudioRequestFactoryTest {
38+
39+
@Test
40+
public void verifyBytesInSizeFromLocalFile() throws IOException {
41+
URI uri = new File("speech/grpc/resources/audio.raw").toURI();
42+
AudioRequest audio = AudioRequestFactory.createRequest(uri);
43+
44+
int numBytes = audio.getContent().toByteArray().length();
45+
46+
//assert the number of bytes in the audio as 57958
47+
assertSame(numBytes, 57958);
48+
}
49+
50+
@Test
51+
public void verifyBytesInSizeFromGoogleStorageFile() throws IOException {
52+
URI uri = URI.create("gs://cloud-samples-test/speech/audio.raw");
53+
AudioRequest audio = AudioRequestFactory.createRequest(uri);
54+
55+
int numBytes = audio.getContent().toByteArray().length();
56+
57+
//assert the number of bytes in the audio as 57958
58+
assertSame(numBytes, 57958);
59+
}
60+
}

0 commit comments

Comments
 (0)