Skip to content

Commit

Permalink
#37: CommandLineOptions methods never return null
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Dec 3, 2015
1 parent 6c9d0a5 commit fc76673
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
Expand Up @@ -10,6 +10,7 @@

package org.junit.gen5.commons.util;

import java.util.Collection;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -43,6 +44,10 @@ public static void notEmpty(String str, Supplier<String> messageSupplier) {
condition(StringUtils.isNotEmpty(str), messageSupplier);
}

public static void notEmpty(Collection<?> collection, String message) {
condition(collection != null && !collection.isEmpty(), message);
}

/**
* @see StringUtils#isNotBlank(String)
*/
Expand Down
Expand Up @@ -111,10 +111,9 @@ private TestPlanSpecification createTestPlanSpecification() {
else {
testPlanSpecification = TestPlanSpecification.build(testPlanSpecificationElementsFromArguments());
}
if (options.getClassnameFilter() != null) {
testPlanSpecification.filterWith(classNameMatches(options.getClassnameFilter()));
}
if (options.getTagsFilter() != null && !options.getTagsFilter().isEmpty()) {
options.getClassnameFilter().ifPresent(
classnameFilter -> testPlanSpecification.filterWith(classNameMatches(classnameFilter)));
if (!options.getTagsFilter().isEmpty()) {
testPlanSpecification.filterWith(byTags(options.getTagsFilter()));
}
return testPlanSpecification;
Expand All @@ -132,7 +131,7 @@ private void printSummaryToStandardOut(TestExecutionSummary summary) {
}

private List<TestPlanSpecificationElement> testPlanSpecificationElementsFromArguments() {
Preconditions.notNull(options.getArguments(), "No arguments given");
Preconditions.notEmpty(options.getArguments(), "No arguments given");
return toTestPlanSpecificationElements(options.getArguments());
}

Expand Down
Expand Up @@ -10,7 +10,9 @@

package org.junit.gen5.console.options;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import io.airlift.airline.Arguments;
import io.airlift.airline.Command;
Expand Down Expand Up @@ -42,12 +44,12 @@ public class AirlineCommandLineOptions implements CommandLineOptions {
private String classnameFilter;

@Option(name = {"-t", "--filter-tags"}, description = "Give a tag to include in the test run. This option can be repeated.")
private List<String> tagsFilter;
private List<String> tagsFilter = new ArrayList<>();

@Arguments(description = "Test classes, methods or packages to execute."
+ " If --all|-a has been chosen, arguments can list all classpath roots that should be considered for test scanning,"
+ " or none if the full classpath shall be scanned.")
private List<String> arguments;
private List<String> arguments = new ArrayList<>();
// @formatter:on

@Override
Expand Down Expand Up @@ -76,8 +78,8 @@ public boolean isHideDetails() {
}

@Override
public String getClassnameFilter() {
return classnameFilter;
public Optional<String> getClassnameFilter() {
return Optional.ofNullable(classnameFilter);
}

@Override
Expand Down
Expand Up @@ -11,6 +11,7 @@
package org.junit.gen5.console.options;

import java.util.List;
import java.util.Optional;

public interface CommandLineOptions {

Expand All @@ -24,7 +25,7 @@ public interface CommandLineOptions {

boolean isHideDetails();

String getClassnameFilter();
Optional<String> getClassnameFilter();

List<String> getTagsFilter();

Expand Down

0 comments on commit fc76673

Please sign in to comment.