コード例 #1
0
  @Test
  public void call_server() throws Exception {
    String expectedSentence = "Hello Filibuster!";

    Client httpClient = mock(Client.class);
    WebTarget webTarget = mock(WebTarget.class);
    Invocation.Builder builder = mock(Invocation.Builder.class);
    String json = "{\"sound\":\"SGVsbG8gRmlsaWJ1c3RlciE=\"}";

    when(httpClient.target(anyString())).thenReturn(webTarget);
    when(webTarget.path(anyString())).thenReturn(webTarget);
    when(webTarget.queryParam(anyString(), anyString())).thenReturn(webTarget);
    when(webTarget.request(any(MediaType.class))).thenReturn(builder);
    when(builder.get(String.class)).thenReturn(json);

    String host = "localhost";
    int port = 80;
    SpeechClient client = new SpeechClient(httpClient, new ObjectMapper(), host, port);

    SynthesizedSound actual = client.synthesise(expectedSentence);

    assertThat(actual.getSound(), is(expectedSentence.getBytes()));

    verify(httpClient).target("http://localhost:80");
    verify(webTarget).path("synthesize");

    String encoded = Base64.getEncoder().encodeToString(expectedSentence.getBytes("UTF-8"));
    verify(webTarget).queryParam("sentence", encoded);

    verify(webTarget).request(MediaType.APPLICATION_JSON_TYPE);
    verify(builder).get(String.class);
  }
コード例 #2
0
 void addSynthesizedParagraph(SynthesizedSound sound) {
   out.put(sound.getKey(), sound);
 }