-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix ExecutionContext
dirty flag set to false on same value put or null put
#4691
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2006-2023 the original author or authors. | ||
* Copyright 2006-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -30,7 +30,7 @@ | |
/** | ||
* @author Lucas Ward | ||
* @author Mahmoud Ben Hassine | ||
* | ||
* @author Seokmun Heo | ||
*/ | ||
class ExecutionContextTests { | ||
|
||
|
@@ -88,11 +88,13 @@ void testNotDirtyWithDuplicate() { | |
} | ||
|
||
@Test | ||
void testNotDirtyWithRemoveMissing() { | ||
void testDirtyWithRemoveMissing() { | ||
context.putString("1", "test"); | ||
assertTrue(context.isDirty()); | ||
context.putString("1", null); // remove an item that was present | ||
assertTrue(context.isDirty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By changing this line you change the meaning of the test. I think it would be better to clear the dirty flag before setting it to null for the second time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually testing that it stays dirty when inserting null twice could then be done in its own test or testDirtyWithDuplicate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made some adjustments to the test based on the feedback. I added a step to clear the dirty flag before trying to remove an already non-existent item. This way, the test clearly checks that the dirty state doesn’t change in that situation. I think it makes the intent of the test more explicit and separates the different scenarios, making it easier to understand. |
||
|
||
context.clearDirtyFlag(); | ||
context.putString("1", null); // remove a non-existent item | ||
assertFalse(context.isDirty()); | ||
} | ||
|
@@ -161,6 +163,15 @@ void testCopyConstructorNullInput() { | |
assertTrue(context.isEmpty()); | ||
} | ||
|
||
@Test | ||
void testDirtyWithDuplicate() { | ||
ExecutionContext context = new ExecutionContext(); | ||
context.put("1", "testString1"); | ||
assertTrue(context.isDirty()); | ||
context.put("1", "testString1"); // put the same value | ||
assertTrue(context.isDirty()); | ||
} | ||
|
||
/** | ||
* Value object for testing serialization | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick, but I'd prefer a single line change
this.dirty = this.dirty || result == null || !result.equals(value);
(and similar for the else case)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think one line of code was intuitive, so I made it through newDirty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that's a personal thing then. I find the or statements easier to read. Let's see if we get a 3rd opinion from the maintainers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your point, and I think it’s a good idea to get more opinions. I chose this approach because I wanted to explicitly handle situations where the state changes from true to false, ensuring that it doesn’t happen unintentionally.