-
Notifications
You must be signed in to change notification settings - Fork 70
[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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
18495c7
add golden folder
xiaozhenliu-gg5 e1360b5
format
xiaozhenliu-gg5 810e536
move all expected strings to golden files
xiaozhenliu-gg5 424a2bf
format
xiaozhenliu-gg5 b9e691e
merge
xiaozhenliu-gg5 c2b3e6d
update goldens
xiaozhenliu-gg5 22482a0
update ast integration test
xiaozhenliu-gg5 24f788d
keep service client test
xiaozhenliu-gg5 0625e08
constant helper
xiaozhenliu-gg5 8360bf8
format
xiaozhenliu-gg5 b138429
format
xiaozhenliu-gg5 c2a7124
Merge branch 'master' of github.com:googleapis/gapic-generator-java i…
xiaozhenliu-gg5 4d2c524
feedback
xiaozhenliu-gg5 9a2a170
Merge branch 'master' into add_golden_files
xiaozhenliu-gg5 ab11794
Merge branch 'master' into add_golden_files
xiaozhenliu-gg5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/test/java/com/google/api/generator/engine/goldens/BUILD.bazel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"]), | ||
| ) |
149 changes: 149 additions & 0 deletions
149
src/test/java/com/google/api/generator/engine/goldens/JavaCodeGeneratorTest.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is for including
ComposerConstants.javaas src, not only the tests files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
glob(["*.java"])we can avoid modifying this even if more files are added. WDYT? @miraleungThere was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.