|
12 | 12 | import software.amazon.jsii.tests.calculator.AsyncVirtualMethods; |
13 | 13 | import software.amazon.jsii.tests.calculator.Calculator; |
14 | 14 | import software.amazon.jsii.tests.calculator.CalculatorProps; |
| 15 | +import software.amazon.jsii.tests.calculator.ClassWithJavaReservedWords; |
15 | 16 | import software.amazon.jsii.tests.calculator.ClassWithPrivateConstructorAndAutomaticProperties; |
16 | 17 | import software.amazon.jsii.tests.calculator.Constructors; |
17 | 18 | import software.amazon.jsii.tests.calculator.DataRenderer; |
|
50 | 51 | import software.amazon.jsii.tests.calculator.ReturnsPrivateImplementationOfInterface; |
51 | 52 | import software.amazon.jsii.tests.calculator.StableStruct; |
52 | 53 | import software.amazon.jsii.tests.calculator.Statics; |
| 54 | +import software.amazon.jsii.tests.calculator.StructWithJavaReservedWords; |
53 | 55 | import software.amazon.jsii.tests.calculator.Sum; |
54 | 56 | import software.amazon.jsii.tests.calculator.SyncVirtualMethods; |
55 | 57 | import software.amazon.jsii.tests.calculator.UnionProperties; |
|
73 | 75 |
|
74 | 76 | import static org.junit.Assert.assertEquals; |
75 | 77 | import static org.junit.Assert.assertFalse; |
| 78 | +import static org.junit.Assert.assertNotEquals; |
76 | 79 | import static org.junit.Assert.assertNotNull; |
77 | 80 | import static org.junit.Assert.assertNull; |
78 | 81 | import static org.junit.Assert.assertSame; |
@@ -1018,9 +1021,49 @@ public void consts() { |
1018 | 1021 | @Test |
1019 | 1022 | public void reservedKeywordsAreSlugifiedInMethodNames() { |
1020 | 1023 | JavaReservedWords obj = new JavaReservedWords(); |
1021 | | - obj.import_(); |
1022 | | - obj.const_(); |
1023 | | - assertEquals("hello", obj.getWhile()); // properties do not need to be slufieid |
| 1024 | + obj.doImport(); |
| 1025 | + obj.doConst(); |
| 1026 | + assertEquals("hello", obj.getWhileValue()); // properties should also be 'slugified' |
| 1027 | + } |
| 1028 | + |
| 1029 | + @Test |
| 1030 | + public void reservedKeywordsAreSlugifiedInStructProperties() { |
| 1031 | + StructWithJavaReservedWords struct = StructWithJavaReservedWords.builder() |
| 1032 | + .assertValue("one") |
| 1033 | + .defaultValue("two") |
| 1034 | + .build(); |
| 1035 | + |
| 1036 | + assertEquals("one", struct.getAssertValue()); |
| 1037 | + assertEquals("two", struct.getDefaultValue()); |
| 1038 | + } |
| 1039 | + |
| 1040 | + @Test |
| 1041 | + public void reservedKeywordsAreSlugifiedInClassProperties() { |
| 1042 | + ClassWithJavaReservedWords obj = new ClassWithJavaReservedWords("one"); |
| 1043 | + |
| 1044 | + String result = obj.doImport("two"); |
| 1045 | + |
| 1046 | + assertEquals("onetwo", result); |
| 1047 | + } |
| 1048 | + |
| 1049 | + @Test |
| 1050 | + public void hashCodeIsResistantToPropertyShadowingResultVariable() { |
| 1051 | + StructWithJavaReservedWords first = StructWithJavaReservedWords.builder().defaultValue("one").build(); |
| 1052 | + StructWithJavaReservedWords second = StructWithJavaReservedWords.builder().defaultValue("one").build(); |
| 1053 | + StructWithJavaReservedWords third = StructWithJavaReservedWords.builder().defaultValue("two").build(); |
| 1054 | + |
| 1055 | + assertEquals(first.hashCode(), second.hashCode()); |
| 1056 | + assertNotEquals(first.hashCode(), third.hashCode()); |
| 1057 | + } |
| 1058 | + |
| 1059 | + @Test |
| 1060 | + public void equalsIsResistantToPropertyShadowingResultVariable() { |
| 1061 | + StructWithJavaReservedWords first = StructWithJavaReservedWords.builder().defaultValue("one").build(); |
| 1062 | + StructWithJavaReservedWords second = StructWithJavaReservedWords.builder().defaultValue("one").build(); |
| 1063 | + StructWithJavaReservedWords third = StructWithJavaReservedWords.builder().defaultValue("two").build(); |
| 1064 | + |
| 1065 | + assertEquals(first, second); |
| 1066 | + assertNotEquals(first, third); |
1024 | 1067 | } |
1025 | 1068 |
|
1026 | 1069 | @Test |
|
0 commit comments