Giter VIP home page Giter VIP logo

Comments (3)

cpovirk avatar cpovirk commented on June 10, 2024 2

We don't provide an easier way to do this. We should write about why in the FAQ.

Most of the reason is that we were concerned about confusion between this sort of "chaining" and the sort of "chaining" that we provide with assertions like assertThat(exception).hasCauseThat().isInstanceOf(FooException.class). For example:

assertThat(someList)
    .containsExactly(a, b)
    .inOrder();

Is that an assertion that the list contains a and b, with a appearing before b? Or is it an assertion that the list contains a and b and that the entire list (which may contain more elements) is in lexicographical order? (I grant the actual answer is relatively obvious in this case, so I should come up with a better example :))

Another contributing factor is that this approach is only reliably possible if most Subject subclasses declare a "self type" type parameter. We found that people who wrote Truth extensions rarely did this, so chaining did not work in some cases. And in the cases in which people did declare self-type type parameters, they needed additional abstract classes with type parameters (and sometimes that's in combination with more type paramters) to make all the generics work out right.

Previously: #253 #37 #6

(Kotlin provides a syntax that makes this work better, and we may try to make it work still better there: #572)

I'm going to re-purpose this issue to about about adding a FAQ entry.

from truth.

kevinb9n avatar kevinb9n commented on June 10, 2024 1

I expect everyone to want this at one time or another.

But our equation is basically: a moderate API convenience isn't worth even the smallest risk of user confusion (especially user confusion that can lead to false-negative assertions!).

(If we mention the regex workaround we should note that that switch could easily be a step backward in error message usefulness.)

from truth.

cpovirk avatar cpovirk commented on June 10, 2024

(That FAQ entry can also mention the specific approach you discuss in the PR you cross-linked -- using regex instead of startsWith+contains+endsWith. We might have other advice to give, too, like not necessarily worrying about calling isNotNull() before dereferencing a possibly null object.)

from truth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.