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

Update GoTimeUtilTest.java #2987

Conversation

kushagrasinha123ks
Copy link
Contributor

Description

Refactored GoTimeUtilTest to avoid directly calling Optional.get(). Now, the test checks whether the Optional contains a value before fetching it.

Fixes #2970

  • GoTimeUtilTest is refactored to not directly call Optional.get()
  • GoTimeUtilTest is passing after making these changes

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • I have read the contributing guidelines
  • I signed-off my commit with a user that has signed the Eclipse Contributor Agreement
  • My code follows the style guidelines of this project
  • I Keep It Small and Simple: The smaller the PR is, the easier it is to review and have it merged
  • I use conventional commits in my commit messages
  • I have performed a self-review of my code
  • I Added CHANGELOG entry
  • I have updated the documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

git config user.name "Kushagra Sinha"
git config user.email "kushagrasinha123ks@gmail.com"
git commit --amend --signoff
git push origin kushagra/issue#2970 -f

 GoTimeUtilTest is refactored to not directly call Optional.get().
Optional<INTEGER> optionalResult = GoTimeUtil.durationSeconds(duration);
assertThat(optionalResult).isPresent();
assertThat(optionalResult).contains(expectedDuration);
int result = optionalResult.get();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
int result = optionalResult.get();

@@ -32,8 +33,10 @@ class GoTimeUtilTest {
@ParameterizedTest(name = "duration ''{0}'' should be ''{1}'' seconds")
@MethodSource("data")
void conversion(String duration, int expectedDuration) {
int result = GoTimeUtil.durationSeconds(duration).get();
assertThat(result).isEqualTo(expectedDuration);
Optional<INTEGER> optionalResult = GoTimeUtil.durationSeconds(duration);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Optional<INTEGER> optionalResult = GoTimeUtil.durationSeconds(duration);
Optional<Integer> optionalResult = GoTimeUtil.durationSeconds(duration);

int result = GoTimeUtil.durationSeconds(duration).get();
assertThat(result).isEqualTo(expectedDuration);
Optional<INTEGER> optionalResult = GoTimeUtil.durationSeconds(duration);
assertThat(optionalResult).isPresent();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assertThat(optionalResult).isPresent();
assertThat(optionalResult)
.isPresent()
.contains(expectedDuration);

@kushagrasinha123ks kushagrasinha123ks deleted the kushagra/issue#2970 branch April 26, 2024 15:43
@kushagrasinha123ks kushagrasinha123ks restored the kushagra/issue#2970 branch April 26, 2024 15:47
@kushagrasinha123ks kushagrasinha123ks deleted the kushagra/issue#2970 branch April 26, 2024 15:51
@kushagrasinha123ks
Copy link
Contributor Author

Thank you for resolving the error, I'll get on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GoTimeUtilTest : Remove call to Optional.get() without isPresent() check
3 participants