* BAEL-4401

* Update with master and resolve conflicts
This commit is contained in:
Amy DeGregorio 2020-08-24 11:20:26 -04:00 committed by GitHub
parent bbeb322d41
commit aa96649458
3 changed files with 35 additions and 2 deletions

View File

@ -30,5 +30,4 @@
<!-- testing -->
<assertj-core.version>3.10.0</assertj-core.version>
</properties>
</project>
</project>

View File

@ -0,0 +1,17 @@
package com.baeldung.nullmethodparameter;
public class NullParameterExample {
public void processSomethingNotNull(Object myParameter) {
if (myParameter == null) {
throw new IllegalArgumentException("Parameter 'myParameter' cannot be null");
}
//Do something with the parameter
}
public void processSomethingElseNotNull(Object myParameter) {
if (myParameter == null) {
throw new NullPointerException("Parameter 'myParameter' cannot be null");
}
//Do something with the parameter
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.nullmethodparameter;
import org.junit.Test;
public class NullParameterExampleUnitTest {
@Test(expected = IllegalArgumentException.class)
public void givenNullParameter_whenProcessSomethingNotNull_thenIllegalArgumentException() {
NullParameterExample example = new NullParameterExample();
example.processSomethingNotNull(null);
}
@Test(expected = NullPointerException.class)
public void givenNullParameter_whenProcessSomethingElseNotNull_thenNullPointerException() {
NullParameterExample example = new NullParameterExample();
example.processSomethingElseNotNull(null);
}
}