|
23 | 23 |
|
24 | 24 | /**
|
25 | 25 | * Tests that TableSchema.fromImmutableClass() works correctly with immutable classes
|
26 |
| - * that have boolean fields using "is" prefix. |
| 26 | + * that have fields using "is" prefix. |
27 | 27 | */
|
28 |
| -public class ImmutableBooleanIsPrefixTest { |
| 28 | +public class TableSchemaImmutableIsPrefixTest { |
29 | 29 |
|
| 30 | + // Test class for boolean fields with "is" prefix |
30 | 31 | @DynamoDbImmutable(builder = Car.Builder.class)
|
31 | 32 | public static final class Car {
|
32 | 33 | private final String licensePlate;
|
@@ -92,4 +93,70 @@ public void fromImmutableClass_withIsPrefixBooleanSetters_shouldCreateSchemaSucc
|
92 | 93 | "licensePlate", "rusty", "impounded"
|
93 | 94 | );
|
94 | 95 | }
|
| 96 | + |
| 97 | + // Test class for non-boolean fields with "is" prefix |
| 98 | + @DynamoDbImmutable(builder = Vehicle.Builder.class) |
| 99 | + public static final class Vehicle { |
| 100 | + private final String licensePlate; |
| 101 | + private final String isModel; |
| 102 | + private final Integer isYear; |
| 103 | + |
| 104 | + private Vehicle(Builder b) { |
| 105 | + this.licensePlate = b.licensePlate; |
| 106 | + this.isModel = b.isModel; |
| 107 | + this.isYear = b.isYear; |
| 108 | + } |
| 109 | + |
| 110 | + @DynamoDbPartitionKey |
| 111 | + public String licensePlate() { |
| 112 | + return this.licensePlate; |
| 113 | + } |
| 114 | + |
| 115 | + public String isModel() { |
| 116 | + return this.isModel; |
| 117 | + } |
| 118 | + |
| 119 | + public Integer isYear() { |
| 120 | + return this.isYear; |
| 121 | + } |
| 122 | + |
| 123 | + public static final class Builder { |
| 124 | + private String licensePlate; |
| 125 | + private String isModel; |
| 126 | + private Integer isYear; |
| 127 | + |
| 128 | + public Builder licensePlate(String licensePlate) { |
| 129 | + this.licensePlate = licensePlate; |
| 130 | + return this; |
| 131 | + } |
| 132 | + |
| 133 | + public Builder isModel(String isModel) { |
| 134 | + this.isModel = isModel; |
| 135 | + return this; |
| 136 | + } |
| 137 | + |
| 138 | + public Builder isYear(Integer isYear) { |
| 139 | + this.isYear = isYear; |
| 140 | + return this; |
| 141 | + } |
| 142 | + |
| 143 | + public Vehicle build() { |
| 144 | + return new Vehicle(this); |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + public void fromImmutableClass_withIsPrefixNonBooleanFields_shouldNotNormalizeIsPrefix() { |
| 151 | + TableSchema<Vehicle> schema = TableSchema.fromImmutableClass(Vehicle.class); |
| 152 | + |
| 153 | + // Verify the schema was created successfully |
| 154 | + assertThat(schema).isNotNull(); |
| 155 | + assertThat(schema.itemType().rawClass()).isEqualTo(Vehicle.class); |
| 156 | + |
| 157 | + // Verify non-boolean "is" prefix fields are not normalized |
| 158 | + assertThat(schema.attributeNames()).containsExactlyInAnyOrder( |
| 159 | + "licensePlate", "isModel", "isYear" |
| 160 | + ); |
| 161 | + } |
95 | 162 | }
|
0 commit comments