@@ -152,16 +152,16 @@ void shouldReturnNullForNonExistentDimension() {
152152 @ Test
153153 void shouldThrowExceptionWhenExceedingMaxDimensions () {
154154 // Given
155- // Create a map with 9 dimensions (9 is maximum)
156- Map < String , String > dimensions = Map . of (
157- "Key1" , "Value1" , "Key2" , "Value2" , "Key3" , "Value3" , "Key4" , "Value4" , "Key5" , "Value5" ,
158- "Key6" , "Value6" , "Key7" , "Value7" , "Key8" , "Value8" , "Key9" , "Value9" );
159- DimensionSet dimensionSet = DimensionSet . of ( dimensions );
155+ // Create a dimension set with 30 dimensions (30 is maximum)
156+ DimensionSet dimensionSet = new DimensionSet ();
157+ for ( int i = 1 ; i <= 30 ; i ++) {
158+ dimensionSet . addDimension ( "Key" + i , "Value" + i );
159+ }
160160
161161 // When/Then
162- assertThatThrownBy (() -> dimensionSet .addDimension ("Key10 " , "Value10 " ))
162+ assertThatThrownBy (() -> dimensionSet .addDimension ("Key31 " , "Value31 " ))
163163 .isInstanceOf (IllegalStateException .class )
164- .hasMessageContaining ("Cannot exceed 9 dimensions per dimension set" );
164+ .hasMessageContaining ("Cannot exceed 30 dimensions per dimension set" );
165165 }
166166
167167 @ Test
@@ -194,6 +194,98 @@ void shouldThrowExceptionWhenValueIsNull() {
194194 // When/Then
195195 assertThatThrownBy (() -> dimensionSet .addDimension ("Key" , null ))
196196 .isInstanceOf (IllegalArgumentException .class )
197- .hasMessage ("Dimension value cannot be null" );
197+ .hasMessage ("Dimension value cannot be null or empty" );
198+ }
199+
200+ @ Test
201+ void shouldThrowExceptionWhenValueIsEmpty () {
202+ // Given
203+ DimensionSet dimensionSet = DimensionSet .of (Collections .emptyMap ());
204+
205+ // When/Then
206+ assertThatThrownBy (() -> dimensionSet .addDimension ("Key" , "" ))
207+ .isInstanceOf (IllegalArgumentException .class )
208+ .hasMessage ("Dimension value cannot be null or empty" );
209+ }
210+
211+ @ Test
212+ void shouldThrowExceptionWhenKeyContainsWhitespace () {
213+ // Given
214+ DimensionSet dimensionSet = DimensionSet .of (Collections .emptyMap ());
215+
216+ // When/Then
217+ assertThatThrownBy (() -> dimensionSet .addDimension ("Key With Space" , "Value" ))
218+ .isInstanceOf (IllegalArgumentException .class )
219+ .hasMessage ("Dimension key cannot contain whitespaces: Key With Space" );
220+ }
221+
222+ @ Test
223+ void shouldThrowExceptionWhenValueContainsWhitespace () {
224+ // Given
225+ DimensionSet dimensionSet = DimensionSet .of (Collections .emptyMap ());
226+
227+ // When/Then
228+ assertThatThrownBy (() -> dimensionSet .addDimension ("Key" , "Value With Space" ))
229+ .isInstanceOf (IllegalArgumentException .class )
230+ .hasMessage ("Dimension value cannot contain whitespaces: Value With Space" );
231+ }
232+
233+ @ Test
234+ void shouldThrowExceptionWhenKeyStartsWithColon () {
235+ // Given
236+ DimensionSet dimensionSet = DimensionSet .of (Collections .emptyMap ());
237+
238+ // When/Then
239+ assertThatThrownBy (() -> dimensionSet .addDimension (":Key" , "Value" ))
240+ .isInstanceOf (IllegalArgumentException .class )
241+ .hasMessage ("Dimension key cannot start with colon: :Key" );
242+ }
243+
244+ @ Test
245+ void shouldThrowExceptionWhenKeyExceedsMaxLength () {
246+ // Given
247+ DimensionSet dimensionSet = DimensionSet .of (Collections .emptyMap ());
248+ String longKey = "a" .repeat (251 ); // MAX_DIMENSION_NAME_LENGTH + 1
249+
250+ // When/Then
251+ assertThatThrownBy (() -> dimensionSet .addDimension (longKey , "Value" ))
252+ .isInstanceOf (IllegalArgumentException .class )
253+ .hasMessage ("Dimension name exceeds maximum length of 250: " + longKey );
254+ }
255+
256+ @ Test
257+ void shouldThrowExceptionWhenValueExceedsMaxLength () {
258+ // Given
259+ DimensionSet dimensionSet = DimensionSet .of (Collections .emptyMap ());
260+ String longValue = "a" .repeat (1025 ); // MAX_DIMENSION_VALUE_LENGTH + 1
261+
262+ // When/Then
263+ assertThatThrownBy (() -> dimensionSet .addDimension ("Key" , longValue ))
264+ .isInstanceOf (IllegalArgumentException .class )
265+ .hasMessage ("Dimension value exceeds maximum length of 1024: " + longValue );
266+ }
267+
268+ @ Test
269+ void shouldThrowExceptionWhenKeyContainsNonAsciiCharacters () {
270+ // Given
271+ DimensionSet dimensionSet = DimensionSet .of (Collections .emptyMap ());
272+ String keyWithNonAscii = "Key\u0080 " ; // Non-ASCII character
273+
274+ // When/Then
275+ assertThatThrownBy (() -> dimensionSet .addDimension (keyWithNonAscii , "Value" ))
276+ .isInstanceOf (IllegalArgumentException .class )
277+ .hasMessage ("Dimension name has invalid characters: " + keyWithNonAscii );
278+ }
279+
280+ @ Test
281+ void shouldThrowExceptionWhenValueContainsNonAsciiCharacters () {
282+ // Given
283+ DimensionSet dimensionSet = DimensionSet .of (Collections .emptyMap ());
284+ String valueWithNonAscii = "Value\u0080 " ; // Non-ASCII character
285+
286+ // When/Then
287+ assertThatThrownBy (() -> dimensionSet .addDimension ("Key" , valueWithNonAscii ))
288+ .isInstanceOf (IllegalArgumentException .class )
289+ .hasMessage ("Dimension value has invalid characters: " + valueWithNonAscii );
198290 }
199291}
0 commit comments