Skip to content

Commit

Permalink
Remove Copyable, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelprazak committed Jun 9, 2022
1 parent 288c799 commit e0f9e19
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.pulumi.resources;

import com.pulumi.core.internal.Copyable;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
Expand All @@ -13,7 +11,7 @@
* @see StackOptions is a bag of optional settings that control a stack's behavior.
*/
@ParametersAreNonnullByDefault
public class StackOptions implements Copyable<StackOptions> {
public class StackOptions {

public static final StackOptions Empty = new Builder().build();

Expand All @@ -40,12 +38,6 @@ public List<ResourceTransformation> resourceTransformations() {
return this.resourceTransformations;
}

public StackOptions copy() {
return new StackOptions(
this.resourceTransformations
);
}

/**
* @return a {@link StackOptions} builder instance
*/
Expand Down Expand Up @@ -100,11 +92,11 @@ public StackOptions build() {
* @return a new {@link StackOptions} with merged values
*/
public static StackOptions merge(@Nullable StackOptions options1, @Nullable StackOptions options2) {
options1 = options1 != null ? options1.copy() : Empty;
options2 = options2 != null ? options2.copy() : Empty;
var opt1 = options1 != null ? options1 : Empty;
var opt2 = options2 != null ? options2 : Empty;

var resourceTransformations = requireNonNull(mergeNullableList(
options1.resourceTransformations, options2.resourceTransformations
opt1.resourceTransformations, opt2.resourceTransformations
));
return new StackOptions(resourceTransformations);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.pulumi.resources;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;

class StackOptionsTest {

public static Stream<Arguments> testMerge() {
final ResourceTransformation transformation1 = args -> Optional.empty();
final ResourceTransformation transformation2 = args -> Optional.empty();
return Stream.of(
arguments(
null,
null,
new StackOptions(List.of())
),
arguments(
null,
new StackOptions(List.of()),
new StackOptions(List.of())
),
arguments(
new StackOptions(List.of()),
null,
new StackOptions(List.of())
),
arguments(
new StackOptions(List.of()),
new StackOptions(List.of()),
new StackOptions(List.of())
),
arguments(
new StackOptions(List.of(transformation1)),
new StackOptions(List.of()),
new StackOptions(List.of(transformation1))
),
arguments(
new StackOptions(List.of()),
new StackOptions(List.of(transformation1)),
new StackOptions(List.of(transformation1))
),
arguments(
new StackOptions(List.of(transformation1)),
new StackOptions(List.of(transformation2)),
new StackOptions(List.of(transformation1, transformation2))
)
);
}

@ParameterizedTest
@MethodSource
void testMerge(@Nullable StackOptions first, @Nullable StackOptions second, StackOptions expected) {
var result = StackOptions.merge(first, second);

assertThat(result.resourceTransformations()).containsExactlyElementsOf(expected.resourceTransformations());
}
}

0 comments on commit e0f9e19

Please sign in to comment.