/*
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.sps.servlets;

import org.junit.jupiter.api.Test;

import javax.servlet.http.HttpServletResponse;

import static org.mockito.Mockito.mock;

public class RegistrationServletTest {

    @Test
    public void testPostNullRequest() {
        RegistrationServlet registrationServlet = new RegistrationServlet();
        HttpServletResponse response = mock(HttpServletResponse.class);
        registrationServlet.doPost(null, response);
    }
}

@@ -634,220 +634,1215 @@
 ort 
-org.junit.jupiter.api.Test;%0A%0Aimport javax.servlet.http.HttpServletResponse;%0A%0Aimport static org.mockito.Mockito.mock;%0A%0Apublic class RegistrationServletTest %7B%0A%0A    @Test%0A    public void testPostNullRequest() %7B%0A    
+com.google.appengine.tools.development.testing.LocalServiceTestHelper;%0Aimport com.google.appengine.tools.development.testing.LocalUserServiceTestConfig;%0Aimport org.junit.jupiter.api.AfterAll;%0Aimport org.junit.jupiter.api.BeforeAll;%0Aimport org.junit.jupiter.api.Test;%0Aimport org.mockito.ArgumentCaptor;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0Aimport static org.junit.jupiter.api.Assertions.assertEquals;%0Aimport static org.mockito.Mockito.doNothing;%0Aimport static org.mockito.Mockito.mock;%0A%0Apublic class RegistrationServletTest %7B%0A  private static final LocalServiceTestHelper userServiceHelper =%0A          new LocalServiceTestHelper(new LocalUserServiceTestConfig());%0A%0A  @BeforeAll%0A  static void setUp() %7B%0A    userServiceHelper.setUp();%0A  %7D%0A%0A  @AfterAll%0A  static void tearDown() %7B%0A    userServiceHelper.tearDown();%0A  %7D%0A%0A  @Test%0A  public void testPostNullRequest() %7B%0A    RegistrationServlet registrationServlet = new RegistrationServlet();%0A    HttpServletResponse response = mock(HttpServletResponse.class);%0A    registrationServlet.doPost(null, response);%0A  %7D%0A%0A  @Test%0A  public void testPostNotLoggedIn() %7B%0A    userServiceHelper.setEnvIsLoggedIn(false);%0A%0A
     
@@ -1910,24 +1910,85 @@
 vlet();%0A    
+HttpServletRequest request = mock(HttpServletRequest.class);%0A
     HttpServ
@@ -2043,20 +2043,167 @@
 class);%0A
+%0A
     
+ArgumentCaptor%3CInteger%3E valueCapture = ArgumentCaptor.forClass(Integer.class);%0A    doNothing().when(response).setStatus(valueCapture.capture());%0A%0A
     regi
@@ -2217,36 +2217,39 @@
 nServlet.doPost(
-null
+request
 , response);%0A   
@@ -2247,14 +2247,92 @@
 nse);%0A  
+  assertEquals(HttpServletResponse.SC_UNAUTHORIZED, valueCapture.getValue());%0A
   %7D%0A%7D%0A

Test with UserService API