Polish ManagedList[Tests] and ManagedSet[Tests]
This commit is contained in:
@@ -25,61 +25,61 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ManagedList}.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class ManagedListTests {
|
||||
class ManagedListTests {
|
||||
|
||||
@Test
|
||||
public void mergeSunnyDay() {
|
||||
void mergeSunnyDay() {
|
||||
ManagedList parent = ManagedList.of("one", "two");
|
||||
ManagedList child = ManagedList.of("three");
|
||||
child.setMergeEnabled(true);
|
||||
List mergedList = child.merge(parent);
|
||||
assertThat(mergedList.size()).as("merge() obviously did not work.").isEqualTo(3);
|
||||
assertThat(mergedList).as("merge() obviously did not work.").containsExactly("one", "two", "three");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeWithNullParent() {
|
||||
void mergeWithNullParent() {
|
||||
ManagedList child = ManagedList.of("one");
|
||||
child.setMergeEnabled(true);
|
||||
assertThat(child.merge(null)).isSameAs(child);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeNotAllowedWhenMergeNotEnabled() {
|
||||
void mergeNotAllowedWhenMergeNotEnabled() {
|
||||
ManagedList child = new ManagedList();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
child.merge(null));
|
||||
assertThatIllegalStateException().isThrownBy(() -> child.merge(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeWithNonCompatibleParentType() {
|
||||
void mergeWithIncompatibleParentType() {
|
||||
ManagedList child = ManagedList.of("one");
|
||||
child.setMergeEnabled(true);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
child.merge("hello"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> child.merge("hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeEmptyChild() {
|
||||
void mergeEmptyChild() {
|
||||
ManagedList parent = ManagedList.of("one", "two");
|
||||
ManagedList child = new ManagedList();
|
||||
child.setMergeEnabled(true);
|
||||
List mergedList = child.merge(parent);
|
||||
assertThat(mergedList.size()).as("merge() obviously did not work.").isEqualTo(2);
|
||||
assertThat(mergedList).as("merge() obviously did not work.").containsExactly("one", "two");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeChildValuesOverrideTheParents() {
|
||||
void mergedChildValuesDoNotOverrideTheParents() {
|
||||
// doesn't make much sense in the context of a list...
|
||||
ManagedList parent = ManagedList.of("one", "two");
|
||||
ManagedList child = ManagedList.of("one");
|
||||
child.setMergeEnabled(true);
|
||||
List mergedList = child.merge(parent);
|
||||
assertThat(mergedList.size()).as("merge() obviously did not work.").isEqualTo(3);
|
||||
assertThat(mergedList).as("merge() obviously did not work.").containsExactly("one", "two", "one");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,61 +25,62 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ManagedSet}.
|
||||
*
|
||||
* @author Rick Evans
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class ManagedSetTests {
|
||||
class ManagedSetTests {
|
||||
|
||||
@Test
|
||||
public void mergeSunnyDay() {
|
||||
void mergeSunnyDay() {
|
||||
ManagedSet parent = ManagedSet.of("one", "two");
|
||||
ManagedSet child = ManagedSet.of("three");
|
||||
child.add("three");
|
||||
child.add("four");
|
||||
child.setMergeEnabled(true);
|
||||
Set mergedSet = child.merge(parent);
|
||||
assertThat(mergedSet.size()).as("merge() obviously did not work.").isEqualTo(3);
|
||||
assertThat(mergedSet).as("merge() obviously did not work.").containsExactly("one", "two", "three", "four");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeWithNullParent() {
|
||||
void mergeWithNullParent() {
|
||||
ManagedSet child = ManagedSet.of("one");
|
||||
child.setMergeEnabled(true);
|
||||
assertThat(child.merge(null)).isSameAs(child);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeNotAllowedWhenMergeNotEnabled() {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
new ManagedSet().merge(null));
|
||||
void mergeNotAllowedWhenMergeNotEnabled() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> new ManagedSet().merge(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeWithNonCompatibleParentType() {
|
||||
void mergeWithNonCompatibleParentType() {
|
||||
ManagedSet child = ManagedSet.of("one");
|
||||
child.setMergeEnabled(true);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
child.merge("hello"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> child.merge("hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeEmptyChild() {
|
||||
void mergeEmptyChild() {
|
||||
ManagedSet parent = ManagedSet.of("one", "two");
|
||||
ManagedSet child = new ManagedSet();
|
||||
child.setMergeEnabled(true);
|
||||
Set mergedSet = child.merge(parent);
|
||||
assertThat(mergedSet.size()).as("merge() obviously did not work.").isEqualTo(2);
|
||||
assertThat(mergedSet).as("merge() obviously did not work.").containsExactly("one", "two");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeChildValuesOverrideTheParents() {
|
||||
void mergeChildValuesOverrideTheParents() {
|
||||
// asserts that the set contract is not violated during a merge() operation...
|
||||
ManagedSet parent = ManagedSet.of("one", "two");
|
||||
ManagedSet child = ManagedSet.of("one");
|
||||
child.setMergeEnabled(true);
|
||||
Set mergedSet = child.merge(parent);
|
||||
assertThat(mergedSet.size()).as("merge() obviously did not work.").isEqualTo(2);
|
||||
assertThat(mergedSet).as("merge() obviously did not work.").containsExactly("one", "two");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user