-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: adjust resolver methods to ignore nullable values
- Loading branch information
Showing
25 changed files
with
417 additions
and
306 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
25 changes: 25 additions & 0 deletions
25
...api/src/test/java/org/citrusframework/openapi/actions/OpenApiClientActionBuilderTest.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,25 @@ | ||
package org.citrusframework.openapi.actions; | ||
|
||
import org.citrusframework.endpoint.Endpoint; | ||
import org.citrusframework.openapi.OpenApiSpecification; | ||
import org.citrusframework.spi.AbstractReferenceResolverAwareTestActionBuilder; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class OpenApiClientActionBuilderTest { | ||
|
||
private OpenApiClientActionBuilder fixture; | ||
|
||
@BeforeMethod | ||
public void beforeMethod() { | ||
fixture = new OpenApiClientActionBuilder(mock(Endpoint.class), mock(OpenApiSpecification.class)); | ||
} | ||
|
||
@Test | ||
public void isReferenceResolverAwareTestActionBuilder() { | ||
assertTrue(fixture instanceof AbstractReferenceResolverAwareTestActionBuilder<?>, "Is instanceof AbstractReferenceResolverAwareTestActionBuilder"); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...api/src/test/java/org/citrusframework/openapi/actions/OpenApiServerActionBuilderTest.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,25 @@ | ||
package org.citrusframework.openapi.actions; | ||
|
||
import org.citrusframework.endpoint.Endpoint; | ||
import org.citrusframework.openapi.OpenApiSpecification; | ||
import org.citrusframework.spi.AbstractReferenceResolverAwareTestActionBuilder; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class OpenApiServerActionBuilderTest { | ||
|
||
private OpenApiServerActionBuilder fixture; | ||
|
||
@BeforeMethod | ||
public void beforeMethod() { | ||
fixture = new OpenApiServerActionBuilder(mock(Endpoint.class), mock(OpenApiSpecification.class)); | ||
} | ||
|
||
@Test | ||
public void isReferenceResolverAwareTestActionBuilder() { | ||
assertTrue(fixture instanceof AbstractReferenceResolverAwareTestActionBuilder<?>, "Is instanceof AbstractReferenceResolverAwareTestActionBuilder"); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/org/citrusframework/spi/AbstractReferenceResolverAwareTestActionBuilder.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,32 @@ | ||
package org.citrusframework.spi; | ||
|
||
import jakarta.annotation.Nullable; | ||
import org.citrusframework.TestAction; | ||
import org.citrusframework.TestActionBuilder; | ||
|
||
public abstract class AbstractReferenceResolverAwareTestActionBuilder<T extends TestAction> implements TestActionBuilder.DelegatingTestActionBuilder<T>, ReferenceResolverAware { | ||
|
||
/** Bean reference resolver */ | ||
protected ReferenceResolver referenceResolver; | ||
|
||
protected TestActionBuilder<? extends T> delegate; | ||
|
||
@Override | ||
public TestActionBuilder<? extends T> getDelegate() { | ||
return delegate; | ||
} | ||
|
||
/** | ||
* Specifies the referenceResolver. | ||
*/ | ||
@Override | ||
public void setReferenceResolver(@Nullable ReferenceResolver referenceResolver) { | ||
if (referenceResolver != null) { | ||
this.referenceResolver = referenceResolver; | ||
|
||
if (delegate instanceof ReferenceResolverAware referenceResolverAware) { | ||
referenceResolverAware.setReferenceResolver(referenceResolver); | ||
} | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...est/java/org/citrusframework/spi/AbstractReferenceResolverAwareTestActionBuilderTest.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,87 @@ | ||
package org.citrusframework.spi; | ||
|
||
import org.citrusframework.TestAction; | ||
import org.citrusframework.TestActionBuilder; | ||
import org.mockito.Mock; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
import static org.mockito.MockitoAnnotations.openMocks; | ||
import static org.springframework.test.util.ReflectionTestUtils.getField; | ||
import static org.springframework.test.util.ReflectionTestUtils.setField; | ||
|
||
public class AbstractReferenceResolverAwareTestActionBuilderTest { | ||
|
||
@Mock | ||
private ReferenceResolver referenceResolver; | ||
|
||
@Mock | ||
private TestReferenceResolver referenceResolverAware; | ||
|
||
private AbstractReferenceResolverAwareTestActionBuilder fixture; | ||
|
||
private AutoCloseable openedMocks; | ||
|
||
@BeforeMethod | ||
public void beforeMethod() { | ||
openedMocks = openMocks(this); | ||
|
||
fixture = new AbstractReferenceResolverAwareTestActionBuilder() { | ||
|
||
@Override | ||
public TestAction build() { | ||
throw new IllegalArgumentException("Test implementation!"); | ||
} | ||
}; | ||
|
||
setField(fixture, "delegate", referenceResolverAware); | ||
} | ||
|
||
@Test | ||
public void getDelegate() { | ||
assertEquals(referenceResolverAware, fixture.getDelegate()); | ||
} | ||
|
||
@Test | ||
public void setReferenceResolver() { | ||
fixture.setReferenceResolver(referenceResolver); | ||
|
||
assertNotNull(getField(fixture, "referenceResolver"), "ReferenceResolver should be set"); | ||
verify(referenceResolverAware).setReferenceResolver(referenceResolver); | ||
} | ||
|
||
@Test | ||
public void setReferenceResolver_doesNotPropagateToNonReferenceResolverAware() { | ||
var testActionBuilder = mock(TestActionBuilder.class); | ||
setField(fixture, "delegate", testActionBuilder); | ||
|
||
fixture.setReferenceResolver(referenceResolver); | ||
|
||
assertNotNull(getField(fixture, "referenceResolver"), "ReferenceResolver should be set"); | ||
verifyNoInteractions(referenceResolverAware); | ||
verifyNoInteractions(testActionBuilder); | ||
} | ||
|
||
@Test | ||
public void setReferenceResolver_ignoresNullReferenceResolver() { | ||
fixture.setReferenceResolver(null); | ||
|
||
assertNull(getField(fixture, "referenceResolver"), "ReferenceResolver should NOT be set"); | ||
verifyNoInteractions(referenceResolverAware); | ||
} | ||
|
||
@AfterMethod | ||
public void afterMethod() throws Exception { | ||
openedMocks.close(); | ||
} | ||
|
||
private abstract static class TestReferenceResolver implements TestActionBuilder, ReferenceResolverAware { | ||
} | ||
} |
Oops, something went wrong.