|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2019 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.
|
|
19 | 19 | import java.beans.Introspector;
|
20 | 20 | import java.beans.PropertyDescriptor;
|
21 | 21 | import java.lang.reflect.Method;
|
| 22 | +import java.net.URI; |
| 23 | +import java.net.URL; |
| 24 | +import java.time.DayOfWeek; |
22 | 25 | import java.util.ArrayList;
|
| 26 | +import java.util.Date; |
23 | 27 | import java.util.List;
|
| 28 | +import java.util.Locale; |
| 29 | +import java.util.stream.Stream; |
24 | 30 |
|
25 | 31 | import org.junit.Test;
|
26 | 32 |
|
|
32 | 38 | import org.springframework.tests.sample.beans.ITestBean;
|
33 | 39 | import org.springframework.tests.sample.beans.TestBean;
|
34 | 40 |
|
35 |
| -import static org.junit.Assert.*; |
| 41 | +import static org.junit.Assert.assertEquals; |
| 42 | +import static org.junit.Assert.assertFalse; |
| 43 | +import static org.junit.Assert.assertNotNull; |
| 44 | +import static org.junit.Assert.assertNull; |
| 45 | +import static org.junit.Assert.assertTrue; |
| 46 | +import static org.junit.Assert.fail; |
36 | 47 |
|
37 | 48 | /**
|
38 | 49 | * Unit tests for {@link BeanUtils}.
|
39 | 50 | *
|
40 | 51 | * @author Juergen Hoeller
|
41 | 52 | * @author Rob Harrop
|
42 | 53 | * @author Chris Beams
|
| 54 | + * @author Sam Brannen |
43 | 55 | * @since 19.05.2003
|
44 | 56 | */
|
45 | 57 | public class BeanUtilsTests {
|
@@ -275,6 +287,60 @@ public void testSPR6063() {
|
275 | 287 | }
|
276 | 288 | }
|
277 | 289 |
|
| 290 | + @Test |
| 291 | + public void isSimpleValueType() { |
| 292 | + Stream.of( |
| 293 | + |
| 294 | + boolean.class, char.class, byte.class, short.class, int.class, |
| 295 | + long.class, float.class, double.class, |
| 296 | + |
| 297 | + Boolean.class, Character.class, Byte.class, Short.class, Integer.class, |
| 298 | + Long.class, Float.class, Double.class, |
| 299 | + |
| 300 | + DayOfWeek.class, String.class, Date.class, URI.class, URL.class, Locale.class, Class.class |
| 301 | + |
| 302 | + ).forEach(this::assertIsSimpleValueType); |
| 303 | + |
| 304 | + Stream.of(int[].class, Object.class, List.class, void.class, Void.class) |
| 305 | + .forEach(this::assertIsNotSimpleValueType); |
| 306 | + } |
| 307 | + |
| 308 | + @Test |
| 309 | + public void isSimpleProperty() { |
| 310 | + Stream.of( |
| 311 | + |
| 312 | + boolean.class, char.class, byte.class, short.class, int.class, |
| 313 | + long.class, float.class, double.class, |
| 314 | + |
| 315 | + Boolean.class, Character.class, Byte.class, Short.class, Integer.class, |
| 316 | + Long.class, Float.class, Double.class, |
| 317 | + |
| 318 | + DayOfWeek.class, String.class, Date.class, URI.class, URL.class, Locale.class, Class.class, |
| 319 | + |
| 320 | + boolean[].class, Boolean[].class, Date[].class |
| 321 | + |
| 322 | + ).forEach(this::assertIsSimpleProperty); |
| 323 | + |
| 324 | + Stream.of(Object.class, List.class, void.class, Void.class) |
| 325 | + .forEach(this::assertIsNotSimpleProperty); |
| 326 | + } |
| 327 | + |
| 328 | + private void assertIsSimpleValueType(Class<?> type) { |
| 329 | + assertTrue("Type [" + type.getName() + "] should be a simple value type", BeanUtils.isSimpleValueType(type)); |
| 330 | + } |
| 331 | + |
| 332 | + private void assertIsNotSimpleValueType(Class<?> type) { |
| 333 | + assertFalse("Type [" + type.getName() + "] should not be a simple value type", BeanUtils.isSimpleValueType(type)); |
| 334 | + } |
| 335 | + |
| 336 | + private void assertIsSimpleProperty(Class<?> type) { |
| 337 | + assertTrue("Type [" + type.getName() + "] should be a simple property", BeanUtils.isSimpleProperty(type)); |
| 338 | + } |
| 339 | + |
| 340 | + private void assertIsNotSimpleProperty(Class<?> type) { |
| 341 | + assertFalse("Type [" + type.getName() + "] should not be a simple property", BeanUtils.isSimpleProperty(type)); |
| 342 | + } |
| 343 | + |
278 | 344 | private void assertSignatureEquals(Method desiredMethod, String signature) {
|
279 | 345 | assertEquals(desiredMethod, BeanUtils.resolveSignature(signature, MethodSignatureBean.class));
|
280 | 346 | }
|
@@ -445,6 +511,7 @@ public void setValue(String aValue) {
|
445 | 511 | }
|
446 | 512 | }
|
447 | 513 |
|
| 514 | + @SuppressWarnings("unused") |
448 | 515 | private static class BeanWithSingleNonDefaultConstructor {
|
449 | 516 |
|
450 | 517 | private final String name;
|
|
0 commit comments