Skip to content

Adding test utilities to create Value types #1158

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 10 commits into from
Jan 24, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

This exposes a similar interface as wrap() and allows me to change the existing FieldValue test to use Value protos.

For reference: #1156

This will be used (and tested) in the follow-up CL that adds the FieldValue tpes.
This exposes a similar interface as wrap() and allows me to change the existing FieldValue test to use Value protos
@codecov
Copy link

codecov bot commented Jan 23, 2020

Codecov Report

Merging #1158 into mrschmidt/rewritefieldvalue will increase coverage by 0.74%.
The diff coverage is 0%.

Flag Coverage Δ Complexity Δ
#FirebaseFirestore 61.29% <0%> (+0.03%) 2279 <0> (ø) ⬇️
#FirebaseFirestore_Ktx 41.17% <ø> (ø) 0 <ø> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
...le/firebase/firestore/model/value/ProtoValues.java 0% <0%> (ø) 0 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8d1ce8...063a256. Read the comment docs.

@schmidt-sebastian schmidt-sebastian changed the base branch from mrschmidt/rewritefieldvalue to mrschmidt/comparisons January 23, 2020 18:01
import java.util.List;

/** Test helper to create Firestore Value protos from Java types. */
public class ValueHelper {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of classes named with "Util" or "Helper". How about just Values? This is a convention found in Guava, where e.g. helpers for creating/manipulating lists are in Lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValueHelperUtil it is :)

I renamed it to Values. FWIW, in most APIs that use this convention, the helper library and the main library sit in the same package, which we can't do here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists is a great example because it's a collection of Guava utilities about java.util.List. In other cases where the library has a class and static utilities for dealing with it, it makes sense that they'd colocate them. I don't think that invalidates the static utilities as plurals convention.

See go/java-practices/utility-classes.md.

return Value.newBuilder().setMapValue(builder).build();
}

public static Value wrapRef(DatabaseId dbId, DocumentKey key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of this class doesn't really have much to do with wrapping, but does create values. How about refValue or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (o instanceof Value) {
return (Value) o;
} else if (o instanceof String) {
return (Value.newBuilder().setStringValue((String) o).build());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra parens, here and throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Sorry, I was quite certain googleJavaFormat would do this for me.

com.google.protobuf.Timestamp.newBuilder()
.setSeconds(timestamp.getSeconds())
.setNanos(timestamp.getNanoseconds())
.build())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inner build() is unnecessary. Proto setters take messages or builders and automatically call build() for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed here and for GeoPoint.

} else if (o instanceof DocumentReference) {
return (Value.newBuilder()
.setReferenceValue(
"projects/projectId/databases/(default)/documents/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

projectId isn't a valid project identifier. Elsewhere we've just used "project", FWIW.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stole this from somewhere (SQLiteSchemaTest) and fixed it there as well.

@@ -0,0 +1,98 @@
// Copyright 2020 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you currently only need this for tests, but eventually, won't the UserDataConverter need this as well? Maybe put this in with regular sources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to punt on this for now to figure out how much of this code I will need in UserDataConverter and where to put it. I added a TODO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think it's nice that this is a separate class that just has these static, simple functions. Moving it into the UserDataConverter would muddy that considerably. I was proposing just moving the class wholesale into the same package, or maybe even merging with/renaming ProtoValues and putting it in model.

In any case, no action required for this PR for sure.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Jan 23, 2020
@schmidt-sebastian
Copy link
Contributor Author

/test device-check-changed

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,98 @@
// Copyright 2020 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I think it's nice that this is a separate class that just has these static, simple functions. Moving it into the UserDataConverter would muddy that considerably. I was proposing just moving the class wholesale into the same package, or maybe even merging with/renaming ProtoValues and putting it in model.

In any case, no action required for this PR for sure.

import java.util.List;

/** Test helper to create Firestore Value protos from Java types. */
public class ValueHelper {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists is a great example because it's a collection of Guava utilities about java.util.List. In other cases where the library has a class and static utilities for dealing with it, it makes sense that they'd colocate them. I don't think that invalidates the static utilities as plurals convention.

See go/java-practices/utility-classes.md.

return Value.newBuilder().setStringValue((String) o).build();
} else if (o instanceof Blob) {
return Value.newBuilder().setBytesValue(((Blob) o).toByteString()).build();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: excess newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - I forgot to address this before merging. I fixed it in the follow up PR.

return (Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());
return Value.newBuilder().setArrayValue(list).build();
} else if (o instanceof Map) {
com.google.firestore.v1.MapValue.Builder builder =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: import MapValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@wilhuff wilhuff removed their assignment Jan 24, 2020
@schmidt-sebastian schmidt-sebastian changed the base branch from mrschmidt/comparisons to mrschmidt/rewritefieldvalue January 24, 2020 05:30
@schmidt-sebastian schmidt-sebastian merged commit 94844bb into mrschmidt/rewritefieldvalue Jan 24, 2020
@google-oss-bot
Copy link
Contributor

@schmidt-sebastian: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
smoke-tests 063a256 link /test smoke-tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/testhelpers branch February 7, 2020 00:22
@firebase firebase locked and limited conversation to collaborators Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants