Skip to content

Commit e14f3ba

Browse files
authored
feat: Adds functions_helloworld_get (GoogleCloudPlatform#1573)
* feat: Adds functions_helloworld_get * fix: Fixes Java linter (multiple cap letters in method name) * Update functions/snippets/src/main/java/HelloWorld.java Co-Authored-By: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> * Update HelloWorld.java * Update HelloWorld.java
1 parent 6ad33a3 commit e14f3ba

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2019 Google LLC
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+
// [START functions_helloworld_get]
18+
import java.io.IOException;
19+
import java.io.PrintWriter;
20+
import javax.servlet.http.HttpServletRequest;
21+
import javax.servlet.http.HttpServletResponse;
22+
23+
public class HelloWorld {
24+
// Simple function to return "Hello World"
25+
public void helloGet(HttpServletRequest request, HttpServletResponse response)
26+
throws IOException {
27+
PrintWriter writer = response.getWriter();
28+
writer.write("Hello World!");
29+
}
30+
}
31+
32+
// [END functions_helloworld_get]

functions/snippets/src/test/java/SnippetsTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ public void afterTest() {
6969
System.setOut(null);
7070
}
7171

72+
@Test
73+
public void helloWorldTest() throws IOException {
74+
new HelloWorld().helloGet(request, response);
75+
76+
assertThat(responseOut.toString(), containsString("Hello World!"));
77+
}
78+
7279
@Test
7380
public void logHelloWorldTest() throws IOException {
7481
new LogHelloWorld().logHelloWorld(request, response);

0 commit comments

Comments
 (0)