|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 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.
|
|
31 | 31 | import java.util.Collections;
|
32 | 32 | import java.util.List;
|
33 | 33 | import java.util.Set;
|
| 34 | +import java.util.function.Supplier; |
34 | 35 |
|
35 | 36 | import org.junit.jupiter.api.BeforeEach;
|
36 | 37 | import org.junit.jupiter.api.Nested;
|
@@ -408,6 +409,29 @@ void isPrimitiveOrWrapperWithWrapper(Class<?> type) {
|
408 | 409 | assertThat(ClassUtils.isPrimitiveOrWrapper(type)).isTrue();
|
409 | 410 | }
|
410 | 411 |
|
| 412 | + @Test |
| 413 | + void isLambda() { |
| 414 | + assertIsLambda(ClassUtilsTests.staticLambdaExpression); |
| 415 | + assertIsLambda(ClassUtilsTests::staticStringFactory); |
| 416 | + |
| 417 | + assertIsLambda(this.instanceLambdaExpression); |
| 418 | + assertIsLambda(this::instanceStringFactory); |
| 419 | + } |
| 420 | + |
| 421 | + @Test |
| 422 | + void isNotLambda() { |
| 423 | + assertIsNotLambda(new EnigmaSupplier()); |
| 424 | + |
| 425 | + assertIsNotLambda(new Supplier<String>() { |
| 426 | + @Override |
| 427 | + public String get() { |
| 428 | + return "anonymous inner class"; |
| 429 | + } |
| 430 | + }); |
| 431 | + |
| 432 | + assertIsNotLambda(new Fake$$LambdaSupplier()); |
| 433 | + } |
| 434 | + |
411 | 435 |
|
412 | 436 | @Nested
|
413 | 437 | class GetStaticMethodTests {
|
@@ -500,4 +524,38 @@ void print(String header, String[] messages, String footer) {
|
500 | 524 | }
|
501 | 525 | }
|
502 | 526 |
|
| 527 | + private static void assertIsLambda(Supplier<String> supplier) { |
| 528 | + assertThat(ClassUtils.isLambdaClass(supplier.getClass())).isTrue(); |
| 529 | + } |
| 530 | + |
| 531 | + private static void assertIsNotLambda(Supplier<String> supplier) { |
| 532 | + assertThat(ClassUtils.isLambdaClass(supplier.getClass())).isFalse(); |
| 533 | + } |
| 534 | + |
| 535 | + private static final Supplier<String> staticLambdaExpression = () -> "static lambda expression"; |
| 536 | + |
| 537 | + private final Supplier<String> instanceLambdaExpression = () -> "instance lambda expressions"; |
| 538 | + |
| 539 | + private static String staticStringFactory() { |
| 540 | + return "static string factory"; |
| 541 | + } |
| 542 | + |
| 543 | + private String instanceStringFactory() { |
| 544 | + return "instance string factory"; |
| 545 | + } |
| 546 | + |
| 547 | + private static class EnigmaSupplier implements Supplier<String> { |
| 548 | + @Override |
| 549 | + public String get() { |
| 550 | + return "enigma"; |
| 551 | + } |
| 552 | + } |
| 553 | + |
| 554 | + private static class Fake$$LambdaSupplier implements Supplier<String> { |
| 555 | + @Override |
| 556 | + public String get() { |
| 557 | + return "fake lambda"; |
| 558 | + } |
| 559 | + } |
| 560 | + |
503 | 561 | }
|
0 commit comments