Skip to content

Commit

Permalink
Apply recipes of org.openrewrite.staticanalysis.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Nov 19, 2024
1 parent 37da6da commit 1422502
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
3 changes: 0 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,6 @@
<exclusions>
<exclusion>**/docker/**</exclusion>
<exclusion>**/AbstractComparableTest.java</exclusion>
<exclusion>**/AbstractEqualsTest.java</exclusion>
<exclusion>**/EnsureTest.java</exclusion>
<exclusion>**/ResourceExtractorTest.java</exclusion>
</exclusions>
<activeRecipes>
<recipe>org.openrewrite.maven.BestPractices</recipe>
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/edu/hm/hafner/util/EnsureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void shouldNotThrowExceptionIfContractIsValid() {
Ensure.that(true).isTrue();
Ensure.that("").isNotNull();
Ensure.that("", "").isNotNull();
Ensure.that(null, (Object)null).isNull();
Ensure.that(null, (Object) null).isNull();
Ensure.that(new String[]{""}).isNotEmpty();
Ensure.that(SOME_STRING).isNotEmpty();
Ensure.that(SOME_STRING).isNotBlank();
Expand Down Expand Up @@ -89,29 +89,29 @@ void shouldThrowExceptionIfContractIsViolated() {
*/
@Test @SuppressWarnings("NullAway")
void shouldThrowNpeIfContractIsViolated() {
assertThatThrownBy(() -> Ensure.that((Object)null).isNotNull(ERROR_MESSAGE))
assertThatThrownBy(() -> Ensure.that((Object) null).isNotNull(ERROR_MESSAGE))
.isInstanceOf(NullPointerException.class).hasMessage(ERROR_MESSAGE);
assertThatThrownBy(() -> Ensure.that(SOME_STRING, (Object)null).isNotNull(ERROR_MESSAGE))
assertThatThrownBy(() -> Ensure.that(SOME_STRING, (Object) null).isNotNull(ERROR_MESSAGE))
.isInstanceOf(NullPointerException.class).hasMessage(ERROR_MESSAGE);
assertThatThrownBy(() -> Ensure.that(null, SOME_STRING).isNotNull(ERROR_MESSAGE))
.isInstanceOf(NullPointerException.class).hasMessage(ERROR_MESSAGE);
assertThatThrownBy(() -> Ensure.that(null, (Object[]) null).isNotNull(ERROR_MESSAGE))
.isInstanceOf(NullPointerException.class).hasMessage(ERROR_MESSAGE);
assertThatThrownBy(() -> Ensure.that((Object)null).isNotNull())
assertThatThrownBy(() -> Ensure.that((Object) null).isNotNull())
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> Ensure.that(SOME_STRING, (Object)null).isNotNull())
assertThatThrownBy(() -> Ensure.that(SOME_STRING, (Object) null).isNotNull())
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> Ensure.that(null, SOME_STRING).isNotNull())
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> Ensure.that(null, (Object[]) null).isNotNull())
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> Ensure.that((Object[])null).isNotEmpty(ERROR_MESSAGE))
assertThatThrownBy(() -> Ensure.that((Object[]) null).isNotEmpty(ERROR_MESSAGE))
.isInstanceOf(NullPointerException.class).hasMessage(ERROR_MESSAGE);
assertThatThrownBy(() -> Ensure.that((String)null).isNotEmpty(ERROR_MESSAGE))
assertThatThrownBy(() -> Ensure.that((String) null).isNotEmpty(ERROR_MESSAGE))
.isInstanceOf(NullPointerException.class).hasMessage(ERROR_MESSAGE);
assertThatThrownBy(() -> Ensure.that((Object[])null).isNotEmpty())
assertThatThrownBy(() -> Ensure.that((Object[]) null).isNotEmpty())
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> Ensure.that((String)null).isNotEmpty())
assertThatThrownBy(() -> Ensure.that((String) null).isNotEmpty())
.isInstanceOf(NullPointerException.class);
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/edu/hm/hafner/util/ResourceExtractorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void shouldExtractFromFolder(@TempDir final Path targetFolder) {
void shouldThrowExceptionIfTargetIsFileInFolder() throws IOException {
var proxy = new ResourceExtractor(ResourceExtractor.class);

Path tempFile = Files.createTempFile("tmp", "tmp");
var tempFile = Files.createTempFile("tmp", "tmp");
assertThatIllegalArgumentException().isThrownBy(() -> proxy.extract(tempFile, MANIFEST_MF));
}

Expand All @@ -89,7 +89,7 @@ void shouldExtractFromJar(@TempDir final Path targetFolder) {
void shouldThrowExceptionIfTargetIsFileInJar() throws IOException {
var proxy = new ResourceExtractor(StringUtils.class);

Path tempFile = Files.createTempFile("tmp", "tmp");
var tempFile = Files.createTempFile("tmp", "tmp");
assertThatIllegalArgumentException().isThrownBy(() -> proxy.extract(tempFile, MANIFEST_MF));
}

Expand All @@ -103,20 +103,20 @@ void shouldThrowExceptionIfFileDoesNotExistInJar(@TempDir final Path targetFolde

@Test
void shouldHandleClassloaderProblems() {
ProtectionDomain protectionDomain = mock(ProtectionDomain.class);
var protectionDomain = mock(ProtectionDomain.class);

assertThatIllegalArgumentException()
.isThrownBy(() -> new ResourceExtractor(ResourceExtractor.class, protectionDomain))
.withMessageContainingAll("CodeSource for", "ResourceExtractor");

CodeSource codeSource = mock(CodeSource.class);
var codeSource = mock(CodeSource.class);
when(protectionDomain.getCodeSource()).thenReturn(codeSource);

assertThatIllegalArgumentException()
.isThrownBy(() -> new ResourceExtractor(ResourceExtractor.class, protectionDomain))
.withMessageContaining("CodeSource location for", "ResourceExtractor");

URL url = mock(URL.class);
var url = mock(URL.class);
when(codeSource.getLocation()).thenReturn(url);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ResourceExtractor(ResourceExtractor.class, protectionDomain))
Expand Down

0 comments on commit 1422502

Please sign in to comment.