-
Notifications
You must be signed in to change notification settings - Fork 261
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
Do we need DefaultSubject? #204
Comments
So... we don't, really, but I remember way back having some issues with returning the parent. I think Subject should be abstract. If we're going to do surgery, I think we actually need to do this differently... having something like class abstract Subject { ... universals } // or maybe interface, depending.
class abstract ReferenceObjectSubject<T> {}
class abstract PrimitiveSubject {} and maybe class abstract AbstractObjectArraySubject<T> {} // omit if unneeded, need to think.
class abstract AbstractPrimitiveArraySubject {} And then reset everything. At some level, the only really necessary contract between all subjects is that they hold on to a subject, they hold a failure strategy, and they expose arbitrary methods that will report failure in the context of a subject, to the failure strategy. That's actually all behavioral contract, not API surface, except insofar as we say the Constructor is part of that. If we make Subject an interface, then we don't really have any way to enforce the contract, but then we're not running primitives through boxing, and we can have PrimitiveSubject do the cleaner primitive things. If we don't care about the boxing (and I would argue we don't if we are consistent in thinking this is a library for use in unit tests), then there's not a lot of reason to make Subject an interface, since everything can go through I think it might be reasonable to do a restructuring such as the above, if only because it means we can eliminate some referencey things from primitive subjects. But Whether we want Subject to take on less work is a function of whether we mind the boxing, I think. |
I definitely think we need to lock down DefaultSubject, regardless... and @kluever tried to, but found callers, as predicted. We need to fix those internally before we can mark it final. |
We've had a lot of conversation, in building out subjects internally at Square, and I think we should move on some of these separation of concern issues. Subject probably shouldn't have any assertions, it should have plumbing, and ReferenceObjectSubject and PrimitiveSubject should have the top-level. In practice, that probably means (for backwards compatibility) adding a supertype, since everyone inherits from Subject - maybe AbstractSubject because really that's what it is. It sould have actual() and the raw infrastructure. We could probably make the fail*() methods be a set of APIs on or around FailureStrategy, and the existing Subject can just implement the existing methods against those APIs. We did a lot of preliminary work a couple of years ago, but didn't finish. Now that I'm on the outside, I can't do the cleanup work inside google, but I could implement at least a straw-man backwards-compatible flavor of this change, which could then be tested internally, and migrated. (cc: @cpovirk) |
Lots to think about here, thanks.
(1) might not be a breaking change, which would mean it could wait until after 1.0. Or maybe it is a breaking change if it requires a generics change on (2) is something that I'm still hoping to look at for 1.0, since removing (3)... I have forgotten the details about, sorry :( I know it came up on, uh, "Aug 2, 2016" :) But I forget the motivation and details. My suspicion is that removing any methods from the |
#204 RELNOTES=Deprecated `DefaultSubject`. Use plain `Subject`. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=246324825
#204 RELNOTES=Deprecated `DefaultSubject`. Use plain `Subject`. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=246324825
RE: (3): @ronshapiro points out that it would be nice to eliminate:
Not to mention We could even tweak other methods, like giving each primitive type its own So there's more here than I had given it credit for. Sorry about that. Unfortunately, with 1.0 bearing down on us, we'll likely just live with what we have. We should definitely have static analysis for Error Prone users -- which also has the advantage of working well with |
(The more specific types on the primitive subjects' |
…, `StandardSubjectBuilder.fail(...)` overload that accepts arguments, and `Optional*Subject.hasValueThat()` Fixes google#204 Relnotes: - Removed the overload of `StandardSubjectBuilder.fail(...)` that accepts a message. Instead of `assert_().fail(...)`, use `assertWithMessage(...).fail()`. Similarly, instead of `expect.fail(...)`, use `expect.withMessage(...).fail()`, and so forth. - Removed `DefaultSubject`. Use plain `Subject`. - Removed `Optional*Subject.hasValueThat()`. Instead of `assertThat(optional).hasValueThat()....`, use `assertThat(optional.getAs*())....`. - Removed `AtomicLongMapSubject`. In most cases, you can [assert on the `asMap()` view instead](google#579). [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=254994279
It seems like
Subject
itself serves the purpose. Well, OK, I guess that we need some values to plug in for the type parameters (Object
and... what?), but this is the same problem we have withIterableSubject
, and we get by there OK with our unchecked+rawtypescreate
method, so this is a problem that we already have and have already solved. Or we can eliminate the problem by eliminating the type parameter (#202).(If
DefaultSubject
needs to stick around, should it beObjectSubject
for consistency with other subjects?)(I tagged this as a blocker of Release 1.0, even though it's maybe not technically SPI, on the theory that writers of custom
assertThat
methods are likely to useDefaultSubject
, just as they're likely to use true SPI. I'm not sure whether I buy my own logic here or not.)The text was updated successfully, but these errors were encountered: