Skip to content

Commit

Permalink
Simplify Some Test Setup in StateValidation
Browse files Browse the repository at this point in the history
Summary:
While here, I noticed that we needed to always set all of these to empty due to how we’re mocking.  Instead of needing to do this in the majority of the tests, let’s just do that in setup (done in prior diff when adding my test cases), and then people can override it as needed.

Splitting the cleanup (deletion) out into its own diff.

Reviewed By: colriot

Differential Revision: D53113285

fbshipit-source-id: 49e0fb8c579b4f40734ab37e7dc808c52934fee4
  • Loading branch information
Nichole Clarke authored and facebook-github-bot committed Jan 27, 2024
1 parent a083f72 commit a639c6c
Showing 1 changed file with 5 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public void setup() {
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getSpecElementType()).thenReturn(SpecElementType.JAVA_CLASS);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.<StateParamModel>of());
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());
}

@Test
Expand All @@ -70,11 +75,6 @@ public void testTwoStateValuesWithSameNameButDifferentType() {
when(stateValue2.getTypeName()).thenReturn(TypeName.INT);
when(stateValue2.getRepresentedObject()).thenReturn(mRepresentedObject2);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue1, stateValue2));
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand All @@ -96,11 +96,6 @@ public void testTwoStateValuesWithSameNameButDifferentCanUpdateLazily() {
when(stateValue1.canUpdateLazily()).thenReturn(true);
when(stateValue2.getRepresentedObject()).thenReturn(mRepresentedObject2);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue1, stateValue2));
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -339,10 +334,6 @@ public boolean dynamic() {

when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue));
when(mSpecModel.getProps()).thenReturn(ImmutableList.of(prop));
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

final List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -371,11 +362,7 @@ public Class<? extends Annotation> annotationType() {
.thenReturn(ImmutableList.<Annotation>of(injectPropAnnotation));

when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue));
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.of(injectProp));
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

final List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -404,11 +391,7 @@ public Class<? extends Annotation> annotationType() {
when(treeProp.getAnnotations()).thenReturn(ImmutableList.<Annotation>of(treePropAnnotation));

when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue));
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.of(treeProp));
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

final List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -445,11 +428,6 @@ public void testStateWithDifferentReturnTypes() {
.build(),
false /* canUpdateLazily */);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue1, stateValue2));
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -487,11 +465,6 @@ public void testStateWithDifferentReturnTypesAndMismatchedLazy() {
.build(),
true /* canUpdateLazily */);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue1, stateValue2));
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -528,11 +501,6 @@ public void testStateWithCovariantDifferentReturnTypesForJavaSpec() {
.build(),
false /* canUpdateLazily */);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue1, stateValue2));
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -565,11 +533,6 @@ public void testStateWithCovariantDifferentReturnTypesForKotlinSpec() {
false /* canUpdateLazily */);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue1, stateValue2));
when(mSpecModel.getSpecElementType()).thenReturn(SpecElementType.KOTLIN_SINGLETON);
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -604,11 +567,6 @@ public void testStateWithCovariantDifferentReturnTypesForKotlinSpecFirstStateNot
false /* canUpdateLazily */);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue1, stateValue2));
when(mSpecModel.getSpecElementType()).thenReturn(SpecElementType.KOTLIN_SINGLETON);
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down Expand Up @@ -643,11 +601,6 @@ public void testStateWithCovariantDifferentReturnTypesForKotlinSpecAndMismatchLa
false /* canUpdateLazily */);
when(mSpecModel.getStateValues()).thenReturn(ImmutableList.of(stateValue1, stateValue2));
when(mSpecModel.getSpecElementType()).thenReturn(SpecElementType.KOTLIN_SINGLETON);
when(mSpecModel.getProps()).thenReturn(ImmutableList.<PropModel>of());
when(mSpecModel.getInjectProps()).thenReturn(ImmutableList.<InjectPropModel>of());
when(mSpecModel.getTreeProps()).thenReturn(ImmutableList.<TreePropModel>of());
when(mSpecModel.getInterStageInputs()).thenReturn(ImmutableList.of());
when(mSpecModel.getPrepareInterStageInputs()).thenReturn(ImmutableList.of());

List<SpecModelValidationError> validationErrors =
StateValidation.validateStateValues(mSpecModel);
Expand Down

0 comments on commit a639c6c

Please sign in to comment.