Giter Site home page Giter Site logo

Comments (4)

joel-costigliola avatar joel-costigliola commented on July 20, 2024

I agree on the consequences but without dateFormat static field users would have to set the date format each time they call assertThat(), with static fields dateFormat can be set only once.

Do you think of a solution that would both simple for users and parallel safe ?

from assertj.

ash2k avatar ash2k commented on July 20, 2024

I think it is possible to use ThreadLocal to avoid sharing instances between threads. That way it would be possible to set required format in @Before/@BeforeMethod-annotated methods for the current thread.

p.s. also I think it's worth mentioning in JavaDoc that with default format current timezone is used i.e. of the machine where tests are executed. This can cause problems.

from assertj.

kretes avatar kretes commented on July 20, 2024

I would say keeping any state between two assertions is a premature optimization.

I understand the problem to be solved was to replace:
assertThat(date).withFormat(dateFormat).isAfter(dateAsString)
assertThat(date).withFormat(dateFormat).isAfter(dateAsString)
assertThat(date).withFormat(dateFormat).isAfter(dateAsString)

with
DateAssert.setDateFormat(dateFormat);
assertThat(date).isAfter(dateAsString)
assertThat(date).isAfter(dateAsString)
assertThat(date).isAfter(dateAsString)

but user could really easily do it with wrapping the assertThat(date).withFormat(dateFormat) in some private method.
I will try to make it ThreadLocal, though, but I would vote for changing it to assertion instance, starting with marking methods as deprecated

from assertj.

joel-costigliola avatar joel-costigliola commented on July 20, 2024

I'm thinking that it might be better to take another approach similar to the way we deal with date default formats.

Instead of replacing the custom date format, we could just add it to a list of custom date formats, this should fix the problem described if code accessing custom date formats list is properly synchronized or if we use a concurrent collection (CopyOnWriteArrayList ?)

from assertj.

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.