@@ -0,0 +1,2613 @@
+// Copyright 2019 Google LLC%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     https://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0A//package com.google.speech.tools.voxetta;%0A%0Apackage com.google.speech.tools.voxetta;%0A%0Aimport com.google.appengine.api.blobstore.BlobstoreService;%0Aimport java.io.StringWriter;%0Aimport java.io.PrintWriter;%0Aimport javax.servlet.http.*;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.JUnit4;%0Aimport org.mockito.Mockito;%0A%0A/** %0A* Verifies the intended behavior of BlobstoreLinkServlet.java. %0A*/%0A@RunWith(JUnit4.class)%0Apublic final class BlobstoreLinkServletTest extends Mockito %7B%0A%0A  @Test%0A  public void VerifyBlobstoreLinkBehavior() throws Exception %7B%0A    // Mock the Blobstore API service%0A    BlobstoreService blobstoreService = Mockito.mock(BlobstoreService.class);%0A%0A    // Return the string 'url' when the mocked Blobstore service is called%0A    when(blobstoreService.createUploadUrl(%22/upload-utterance%22)).thenReturn(%22url%22);%0A%0A    // Create a new servlet & set its Blobstore service to be the mocked service%0A    BlobstoreLinkServlet servlet = new BlobstoreLinkServlet();%0A    servlet.setBlobstoreService(blobstoreService);%0A%0A    // Mock the request and response %0A    HttpServletRequest request = mock(HttpServletRequest.class);       %0A    HttpServletResponse response = mock(HttpServletResponse.class);%0A%0A    // Create a writer that will record the doGet function's printed text%0A    StringWriter stringWriter = new StringWriter();%0A    PrintWriter printWriter = new PrintWriter(stringWriter);%0A    when(response.getWriter()).thenReturn(printWriter);%0A%0A    // Call the doGet function now that all mocks are in place%0A    servlet.doGet(request, response);%0A%0A    // Verify that the 'setContentType' function was truly called%0A    verify(response, atLeast(1)).setContentType(%22text/html%22); %0A%0A    // Assert that the function printed the mock's retrieved 'url'%0A    Assert.assertTrue(stringWriter.toString().contains(%22url%22));%0A  %7D%0A%7D

add unit testing for link servlet