Skip to content

Commit 7beebbd

Browse files
authored
ProtoReservedFieldTraitValue must be of exactly one type (#249)
* ProtoReservedFieldTraitValue must be of exactly one type * add header
1 parent a1f04e0 commit 7beebbd

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

modules/core/src/alloy/proto/ProtoReservedFieldsTraitValue.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import software.amazon.smithy.model.node.*;
1919
import software.amazon.smithy.utils.SmithyBuilder;
2020

21+
import java.util.stream.Stream;
22+
import java.util.Objects;
23+
2124
public final class ProtoReservedFieldsTraitValue {
2225

2326
public static final String NUMBER = "number";
@@ -29,6 +32,13 @@ public final class ProtoReservedFieldsTraitValue {
2932
public final Range range;
3033

3134
public ProtoReservedFieldsTraitValue(Builder builder) {
35+
if (Stream.of(
36+
builder.number,
37+
builder.name,
38+
builder.range
39+
).filter(Objects::nonNull).count() != 1) {
40+
throw new IllegalArgumentException("ProtoReservedFieldsTraitValue must be of exactly one type");
41+
}
3242
this.number = builder.number;
3343
this.name = builder.name;
3444
this.range = builder.range;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Copyright 2022 Disney Streaming
2+
*
3+
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* https://disneystreaming.github.io/TOST-1.0.txt
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package alloy.proto
17+
18+
final class ProtoReservedFieldsTraitValueSpec extends munit.FunSuite {
19+
20+
test("cannot instantiate invalid ProtoReservedFieldsTraitValue") {
21+
intercept[IllegalArgumentException](
22+
ProtoReservedFieldsTraitValue.builder().build()
23+
)
24+
}
25+
}

0 commit comments

Comments
 (0)