BAEL2489 Avoid check for null statement in Java
This commit is contained in:
parent
66146ea761
commit
c7c5d56eb3
|
@ -15,11 +15,29 @@
|
|||
</parent>
|
||||
|
||||
<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>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<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>
|
||||
</project>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.baeldung.nulls;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
public class FindBugsAnnotations {
|
||||
|
||||
public void accept(@Nonnull Object param) {
|
||||
public void accept(@NotNull Object param) {
|
||||
System.out.println(param.toString());
|
||||
}
|
||||
|
||||
|
@ -13,7 +14,7 @@ public class FindBugsAnnotations {
|
|||
System.out.println("Printing " + param);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public Object process() throws Exception {
|
||||
Object result = doSomething();
|
||||
if (result == null) {
|
|
@ -1,10 +1,10 @@
|
|||
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.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PrimitivesAndWrapperUnitTest {
|
||||
|
||||
@Test
|
|
@ -1,10 +1,9 @@
|
|||
package com.baeldung.nulls;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class UsingLombokUnitTest {
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
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.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class UsingObjectsUnitTest {
|
||||
|
||||
private UsingObjects classUnderTest;
|
||||
|
@ -19,7 +18,7 @@ class UsingObjectsUnitTest {
|
|||
@Test
|
||||
public void whenArgIsNull_thenThrowException() {
|
||||
|
||||
assertThrows(Exception.class, () -> classUnderTest.accept(null));
|
||||
assertThrows(NullPointerException.class, () -> classUnderTest.accept(null));
|
||||
}
|
||||
|
||||
@Test
|
|
@ -1,14 +1,14 @@
|
|||
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.assertThrows;
|
||||
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 {
|
||||
|
||||
private UsingOptional classUnderTest;
|
|
@ -1,10 +1,9 @@
|
|||
package com.baeldung.nulls;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class UsingStringUtilsUnitTest {
|
||||
|
Loading…
Reference in New Issue