Skip to content

Commit

Permalink
chore(jkube-kit-enricher-api): Moved
Browse files Browse the repository at this point in the history
 declaration of JKubeEnricherContext to setUp in JKubeEnricherContextTest
  • Loading branch information
ShantKhatri committed Feb 7, 2024
1 parent b62983d commit 4796623
Showing 1 changed file with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@
class JKubeEnricherContextTest {

private JavaProject javaProject;
private JKubeEnricherContext jKubeEnricherContext;

@BeforeEach
void setUp() {
javaProject = JavaProject.builder()
.groupId("org.eclipse.jkube").artifactId("test-project").version("0.0.1")
.build();
jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
.build();
}

@Test
void builder_whenInvoked_shouldConstructJKubeEnricherContext() {
// Given + When
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
jKubeEnricherContext = jKubeEnricherContext.toBuilder()
.jKubeBuildStrategy(JKubeBuildStrategy.jib)
.processingInstruction("foo", "bar")
.image(ImageConfiguration.builder().name("foo:latest").build())
Expand All @@ -71,9 +75,6 @@ void builder_whenInvoked_shouldConstructJKubeEnricherContext() {
@Test
void getGav_whenInvoked_shouldReturnExpectedGroupArtifactVersion() {
// Given + When
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
.build();

// Then
assertThat(jKubeEnricherContext.getGav())
Expand All @@ -85,9 +86,6 @@ void getGav_whenInvoked_shouldReturnExpectedGroupArtifactVersion() {
@Test
void getDockerJsonConfigString_whenNoServerPresent_shouldReturnBlankString() {
// Given
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
.build();

// When
String dockerConfigJson = jKubeEnricherContext.getDockerJsonConfigString(Collections.emptyList(), "server1");
Expand All @@ -99,9 +97,6 @@ void getDockerJsonConfigString_whenNoServerPresent_shouldReturnBlankString() {
@Test
void getDockerJsonConfigString_whenServerPresent_shouldReturnDockerJsonString() {
// Given
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
.build();

// When
String dockerConfigJson = jKubeEnricherContext.getDockerJsonConfigString(Collections.singletonList(RegistryServerConfiguration.builder()
Expand All @@ -121,7 +116,7 @@ void getProperty_whenPropertyPresent_shouldReturnValue() {
// Given
Properties properties = new Properties();
properties.put("key1", "value1");
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
jKubeEnricherContext = jKubeEnricherContext.toBuilder()
.project(javaProject.toBuilder().properties(properties).build())
.build();

Expand All @@ -136,7 +131,7 @@ void getProperty_whenPropertyPresent_shouldReturnValue() {
void getProperty_whenPropertyAbsent_shouldReturnNull() {
// Given
Properties properties = new Properties();
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
jKubeEnricherContext = jKubeEnricherContext.toBuilder()
.project(javaProject.toBuilder().properties(properties).build())
.build();

Expand All @@ -150,8 +145,7 @@ void getProperty_whenPropertyAbsent_shouldReturnNull() {
@Test
void getBuildStrategy_whenBuildStrategyPresent_shouldReturnBuildStrategy() {
// Given
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
jKubeEnricherContext = jKubeEnricherContext.toBuilder()
.jKubeBuildStrategy(JKubeBuildStrategy.docker)
.build();

Expand All @@ -170,9 +164,6 @@ void getDependencies_whenTransitiveTrue_shouldGetTransitiveDeps() {
.groupId("org.eclipse.jkube").artifactId("test-project").version("0.0.1").build());

javaProject.setDependenciesWithTransitive(deps);
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
.build();

// When
List<Dependency> jKubeEnricherContextDependencies = jKubeEnricherContext.getDependencies(true);
Expand All @@ -190,9 +181,6 @@ void getDependencies_whenTransitiveFalse_shouldGetDeps() {
.groupId("org.eclipse.jkube").artifactId("test-project").version("0.0.1").build());

javaProject.setDependenciesWithTransitive(deps);
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
.build();

// When
List<Dependency> jKubeEnricherContextDependencies = jKubeEnricherContext.getDependencies(false);
Expand All @@ -205,9 +193,6 @@ void getDependencies_whenTransitiveFalse_shouldGetDeps() {
void hasPlugin_withNullGroup_shouldSearchPluginWithArtifactId() {
try (MockedStatic<JKubeProjectUtil> jKubeProjectUtilMockedStatic = mockStatic(JKubeProjectUtil.class)) {
// Given
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
.build();

// When
jKubeEnricherContext.hasPlugin(null, "test-plugin");
Expand All @@ -221,9 +206,6 @@ void hasPlugin_withNullGroup_shouldSearchPluginWithArtifactId() {
void hasPlugin_withGroup_shouldSearchPluginWithArtifactId() {
try (MockedStatic<JKubeProjectUtil> jKubeProjectUtilMockedStatic = mockStatic(JKubeProjectUtil.class)) {
// Given
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
.project(javaProject)
.build();

// When
jKubeEnricherContext.hasPlugin("org.test", "test-plugin");
Expand All @@ -238,7 +220,7 @@ void getProjectClassLoaders_whenInvoked_shouldCreateClassLoaderFromCompileClassp
try (MockedStatic<ClassUtil> classUtilMockedStatic = mockStatic(ClassUtil.class)) {
// Given
File targetDir = new File("target");
JKubeEnricherContext jKubeEnricherContext = JKubeEnricherContext.builder()
jKubeEnricherContext = jKubeEnricherContext.toBuilder()
.project(javaProject.toBuilder()
.compileClassPathElements(Collections.singletonList("/test/foo.jar"))
.outputDirectory(targetDir)
Expand Down

0 comments on commit 4796623

Please sign in to comment.