@@ -103,4 +103,44 @@ public void testTraitExistenceConditions(SegmentConditions conditionOperator, St
103103 // The result is as we expect from the DataProvider definition
104104 Assertions .assertEquals (inSegment , expectedResult );
105105 }
106+
107+ private static Stream <Arguments > identitiesInSegmentsPercentageSplit () {
108+ return Stream .of (
109+ Arguments .of (null , "Test" , Boolean .TRUE ),
110+ Arguments .of (1 , "Test" , Boolean .FALSE ));
111+ }
112+
113+ @ ParameterizedTest
114+ @ MethodSource ("identitiesInSegmentsPercentageSplit" )
115+ public void testIdentityInSegmentPercentageSplitUsesDjangoId (Integer djangoId , String identifier ,
116+ Boolean expectedResult ) {
117+ // Given
118+ // An identity with djangoId and identifier as defined in the DataProvider
119+ IdentityModel identityModel = new IdentityModel ();
120+ identityModel .setDjangoId (djangoId );
121+ identityModel .setIdentifier (identifier );
122+ identityModel .setEnvironmentApiKey ("key" );
123+
124+ // And a segment with 50% percentage split
125+ SegmentConditionModel segmentCondition = new SegmentConditionModel ();
126+ segmentCondition .setOperator (SegmentConditions .PERCENTAGE_SPLIT );
127+ segmentCondition .setValue ("50" );
128+
129+ SegmentRuleModel segmentRule = new SegmentRuleModel ();
130+ segmentRule .setConditions (new ArrayList <>(Arrays .asList (segmentCondition )));
131+ segmentRule .setType (SegmentRules .ALL_RULE .getRule ());
132+
133+ SegmentModel segment = new SegmentModel ();
134+ segment .setId (1 );
135+ segment .setName ("% split" );
136+ segment .setRules (new ArrayList <>(Arrays .asList (segmentRule )));
137+
138+ // When
139+ // We evaluate whether the identity is in the segment
140+ Boolean result = SegmentEvaluator .evaluateIdentityInSegment (identityModel , segment , null );
141+
142+ // Then
143+ // The result is as we expect from the DataProvider definition
144+ Assertions .assertEquals (result , expectedResult );
145+ }
106146}
0 commit comments