@@ -57,11 +57,50 @@ public void testIsDefaultPartition_withPartitionAsParameter() {
5757 assertThat (defaultPartition ().isPartition (null )).isTrue ();
5858 assertThat (fromPartitionIds (ourDefaultPartitionId ).isPartition (ourDefaultPartitionId )).isTrue ();
5959
60- assertThat (defaultPartition ().isPartition (ourDefaultPartitionId )).isFalse ();
60+ // Since null partition ID is now treated as 0, defaultPartition() (null) matches ourDefaultPartitionId (0)
61+ assertThat (defaultPartition ().isPartition (ourDefaultPartitionId )).isTrue ();
6162 assertThat (allPartitions ().isPartition (ourDefaultPartitionId )).isFalse ();
6263 assertThat (fromPartitionIds (ourDefaultPartitionId , 2 ).isPartition (ourDefaultPartitionId )).isFalse ();
6364 }
6465
66+ @ Test
67+ public void testIsPartition_NullPartitionIdTreatedAsZero () {
68+ // Test that null partition ID in the RequestPartitionId is treated as 0
69+ RequestPartitionId partitionWithNull = fromPartitionIds ((Integer ) null );
70+ assertThat (partitionWithNull .isPartition (0 )).as ("Null partition ID should be treated as 0" ).isTrue ();
71+ assertThat (partitionWithNull .isPartition (null )).as ("Null should match null" ).isTrue ();
72+ assertThat (partitionWithNull .isPartition (1 )).as ("Null partition ID should not match 1" ).isFalse ();
73+
74+ // Test that partition ID 0 matches null parameter
75+ RequestPartitionId partitionWithZero = fromPartitionIds (0 );
76+ assertThat (partitionWithZero .isPartition (null )).as ("Partition ID 0 should match null parameter" ).isTrue ();
77+ assertThat (partitionWithZero .isPartition (0 )).as ("Partition ID 0 should match 0" ).isTrue ();
78+ assertThat (partitionWithZero .isPartition (1 )).as ("Partition ID 0 should not match 1" ).isFalse ();
79+ }
80+
81+ @ Test
82+ public void testIsPartition_WithNonNullPartitionIds () {
83+ // Test normal partition ID matching
84+ RequestPartitionId partition1 = fromPartitionIds (1 );
85+ assertThat (partition1 .isPartition (1 )).isTrue ();
86+ assertThat (partition1 .isPartition (0 )).isFalse ();
87+ assertThat (partition1 .isPartition (null )).isFalse ();
88+ assertThat (partition1 .isPartition (2 )).isFalse ();
89+
90+ // Test with multiple partition IDs (should return false)
91+ RequestPartitionId multiPartition = fromPartitionIds (1 , 2 );
92+ assertThat (multiPartition .isPartition (1 )).isFalse ();
93+ assertThat (multiPartition .isPartition (2 )).isFalse ();
94+ }
95+
96+ @ Test
97+ public void testIsPartition_WithAllPartitions () {
98+ RequestPartitionId allParts = allPartitions ();
99+ assertThat (allParts .isPartition (0 )).isFalse ();
100+ assertThat (allParts .isPartition (1 )).isFalse ();
101+ assertThat (allParts .isPartition (null )).isFalse ();
102+ }
103+
65104 @ Test
66105 public void testHasDefaultPartition_withDefaultPartitionAsParameter () {
67106
0 commit comments