From 597fe237b5c84f24cfa64a92c8650a32e6842dc2 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 22 Aug 2018 15:35:52 +0200 Subject: [PATCH] Polish "Add PropertyMapper.from(value)" Closes gh-13837 --- .../batch/BasicBatchConfigurer.java | 2 +- .../context/properties/PropertyMapper.java | 24 +++++++++---------- .../properties/PropertyMapperTests.java | 24 +++++++++---------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java index 6a91a053be..862d6a7266 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java index cbe9ad0ddb..fb5a301a2d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/PropertyMapper.java @@ -91,24 +91,13 @@ public final class PropertyMapper { return new PropertyMapper(this, operator); } - /** - * Return a new {@link Source} from the specified value that can be used to perform - * the mapping. - * @param the source type - * @param value the value - * @return a {@link Source} that can be used to complete the mapping - * @see #from(Supplier) - */ - public Source from(T value) { - return from(() -> value); - } - /** * Return a new {@link Source} from the specified value supplier that can be used to * perform the mapping. * @param the source type * @param supplier the value supplier * @return a {@link Source} that can be used to complete the mapping + * @see #from(Object) */ public Source from(Supplier supplier) { Assert.notNull(supplier, "Supplier must not be null"); @@ -119,6 +108,17 @@ public final class PropertyMapper { return source; } + /** + * Return a new {@link Source} from the specified value that can be used to perform + * the mapping. + * @param the source type + * @param value the value + * @return a {@link Source} that can be used to complete the mapping + */ + public Source from(T value) { + return from(() -> value); + } + @SuppressWarnings("unchecked") private Source getSource(Supplier supplier) { if (this.parent != null) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java index 5318986d6d..7b0d5ef985 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java @@ -120,24 +120,24 @@ public class PropertyMapperTests { @Test public void whenTrueWhenValueIsTrueShouldMap() { - Boolean result = this.map.from(() -> true).whenTrue().toInstance(Boolean::new); + Boolean result = this.map.from(true).whenTrue().toInstance(Boolean::new); assertThat(result).isTrue(); } @Test public void whenTrueWhenValueIsFalseShouldNotMap() { - this.map.from(() -> false).whenTrue().toCall(Assert::fail); + this.map.from(false).whenTrue().toCall(Assert::fail); } @Test public void whenFalseWhenValueIsFalseShouldMap() { - Boolean result = this.map.from(() -> false).whenFalse().toInstance(Boolean::new); + Boolean result = this.map.from(false).whenFalse().toInstance(Boolean::new); assertThat(result).isFalse(); } @Test public void whenFalseWhenValueIsTrueShouldNotMap() { - this.map.from(() -> true).whenFalse().toCall(Assert::fail); + this.map.from(true).whenFalse().toCall(Assert::fail); } @Test @@ -147,30 +147,29 @@ public class PropertyMapperTests { @Test public void whenHasTextWhenValueIsEmptyShouldNotMap() { - this.map.from(() -> "").whenHasText().toCall(Assert::fail); + this.map.from("").whenHasText().toCall(Assert::fail); } @Test public void whenHasTextWhenValueHasTextShouldMap() { - Integer result = this.map.from(() -> 123).whenHasText().toInstance(Integer::new); + Integer result = this.map.from(123).whenHasText().toInstance(Integer::new); assertThat(result).isEqualTo(123); } @Test public void whenEqualToWhenValueIsEqualShouldMatch() { - String result = this.map.from(() -> "123").whenEqualTo("123") - .toInstance(String::new); + String result = this.map.from("123").whenEqualTo("123").toInstance(String::new); assertThat(result).isEqualTo("123"); } @Test public void whenEqualToWhenValueIsNotEqualShouldNotMatch() { - this.map.from(() -> "123").whenEqualTo("321").toCall(Assert::fail); + this.map.from("123").whenEqualTo("321").toCall(Assert::fail); } @Test public void whenInstanceOfWhenValueIsTargetTypeShouldMatch() { - Long result = this.map.from(() -> 123L).whenInstanceOf(Long.class) + Long result = this.map.from(123L).whenInstanceOf(Long.class) .toInstance((value) -> value + 1); assertThat(result).isEqualTo(124L); } @@ -183,14 +182,13 @@ public class PropertyMapperTests { @Test public void whenWhenValueMatchesShouldMap() { - String result = this.map.from(() -> "123").when("123"::equals) - .toInstance(String::new); + String result = this.map.from("123").when("123"::equals).toInstance(String::new); assertThat(result).isEqualTo("123"); } @Test public void whenWhenValueDoesNotMatchShouldNotMap() { - this.map.from(() -> "123").when("321"::equals).toCall(Assert::fail); + this.map.from("123").when("321"::equals).toCall(Assert::fail); } @Test