-
Notifications
You must be signed in to change notification settings - Fork 69
[ggj][infra][4/5]feat: move the expected string in unit test to golden files #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
18495c7
e1360b5
810e536
424a2bf
b9e691e
c2b3e6d
22482a0
24f788d
0625e08
8360bf8
b138429
c2a7124
4d2c524
9a2a170
ab11794
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| filegroup( | ||
| name = "goldens_files", | ||
| srcs = glob(["*.golden"]), | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /* | ||
| * Copyright 2020 Gagpic-generator-java | ||
| * | ||
| * Licensed description and license version 2.0 (the "License"); | ||
| * | ||
| * https://www.foo.bar/licenses/LICENSE-2.0 | ||
| * | ||
| * Software distributed under the License is distributed on an "AS IS" BASIS. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.example.library.core; | ||
|
|
||
| import com.google.exmaple.library.LibraryService; | ||
| import com.google.exmaple.library.core.LibraryServiceStub; | ||
| import com.google.exmaple.library.v1.BookKind; | ||
| import com.google.gax.grpc.Stub; | ||
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Stack; | ||
|
|
||
| /** | ||
| * Service Description: This is a test comment. | ||
| * | ||
| * <pre><code> | ||
| * LibraryServiceStub libServiceStub = new LibraryServiceStub() | ||
| * </code></pre> | ||
| * | ||
| * <ol> | ||
| * <li>A "flattened" method. | ||
| * <li>A "request object" method. | ||
| * <li>A "callable" method. | ||
| * </ol> | ||
| * | ||
| * @deprecated This is a deprecated message. | ||
| */ | ||
| @SuppressWarnings("all") | ||
| @Deprecated | ||
| @Override | ||
| public class LibraryServiceStub extends Stub implements LibraryService { | ||
| private static final String serviceName = "LibraryServiceStub"; | ||
| protected List<Shelf> shelfList; | ||
| public static HashMap<String, Shelf> shelfMap; | ||
|
|
||
| public LibraryServiceStub() { | ||
| super(); | ||
| this.shelfList = new ArrayList<>(); | ||
| shelfMap = new HashMap<>(); | ||
| } | ||
|
|
||
| @Override | ||
| public String addShelf(String name, double seriesDoubleNum) { | ||
| int seriesNum = ((int) seriesDoubleNum); | ||
| if (condition) { | ||
| return "Series number equals to max int value."; | ||
| } | ||
| shelfList.add(new Shelf(name, seriesNum)); | ||
| if (shelfMap.containsKey(name)) { | ||
| return "Shelf is already existing in the map."; | ||
| } | ||
| shelfMap.put(name, new Shelf(name, seriesNum)); | ||
| return "Shelf added."; | ||
| } | ||
|
|
||
| public void updateShelfMap(Shelf newShelf) throws Exception { | ||
| if (shelfMap.containsKey(newShelf.shelfName)) { | ||
| shelfMap.put(newShelf.shelfName, newShelf); | ||
| } else { | ||
| throw new Exception("Updating shelf is not existing in the map"); | ||
| } | ||
| } | ||
|
|
||
| public void printShelfListToFile(String fileName) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| try { | ||
| FileWriter fileWriter = new FileWriter(fileName); | ||
| for (Shelf s : shelfList) { | ||
| sb.append(s.shelfName).append(s.seriesNum); | ||
| } | ||
| fileName.write(sb.toString()); | ||
| fileName.close(); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Add books to Shelf and check if there is a novel, return string message as whether novel books | ||
| * are added to the shelf. | ||
| * | ||
| * @param shelf The Shelf object to which books will put. | ||
| * @param stack The Stack of the BookKinds. | ||
| */ | ||
| public String addBooksContainsNovel(Shelf shelf, Stack<BookKind> stack) { | ||
| boolean containsNovel = false; | ||
| while (stack.isEmpty()) { | ||
| Book addedBook = addBookToShelf(stack.pop(), shelf); | ||
| if (addedBook instanceof Novel) { | ||
| containsNovel = true; | ||
| } | ||
| } | ||
| return containsNovel ? "Added novels" : "No novels added"; | ||
| } | ||
|
|
||
| // Private helper. | ||
| private Book addBookToShelf(BookKind bookKind, Shelf shelf) { | ||
| Book book = | ||
| new Book() { | ||
| @Override | ||
| public void createBook(int seriesNum, BookKind bookKind) { | ||
| this.seriesNum = seriesNum; | ||
| this.bookKind = bookKind; | ||
| } | ||
| }; | ||
| return book; | ||
| } | ||
|
|
||
| public class Shelf { | ||
| public String shelfName; | ||
| public int seriesNum; | ||
| public String shelfServiceName = serviceName; | ||
|
|
||
| public Shelf(String shelfName, int seriesNum) { | ||
| this.shelfName = shelfName; | ||
| this.seriesNum = seriesNum; | ||
| } | ||
| } | ||
|
|
||
| // Test nested abstract class and abstract method. | ||
| public abstract class Book { | ||
| public BookKind bookKind; | ||
| public int seriesNum; | ||
|
|
||
| public abstract void createBook(int seriesNum, BookKind bookKind); | ||
| } | ||
|
|
||
| public class Novel extends Book { | ||
|
|
||
| @Override | ||
| public void createBook(int seriesNum, BookKind bookKind) { | ||
| this.seriesNum = seriesNum; | ||
| this.bookKind = BookKind.NOVEL; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ TESTS = [ | |
|
|
||
| filegroup( | ||
| name = "composer_files", | ||
| srcs = ["{0}.java".format(f) for f in TESTS], | ||
| srcs = glob(["*.java"]), | ||
| ) | ||
|
|
||
| java_proto_library( | ||
|
|
@@ -39,8 +39,12 @@ java_proto_library( | |
|
|
||
| [java_test( | ||
| name = test_name, | ||
| srcs = ["{0}.java".format(test_name)], | ||
| srcs = [ | ||
| "{0}.java".format(test_name), | ||
| "ComposerConstants.java", | ||
| ], | ||
| data = [ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is for including
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! That should also work, while if we add more helpers, those files have to be explicitly included. By using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! Talked offline and for suggested option, we can avoid including other test files. |
||
| "//src/test/java/com/google/api/generator/gapic/composer/goldens:goldens_files", | ||
| "//src/test/java/com/google/api/generator/gapic/testdata:gapic_config_files", | ||
| "//src/test/java/com/google/api/generator/gapic/testdata:service_config_files", | ||
| ], | ||
|
|
@@ -51,6 +55,7 @@ java_proto_library( | |
| "//src/main/java/com/google/api/generator/engine/ast", | ||
| "//src/main/java/com/google/api/generator/engine/writer", | ||
| "//src/main/java/com/google/api/generator/gapic/composer", | ||
| "//src/test/java/com/google/api/generator/test/framework", | ||
| "//src/main/java/com/google/api/generator/gapic/model", | ||
| "//src/main/java/com/google/api/generator/gapic/protoparser", | ||
| "//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.