BAEL2489 Avoid check for null statement in Java
This commit is contained in:
parent
66146ea761
commit
c7c5d56eb3
|
@ -15,11 +15,29 @@
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>${intellij.annotations.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>${commons-lang3.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<intellij.annotations.version>16.0.2</intellij.annotations.version>
|
||||||
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package com.baeldung.nulls;
|
package com.baeldung.nulls;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import javax.annotation.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|
||||||
public class FindBugsAnnotations {
|
public class FindBugsAnnotations {
|
||||||
|
|
||||||
public void accept(@Nonnull Object param) {
|
public void accept(@NotNull Object param) {
|
||||||
System.out.println(param.toString());
|
System.out.println(param.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ public class FindBugsAnnotations {
|
||||||
System.out.println("Printing " + param);
|
System.out.println("Printing " + param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@NotNull
|
||||||
public Object process() throws Exception {
|
public Object process() throws Exception {
|
||||||
Object result = doSomething();
|
Object result = doSomething();
|
||||||
if (result == null) {
|
if (result == null) {
|
|
@ -1,10 +1,10 @@
|
||||||
package com.baeldung.nulls;
|
package com.baeldung.nulls;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class PrimitivesAndWrapperUnitTest {
|
class PrimitivesAndWrapperUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
|
@ -1,10 +1,9 @@
|
||||||
package com.baeldung.nulls;
|
package com.baeldung.nulls;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
class UsingLombokUnitTest {
|
class UsingLombokUnitTest {
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package com.baeldung.nulls;
|
package com.baeldung.nulls;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class UsingObjectsUnitTest {
|
class UsingObjectsUnitTest {
|
||||||
|
|
||||||
private UsingObjects classUnderTest;
|
private UsingObjects classUnderTest;
|
||||||
|
@ -19,7 +18,7 @@ class UsingObjectsUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenArgIsNull_thenThrowException() {
|
public void whenArgIsNull_thenThrowException() {
|
||||||
|
|
||||||
assertThrows(Exception.class, () -> classUnderTest.accept(null));
|
assertThrows(NullPointerException.class, () -> classUnderTest.accept(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
|
@ -1,14 +1,14 @@
|
||||||
package com.baeldung.nulls;
|
package com.baeldung.nulls;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class UsingOptionalUnitTest {
|
class UsingOptionalUnitTest {
|
||||||
|
|
||||||
private UsingOptional classUnderTest;
|
private UsingOptional classUnderTest;
|
|
@ -1,10 +1,9 @@
|
||||||
package com.baeldung.nulls;
|
package com.baeldung.nulls;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
class UsingStringUtilsUnitTest {
|
class UsingStringUtilsUnitTest {
|
||||||
|
|
Loading…
Reference in New Issue