Skip to content

Commit

Permalink
remove usage of assert keyword and throw NullPointerException instead…
Browse files Browse the repository at this point in the history
… of AssertionError
  • Loading branch information
oliverlietz committed Nov 17, 2024
1 parent a7debc1 commit fb1dfce
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.ops4j.pax.exam.container.remote;

import java.util.Objects;

import static org.ops4j.pax.exam.OptionUtils.filter;

import org.ops4j.pax.exam.Option;
Expand All @@ -35,8 +37,8 @@ public class Parser {
public Parser(Option[] options) {
extractArguments(filter(RBCPortOption.class, options));
extractArguments(filter(RBCLookupTimeoutOption.class, options));
assert port != null : "Port should never be null.";
assert host != null : "Host should never be null.";
Objects.requireNonNull(host, "Host must not be be null.");
Objects.requireNonNull(port, "Port must not be be null.");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.ops4j.pax.exam.container.remote.options;

import java.util.Objects;

import org.ops4j.pax.exam.Option;

/**
Expand All @@ -29,8 +31,8 @@ public class RBCPortOption implements Option {
private String host;

public RBCPortOption(String host, Integer port) {
assert host != null : "Host should never be null.";
assert port != null : "Port should never be null.";
Objects.requireNonNull(host, "Host must not be be null.");
Objects.requireNonNull(port, "Port must not be be null.");

this.host = host;
this.port = port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class ParserTest {

@Test(expected = AssertionError.class)
@Test(expected = NullPointerException.class)
public void testDefaults() {
Option[] options = CoreOptions.options();
new Parser(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Objects;
import java.util.Stack;

import org.ops4j.io.StreamUtils;
Expand Down Expand Up @@ -79,7 +80,7 @@ public class RemoteBundleContextClientImpl implements RemoteBundleContextClient
*/
public RemoteBundleContextClientImpl(final String name, final Integer registry,
final RelativeTimeout timeout) {
assert registry != null : "registry should not be null";
Objects.requireNonNull(registry, "Registry must not be null.");

this.registry = registry;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.ops4j.pax.exam.TestAddress;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void setUp() {
}

public void invoke(TestAddress address) throws Exception {
assert (address != null) : "TestAddress must not be null.";
Objects.requireNonNull(address, "TestAddress must not be null.");
// you can directly invoke:
TestContainer container = map.get(address);
if (container == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.ops4j.pax.exam.TestAddress;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void setUp() {
}

public void invoke(TestAddress address) throws Exception {
assert (address != null) : "TestAddress must not be null.";
Objects.requireNonNull(address, "TestAddress must not be null.");

TestContainer testContainer = map.get(address);
if (testContainer == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.ops4j.pax.exam.TestAddress;
Expand Down Expand Up @@ -104,7 +105,7 @@ public static synchronized StagedExamReactor getInstance(List<TestContainer> con
}

public void invoke(TestAddress address) throws Exception {
assert (address != null) : "TestAddress must not be null.";
Objects.requireNonNull(address, "TestAddress must not be null.");

TestContainer testContainer = testToContainerMap.get(address);
if (testContainer == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testEmptyContainersAndBuilders() throws IOException {
assertThat(reactor.getTargets().size(), is(0));
}

@Test(expected = AssertionError.class)
@Test(expected = NullPointerException.class)
public void testInvokeNull() throws Exception {
List<TestContainer> containers = new ArrayList<TestContainer>();
List<TestProbeBuilder> providers = new ArrayList<TestProbeBuilder>();
Expand Down

0 comments on commit fb1dfce

Please sign in to comment.