|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.util.unit;
|
18 | 18 |
|
19 | 19 | import org.junit.jupiter.api.Test;
|
| 20 | +import org.junit.jupiter.params.ParameterizedTest; |
| 21 | +import org.junit.jupiter.params.provider.ValueSource; |
20 | 22 |
|
21 | 23 | import static org.assertj.core.api.Assertions.assertThat;
|
22 | 24 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
25 | 27 | * Tests for {@link DataSize}.
|
26 | 28 | *
|
27 | 29 | * @author Stephane Nicoll
|
| 30 | + * @author Sam Brannen |
28 | 31 | */
|
29 | 32 | class DataSizeTests {
|
30 | 33 |
|
@@ -128,9 +131,17 @@ void parseNegativeNumberWithCustomDefaultUnit() {
|
128 | 131 | assertThat(DataSize.parse("-1", DataUnit.KILOBYTES)).isEqualTo(DataSize.ofKilobytes(-1));
|
129 | 132 | }
|
130 | 133 |
|
131 |
| - @Test |
132 |
| - void parseWithBytes() { |
133 |
| - assertThat(DataSize.parse("1024B")).isEqualTo(DataSize.ofKilobytes(1)); |
| 134 | + @ParameterizedTest(name = "[{index}] text = ''{0}''") |
| 135 | + @ValueSource(strings = { |
| 136 | + "1024B", |
| 137 | + "1024 B", |
| 138 | + "1024B ", |
| 139 | + " 1024B", |
| 140 | + " 1024B ", |
| 141 | + "\t1024 B\t" |
| 142 | + }) |
| 143 | + void parseWithBytes(CharSequence text) { |
| 144 | + assertThat(DataSize.parse(text)).isEqualTo(DataSize.ofKilobytes(1)); |
134 | 145 | }
|
135 | 146 |
|
136 | 147 | @Test
|
@@ -210,9 +221,12 @@ void toStringWithNegativeBytes() {
|
210 | 221 |
|
211 | 222 | @Test
|
212 | 223 | void parseWithUnsupportedUnit() {
|
213 |
| - assertThatIllegalArgumentException().isThrownBy(() -> |
214 |
| - DataSize.parse("3WB")) |
| 224 | + assertThatIllegalArgumentException() |
| 225 | + .isThrownBy(() -> DataSize.parse("3WB")) |
215 | 226 | .withMessage("'3WB' is not a valid data size");
|
| 227 | + assertThatIllegalArgumentException() |
| 228 | + .isThrownBy(() -> DataSize.parse("3 WB")) |
| 229 | + .withMessage("'3 WB' is not a valid data size"); |
216 | 230 | }
|
217 | 231 |
|
218 | 232 | }
|
0 commit comments