-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: NPE while creating a policies copy #36172
Changes from 2 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.appsmith.server.repositories.ce; | ||
|
||
import com.appsmith.external.models.BaseDomain; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class BaseAppsmithRepositoryImplTest { | ||
|
||
BaseAppsmithRepositoryCEImpl<TestClass> baseAppsmithRepositoryImpl; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
baseAppsmithRepositoryImpl = new BaseAppsmithRepositoryCEImpl<>() {}; | ||
} | ||
|
||
class TestClass extends BaseDomain {} | ||
|
||
@Test | ||
void testSetUserPermissionsInObject_whenPoliciesIsEmptySet_emptyCollectionValueIsSet() { | ||
// Test the method setPoliciesInObject when the policies are null | ||
// The method should set an empty collection value in the object | ||
// The method should return the object | ||
TestClass obj = baseAppsmithRepositoryImpl | ||
.setUserPermissionsInObject(new TestClass(), null) | ||
.block(); | ||
assertNotNull(obj); | ||
Assertions.assertEquals(0, obj.getPolicies().size()); | ||
} | ||
Comment on lines
+25
to
+35
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. Review the logic and naming in the test method. The test method Additionally, the test asserts that the policies size is zero, which contradicts the setup where policies are set to null. This might indicate a misunderstanding in the implementation or the test itself. Clarify whether the method should indeed set an empty set or handle null values differently. |
||
|
||
@Test | ||
void testSetUserPermissionsInObject_whenPoliciesIsNull_nullPoliciesAreSet() { | ||
// Test the method setPoliciesInObject when the policies are empty | ||
// The method should set an empty collection value in the object | ||
// The method should return the object | ||
TestClass obj = new TestClass(); | ||
obj.setPolicies(null); | ||
Set<String> permissionGroups = new HashSet<>(); | ||
permissionGroups.add(UUID.randomUUID().toString()); | ||
obj = baseAppsmithRepositoryImpl | ||
.setUserPermissionsInObject(obj, permissionGroups) | ||
.block(); | ||
assertNotNull(obj); | ||
Assertions.assertNull(obj.getPolicies()); | ||
} | ||
Comment on lines
+37
to
+51
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. Clarify test behavior and improve assertions. The test method The use of |
||
} |
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.
Ensure proper initialization in the setup method.
The
setup
method correctly initializesbaseAppsmithRepositoryImpl
. However, consider using@Mock
for dependencies and@InjectMocks
for the class under test to ensure isolation and control over the test environment.