Skip to content

Commit

Permalink
Fix test with code style
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSiJun528 committed Oct 9, 2024
1 parent b1fd50b commit a985271
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,17 @@ void customizeWhenJpaFacetAbsentShouldNotAddKotlinJpaPlugin() {
assertThat(build.plugins().values()).isEmpty();
}

private GradleBuild getCustomizedBuild(Dependency dependency) {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", dependency)
.build();
SimpleKotlinProjectSettings settings = new SimpleKotlinProjectSettings("1.2.70");
MutableProjectDescription projectDescription = new MutableProjectDescription();
projectDescription.setPlatformVersion(Version.parse("1.0.0"));
KotlinJpaGradleBuildCustomizer customizer = new KotlinJpaGradleBuildCustomizer(metadata, settings,
projectDescription);
GradleBuild build = new GradleBuild(new MetadataBuildItemResolver(metadata, Version.parse("2.0.0.RELEASE")));
build.dependencies().add("foo");
customizer.customize(build);
return build;
}

@Test
void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() {
Dependency dependency = Dependency.withId("foo", "jakarta.persistence", "jakarta.persistence-api");
dependency.setFacets(Collections.singletonList("jpa"));
GradleBuild build = getCustomizedBuild(dependency);
assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> {
assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa");
});
assertThat(build.plugins().values()).singleElement()
.satisfies((plugin) -> assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa"));
assertThat(build.extensions().values()).singleElement().satisfies((extension) -> {
assertThat(extension.getName()).isEqualTo("allOpen");
assertThat(extension.getInvocations())
.filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation"))
.filteredOn((invocation) -> Objects.equals(invocation.getTarget(), "annotation"))
.extracting("arguments")
.containsExactlyInAnyOrder(List.of("jakarta.persistence.Entity"),
List.of("jakarta.persistence.MappedSuperclass"), List.of("jakarta.persistence.Embeddable"));
Expand All @@ -99,18 +83,32 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() {
Dependency dependency = Dependency.withId("foo", "javax.persistence", "javax.persistence-api");
dependency.setFacets(Collections.singletonList("jpa"));
GradleBuild build = getCustomizedBuild(dependency);
assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> {
assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa");
});
assertThat(build.plugins().values()).singleElement()
.satisfies((plugin) -> assertThat(plugin.getId()).isEqualTo("org.jetbrains.kotlin.plugin.jpa"));
assertThat(build.extensions().values()).singleElement().satisfies((extension) -> {
assertThat(extension.getName()).isEqualTo("allOpen");
assertThat(extension.getInvocations())
.filteredOn(invocation -> Objects.equals(invocation.getTarget(), "annotation"))
.filteredOn((invocation) -> Objects.equals(invocation.getTarget(), "annotation"))
.extracting("arguments")
.containsExactlyInAnyOrder("javax.persistence.Entity", "javax.persistence.MappedSuperclass",
"javax.persistence.Embeddable");
.containsExactlyInAnyOrder(List.of("javax.persistence.Entity"),
List.of("javax.persistence.MappedSuperclass"), List.of("javax.persistence.Embeddable"));
});

}

private GradleBuild getCustomizedBuild(Dependency dependency) {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", dependency)
.build();
SimpleKotlinProjectSettings settings = new SimpleKotlinProjectSettings("1.2.70");
MutableProjectDescription projectDescription = new MutableProjectDescription();
projectDescription.setPlatformVersion(Version.parse("1.0.0"));
KotlinJpaGradleBuildCustomizer customizer = new KotlinJpaGradleBuildCustomizer(metadata, settings,
projectDescription);
GradleBuild build = new GradleBuild(new MetadataBuildItemResolver(metadata, Version.parse("2.0.0.RELEASE")));
build.dependencies().add("foo");
customizer.customize(build);
return build;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,12 +31,6 @@

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link KotlinJpaMavenBuildCustomizer}.
*
* @author Madhura Bhave
* @author Sebastien Deleuze
*/
class KotlinJpaMavenBuildCustomizerTests {

@Test
Expand Down Expand Up @@ -80,7 +74,7 @@ void customizeWhenJakartaPersistencePresentShouldCustomizeAllOpenWithJakarta() {
MavenPlugin.Configuration configuration = plugin.getConfiguration();
assertThat(configuration.getSettings()
.stream()
.filter(setting -> "option".equals(setting.getName()))
.filter((setting) -> "option".equals(setting.getName()))
.map(MavenPlugin.Setting::getValue))
.containsExactlyInAnyOrder("all-open:annotation=jakarta.persistence.Entity",
"all-open:annotation=jakarta.persistence.MappedSuperclass",
Expand All @@ -101,7 +95,7 @@ void customizeWhenJavaxPersistencePresentShouldCustomizeAllOpenWithJavax() {
MavenPlugin.Configuration configuration = plugin.getConfiguration();
assertThat(configuration.getSettings()
.stream()
.filter(setting -> "option".equals(setting.getName()))
.filter((setting) -> "option".equals(setting.getName()))
.map(MavenPlugin.Setting::getValue))
.containsExactlyInAnyOrder("all-open:annotation=javax.persistence.Entity",
"all-open:annotation=javax.persistence.MappedSuperclass",
Expand Down

0 comments on commit a985271

Please sign in to comment.