-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1b22341
commit c6cf239
Showing
7 changed files
with
205 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ilder-test/src/main/java/io/soabase/recordbuilder/test/UnmodifiableCollectionsRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2019 The original author or authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.soabase.recordbuilder.test; | ||
|
||
import io.soabase.recordbuilder.core.RecordBuilder; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
@RecordBuilder | ||
@RecordBuilder.Options(useUnmodifiableCollections = true) | ||
record UnmodifiableCollectionsRecord(List<Integer> aList, Set<String> orderedSet, Map<String, Integer> orderedMap, | ||
Collection<String> aCollection) { | ||
} |
72 changes: 72 additions & 0 deletions
72
...-test/src/test/java/io/soabase/recordbuilder/test/TestUnmodifiableCollectionsBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2019 The original author or authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.soabase.recordbuilder.test; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.LinkedHashMap; | ||
import java.util.LinkedHashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static java.util.Map.entry; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class TestUnmodifiableCollectionsBuilder { | ||
|
||
@Test | ||
void shouldWrapCollectionsWithUnmodifiableView() { | ||
// given | ||
var list = new ArrayList<Integer>(); | ||
list.add(2); | ||
list.add(1); | ||
list.add(0); | ||
|
||
var orderedSet = new LinkedHashSet<String>(); | ||
orderedSet.add("C"); | ||
orderedSet.add("B"); | ||
orderedSet.add("A"); | ||
|
||
var orderedMap = new LinkedHashMap<String, Integer>(); | ||
orderedMap.put("C", 2); | ||
orderedMap.put("B", 1); | ||
orderedMap.put("A", 0); | ||
|
||
var collection = new HashSet<String>(); | ||
collection.add("C"); | ||
collection.add("B"); | ||
collection.add("A"); | ||
|
||
// when | ||
var record = UnmodifiableCollectionsRecordBuilder.builder().aList(list).orderedSet(orderedSet) | ||
.orderedMap(orderedMap).aCollection(collection).build(); | ||
|
||
// then | ||
assertAll(() -> assertThrows(UnsupportedOperationException.class, () -> record.aList().add(9)), | ||
() -> assertThat(record.aList()).containsExactly(2, 1, 0), | ||
() -> assertThrows(UnsupportedOperationException.class, () -> record.orderedSet().add("newElement")), | ||
() -> assertThat(record.orderedSet()).containsExactly("C", "B", "A"), | ||
() -> assertThrows(UnsupportedOperationException.class, () -> record.orderedMap().put("newElement", 9)), | ||
() -> assertThat(record.orderedMap()).containsExactly(entry("C", 2), entry("B", 1), entry("A", 0)), | ||
() -> assertThrows(UnsupportedOperationException.class, () -> record.aCollection().add("newElement")), | ||
() -> assertThat(record.aCollection()).containsExactlyInAnyOrder("C", "B", "A")); | ||
} | ||
} |