Skip to content
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

Refactor: Add Instant to TimeService interface and use TimeService in UaaTokenStore #2315

Merged
merged 10 commits into from
Jul 14, 2023

Conversation

strehle
Copy link
Member

@strehle strehle commented May 5, 2023

Add TimeService to UaaTokenStore and replace all now usage to timeService object

Allows to change expiration time without changes in DB expiration.

Follow-up from discussion of #2291

Sonar results
https://sonarcloud.io/summary/new_code?id=cloudfoundry-identity-parent&pullRequest=2315

@cf-gitbot
Copy link

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/185107803

The labels on this github issue will be updated when the story is started.

@strehle strehle changed the title Add mock for TimeService Add Instant to TimeService interface and use it in UaaTokenStore May 5, 2023
@strehle strehle changed the title Add Instant to TimeService interface and use it in UaaTokenStore Refactor: Add Instant to TimeService interface and use TimeService in UaaTokenStore May 5, 2023
@strehle strehle requested a review from hsinn0 May 6, 2023 07:04
Copy link
Contributor

@bruce-ricard bruce-ricard left a comment

Choose a reason for hiding this comment

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

I don't understand the reason why it's better to reuse another interface that is already used by the code.

IMO this is very much the opposite of what dependency injection needs to be: you want to inject what you need, not what is used elsewhere in the code.
Each class or file needs to create their own interfaces specifying what they need, what their dependencies are. Even if 2 classes end up having the exact same dependency at a give point in time, we should NOT reuse the interface, because it creates a binding between the 2 users. If some one class now requires the dependency to be more powerful, that same power will be given to the other class, which doesn't need or want it.

Comment on lines +490 to +493
private static TimeService givenMockedTime() {
TimeServiceImpl timeService = mock(TimeServiceImpl.class);
doReturn(Instant.now()).when(timeService).getCurrentInstant();
return timeService;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the point of this method. It now just returns a normal TimeService that returns the actual current time.

@strehle strehle modified the milestones: 76.15.0, icebox Jun 17, 2023
@strehle strehle modified the milestones: icebox, 76.17.0 Jul 7, 2023
@strehle strehle merged commit eb008a5 into develop Jul 14, 2023
18 checks passed
@strehle strehle deleted the refactor/mockTimeInstant branch July 14, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

5 participants