Skip to content

Commit

Permalink
136: PitUtils.splitBasedOnComma
Browse files Browse the repository at this point in the history
Task-Url: #136
  • Loading branch information
LorenzoBettini committed Aug 28, 2022
1 parent 39393d8 commit 0eb1a80
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand All @@ -46,6 +44,7 @@
import org.pitest.pitclipse.runner.PitOptions;
import org.pitest.pitclipse.runner.PitOptions.PitOptionsBuilder;
import org.pitest.pitclipse.runner.config.PitConfiguration;
import org.pitest.pitclipse.runner.util.PitUtils;

public class LaunchConfigurationWrapper {

Expand Down Expand Up @@ -214,7 +213,7 @@ private List<String> getExcludedMethods() throws CoreException {
} else {
excludedMethods = pitConfiguration.getExcludedMethods();
}
return splitBasedOnComma(excludedMethods);
return PitUtils.splitBasedOnComma(excludedMethods);
}

private List<String> getAvoidCallsTo() throws CoreException {
Expand All @@ -224,7 +223,7 @@ private List<String> getAvoidCallsTo() throws CoreException {
} else {
avoidCallsTo = pitConfiguration.getAvoidCallsTo();
}
return splitBasedOnComma(avoidCallsTo);
return PitUtils.splitBasedOnComma(avoidCallsTo);
}

private List<String> getExcludedClasses() throws CoreException {
Expand All @@ -234,14 +233,7 @@ private List<String> getExcludedClasses() throws CoreException {
} else {
excludedClasses = pitConfiguration.getExcludedClasses();
}
return splitBasedOnComma(excludedClasses);
}

private List<String> splitBasedOnComma(String elements) {
return Arrays.stream(elements.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
return PitUtils.splitBasedOnComma(excludedClasses);
}

private boolean isIncrementalAnalysis() throws CoreException {
Expand All @@ -268,7 +260,7 @@ private List<String> getClassesFromProject() throws CoreException {
private List<String> getTargetClasses() throws CoreException {
final String targetClasses = launchConfig.getAttribute(ATTR_TARGET_CLASSES, "");
return targetClasses.equals("") ? null
: new ArrayList<>(splitBasedOnComma(targetClasses));
: new ArrayList<>(PitUtils.splitBasedOnComma(targetClasses));
}

public IResource[] getMappedResources() throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright 2021 Lorenzo Bettini and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package org.pitest.pitclipse.runner.util;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author Lorenzo Bettini
*
*/
public class PitUtils {

private PitUtils() {
// only static methods
}

public static List<String> splitBasedOnComma(String elements) {
return Arrays.stream(elements.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
}
}

0 comments on commit 0eb1a80

Please sign in to comment.