"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/DurationStyleTests.java" between
spring-boot-2.7.3.tar.gz and spring-boot-2.7.4.tar.gz

About: Spring Boot helps to create Spring-powered, production-grade applications and services.

DurationStyleTests.java  (spring-boot-2.7.3):DurationStyleTests.java  (spring-boot-2.7.4)
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skipping to change at line 31 skipping to change at line 31
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException ; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException ;
/** /**
* Tests for {@link DurationStyle}. * Tests for {@link DurationStyle}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Valentine Wu
*/ */
class DurationStyleTests { class DurationStyleTests {
@Test @Test
void detectAndParseWhenValueIsNullShouldThrowException() { void detectAndParseWhenValueIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> DurationSty le.detectAndParse(null)) assertThatIllegalArgumentException().isThrownBy(() -> DurationSty le.detectAndParse(null))
.withMessageContaining("Value must not be null"); .withMessageContaining("Value must not be null");
} }
@Test @Test
void detectAndParseWhenIso8601ShouldReturnDuration() { void detectAndParseWhenIso8601ShouldReturnDuration() {
assertThat(DurationStyle.detectAndParse("pt20.345s")).isEqualTo(D uration.parse("pt20.345s"));
assertThat(DurationStyle.detectAndParse("PT20.345S")).isEqualTo(D uration.parse("PT20.345S")); assertThat(DurationStyle.detectAndParse("PT20.345S")).isEqualTo(D uration.parse("PT20.345S"));
assertThat(DurationStyle.detectAndParse("PT15M")).isEqualTo(Durat ion.parse("PT15M")); assertThat(DurationStyle.detectAndParse("PT15M")).isEqualTo(Durat ion.parse("PT15M"));
assertThat(DurationStyle.detectAndParse("+PT15M")).isEqualTo(Dura tion.parse("PT15M")); assertThat(DurationStyle.detectAndParse("+PT15M")).isEqualTo(Dura tion.parse("PT15M"));
assertThat(DurationStyle.detectAndParse("PT10H")).isEqualTo(Durat ion.parse("PT10H")); assertThat(DurationStyle.detectAndParse("PT10H")).isEqualTo(Durat ion.parse("PT10H"));
assertThat(DurationStyle.detectAndParse("P2D")).isEqualTo(Duratio n.parse("P2D")); assertThat(DurationStyle.detectAndParse("P2D")).isEqualTo(Duratio n.parse("P2D"));
assertThat(DurationStyle.detectAndParse("P2DT3H4M")).isEqualTo(Du ration.parse("P2DT3H4M")); assertThat(DurationStyle.detectAndParse("P2DT3H4M")).isEqualTo(Du ration.parse("P2DT3H4M"));
assertThat(DurationStyle.detectAndParse("-PT6H3M")).isEqualTo(Dur ation.parse("-PT6H3M")); assertThat(DurationStyle.detectAndParse("-PT6H3M")).isEqualTo(Dur ation.parse("-PT6H3M"));
assertThat(DurationStyle.detectAndParse("-PT-6H+3M")).isEqualTo(D uration.parse("-PT-6H+3M")); assertThat(DurationStyle.detectAndParse("-PT-6H+3M")).isEqualTo(D uration.parse("-PT-6H+3M"));
} }
skipping to change at line 146 skipping to change at line 148
assertThat(DurationStyle.detect("10m")).isEqualTo(DurationStyle.S IMPLE); assertThat(DurationStyle.detect("10m")).isEqualTo(DurationStyle.S IMPLE);
assertThat(DurationStyle.detect("10h")).isEqualTo(DurationStyle.S IMPLE); assertThat(DurationStyle.detect("10h")).isEqualTo(DurationStyle.S IMPLE);
assertThat(DurationStyle.detect("10d")).isEqualTo(DurationStyle.S IMPLE); assertThat(DurationStyle.detect("10d")).isEqualTo(DurationStyle.S IMPLE);
assertThat(DurationStyle.detect("-10ms")).isEqualTo(DurationStyle .SIMPLE); assertThat(DurationStyle.detect("-10ms")).isEqualTo(DurationStyle .SIMPLE);
assertThat(DurationStyle.detect("-10ms")).isEqualTo(DurationStyle .SIMPLE); assertThat(DurationStyle.detect("-10ms")).isEqualTo(DurationStyle .SIMPLE);
assertThat(DurationStyle.detect("10D")).isEqualTo(DurationStyle.S IMPLE); assertThat(DurationStyle.detect("10D")).isEqualTo(DurationStyle.S IMPLE);
} }
@Test @Test
void detectWhenIso8601ShouldReturnIso8601() { void detectWhenIso8601ShouldReturnIso8601() {
assertThat(DurationStyle.detect("pt20.345s")).isEqualTo(DurationS tyle.ISO8601);
assertThat(DurationStyle.detect("PT20.345S")).isEqualTo(DurationS tyle.ISO8601); assertThat(DurationStyle.detect("PT20.345S")).isEqualTo(DurationS tyle.ISO8601);
assertThat(DurationStyle.detect("PT15M")).isEqualTo(DurationStyle .ISO8601); assertThat(DurationStyle.detect("PT15M")).isEqualTo(DurationStyle .ISO8601);
assertThat(DurationStyle.detect("+PT15M")).isEqualTo(DurationStyl e.ISO8601); assertThat(DurationStyle.detect("+PT15M")).isEqualTo(DurationStyl e.ISO8601);
assertThat(DurationStyle.detect("PT10H")).isEqualTo(DurationStyle .ISO8601); assertThat(DurationStyle.detect("PT10H")).isEqualTo(DurationStyle .ISO8601);
assertThat(DurationStyle.detect("P2D")).isEqualTo(DurationStyle.I SO8601); assertThat(DurationStyle.detect("P2D")).isEqualTo(DurationStyle.I SO8601);
assertThat(DurationStyle.detect("P2DT3H4M")).isEqualTo(DurationSt yle.ISO8601); assertThat(DurationStyle.detect("P2DT3H4M")).isEqualTo(DurationSt yle.ISO8601);
assertThat(DurationStyle.detect("-PT6H3M")).isEqualTo(DurationSty le.ISO8601); assertThat(DurationStyle.detect("-PT6H3M")).isEqualTo(DurationSty le.ISO8601);
assertThat(DurationStyle.detect("-PT-6H+3M")).isEqualTo(DurationS tyle.ISO8601); assertThat(DurationStyle.detect("-PT-6H+3M")).isEqualTo(DurationS tyle.ISO8601);
} }
@Test @Test
void detectWhenUnknownShouldThrowException() { void detectWhenUnknownShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> DurationSty le.detect("bad")) assertThatIllegalArgumentException().isThrownBy(() -> DurationSty le.detect("bad"))
.withMessageContaining("'bad' is not a valid dura tion"); .withMessageContaining("'bad' is not a valid dura tion");
} }
@Test @Test
void parseIso8601ShouldParse() { void parseIso8601ShouldParse() {
assertThat(DurationStyle.ISO8601.parse("pt20.345s")).isEqualTo(Du ration.parse("pt20.345s"));
assertThat(DurationStyle.ISO8601.parse("PT20.345S")).isEqualTo(Du ration.parse("PT20.345S")); assertThat(DurationStyle.ISO8601.parse("PT20.345S")).isEqualTo(Du ration.parse("PT20.345S"));
assertThat(DurationStyle.ISO8601.parse("PT15M")).isEqualTo(Durati on.parse("PT15M")); assertThat(DurationStyle.ISO8601.parse("PT15M")).isEqualTo(Durati on.parse("PT15M"));
assertThat(DurationStyle.ISO8601.parse("+PT15M")).isEqualTo(Durat ion.parse("PT15M")); assertThat(DurationStyle.ISO8601.parse("+PT15M")).isEqualTo(Durat ion.parse("PT15M"));
assertThat(DurationStyle.ISO8601.parse("PT10H")).isEqualTo(Durati on.parse("PT10H")); assertThat(DurationStyle.ISO8601.parse("PT10H")).isEqualTo(Durati on.parse("PT10H"));
assertThat(DurationStyle.ISO8601.parse("P2D")).isEqualTo(Duration .parse("P2D")); assertThat(DurationStyle.ISO8601.parse("P2D")).isEqualTo(Duration .parse("P2D"));
assertThat(DurationStyle.ISO8601.parse("P2DT3H4M")).isEqualTo(Dur ation.parse("P2DT3H4M")); assertThat(DurationStyle.ISO8601.parse("P2DT3H4M")).isEqualTo(Dur ation.parse("P2DT3H4M"));
assertThat(DurationStyle.ISO8601.parse("-PT6H3M")).isEqualTo(Dura tion.parse("-PT6H3M")); assertThat(DurationStyle.ISO8601.parse("-PT6H3M")).isEqualTo(Dura tion.parse("-PT6H3M"));
assertThat(DurationStyle.ISO8601.parse("-PT-6H+3M")).isEqualTo(Du ration.parse("-PT-6H+3M")); assertThat(DurationStyle.ISO8601.parse("-PT-6H+3M")).isEqualTo(Du ration.parse("-PT-6H+3M"));
} }
@Test @Test
void parseIso8601WithUnitShouldIgnoreUnit() { void parseIso8601WithUnitShouldIgnoreUnit() {
assertThat(DurationStyle.ISO8601.parse("pt20.345s", ChronoUnit.SE CONDS)).isEqualTo(Duration.parse("pt20.345s"));
assertThat(DurationStyle.ISO8601.parse("PT20.345S", ChronoUnit.SE CONDS)).isEqualTo(Duration.parse("PT20.345S")); assertThat(DurationStyle.ISO8601.parse("PT20.345S", ChronoUnit.SE CONDS)).isEqualTo(Duration.parse("PT20.345S"));
assertThat(DurationStyle.ISO8601.parse("PT15M", ChronoUnit.SECOND S)).isEqualTo(Duration.parse("PT15M")); assertThat(DurationStyle.ISO8601.parse("PT15M", ChronoUnit.SECOND S)).isEqualTo(Duration.parse("PT15M"));
assertThat(DurationStyle.ISO8601.parse("+PT15M", ChronoUnit.SECON DS)).isEqualTo(Duration.parse("PT15M")); assertThat(DurationStyle.ISO8601.parse("+PT15M", ChronoUnit.SECON DS)).isEqualTo(Duration.parse("PT15M"));
assertThat(DurationStyle.ISO8601.parse("PT10H", ChronoUnit.SECOND S)).isEqualTo(Duration.parse("PT10H")); assertThat(DurationStyle.ISO8601.parse("PT10H", ChronoUnit.SECOND S)).isEqualTo(Duration.parse("PT10H"));
assertThat(DurationStyle.ISO8601.parse("P2D")).isEqualTo(Duration .parse("P2D")); assertThat(DurationStyle.ISO8601.parse("P2D")).isEqualTo(Duration .parse("P2D"));
assertThat(DurationStyle.ISO8601.parse("P2DT3H4M", ChronoUnit.SEC ONDS)).isEqualTo(Duration.parse("P2DT3H4M")); assertThat(DurationStyle.ISO8601.parse("P2DT3H4M", ChronoUnit.SEC ONDS)).isEqualTo(Duration.parse("P2DT3H4M"));
assertThat(DurationStyle.ISO8601.parse("-PT6H3M", ChronoUnit.SECO NDS)).isEqualTo(Duration.parse("-PT6H3M")); assertThat(DurationStyle.ISO8601.parse("-PT6H3M", ChronoUnit.SECO NDS)).isEqualTo(Duration.parse("-PT6H3M"));
assertThat(DurationStyle.ISO8601.parse("-PT-6H+3M", ChronoUnit.SE CONDS)).isEqualTo(Duration.parse("-PT-6H+3M")); assertThat(DurationStyle.ISO8601.parse("-PT-6H+3M", ChronoUnit.SE CONDS)).isEqualTo(Duration.parse("-PT-6H+3M"));
} }
 End of changes. 6 change blocks. 
1 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)