this function is very convenient when writting DataProvider methodstags/5.3-RC1
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.server.computation.measure; | |||
import com.google.common.base.Function; | |||
import com.google.common.base.Predicate; | |||
import com.google.common.collect.ImmutableList; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
@@ -27,12 +26,12 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.List; | |||
import javax.annotation.Nonnull; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.server.computation.measure.Measure.ValueType; | |||
import org.sonar.server.util.WrapInSingleElementArray; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -91,18 +90,18 @@ public class MeasureTest { | |||
@DataProvider | |||
public static Object[][] all() { | |||
return from(MEASURES).transform(WrapInArray.INSTANCE).toArray(Measure[].class); | |||
return from(MEASURES).transform(WrapInSingleElementArray.INSTANCE).toArray(Object[].class); | |||
} | |||
private static Measure[][] getMeasuresExcept(final ValueType valueType) { | |||
private static Object[][] getMeasuresExcept(final ValueType valueType) { | |||
return from(MEASURES) | |||
.filter(new Predicate<Measure>() { | |||
@Override | |||
public boolean apply(@Nonnull Measure input) { | |||
return input.getValueType() != valueType; | |||
} | |||
}).transform(WrapInArray.INSTANCE) | |||
.toArray(Measure[].class); | |||
}).transform(WrapInSingleElementArray.INSTANCE) | |||
.toArray(Object[].class); | |||
} | |||
@Test | |||
@@ -364,13 +363,4 @@ public class MeasureTest { | |||
newMeasureBuilder().create(Double.NaN, "some data"); | |||
} | |||
private enum WrapInArray implements Function<Measure, Measure[]> { | |||
INSTANCE; | |||
@Nullable | |||
@Override | |||
public Measure[] apply(@Nonnull Measure input) { | |||
return new Measure[] {input}; | |||
} | |||
} | |||
} |
@@ -20,20 +20,17 @@ | |||
package org.sonar.server.computation.step; | |||
import com.google.common.base.Function; | |||
import com.google.common.base.Predicate; | |||
import com.google.common.collect.FluentIterable; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.mockito.ArgumentCaptor; | |||
import org.mockito.Mockito; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.server.computation.dbcleaner.ProjectCleaner; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.purge.IdUuidPair; | |||
import org.sonar.server.computation.batch.TreeRootHolderRule; | |||
@@ -42,7 +39,9 @@ import org.sonar.server.computation.component.MutableDbIdsRepositoryRule; | |||
import org.sonar.server.computation.component.ReportComponent; | |||
import org.sonar.server.computation.component.SettingsRepository; | |||
import org.sonar.server.computation.component.ViewsComponent; | |||
import org.sonar.server.computation.dbcleaner.ProjectCleaner; | |||
import org.sonar.server.db.DbClient; | |||
import org.sonar.server.util.WrapInSingleElementArray; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -143,17 +142,13 @@ public class PurgeDatastoresStepTest extends BaseStepTest { | |||
private static Object[][] dataproviderFromComponentTypeValues(Predicate<Component.Type> predicate) { | |||
return FluentIterable.from(asList(Component.Type.values())) | |||
.filter(predicate) | |||
.transform(new Function<Object, Object[]>() { | |||
@Nullable | |||
@Override | |||
public Object[] apply(Object input) { | |||
return new Object[]{input}; | |||
} | |||
}).toArray(Object[].class); | |||
.transform(WrapInSingleElementArray.INSTANCE) | |||
.toArray(Object[].class); | |||
} | |||
@Override | |||
protected ComputationStep step() { | |||
return underTest; | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.util; | |||
import com.google.common.base.Function; | |||
import javax.annotation.Nonnull; | |||
public enum WrapInSingleElementArray implements Function<Object, Object[]> { | |||
INSTANCE; | |||
@Override | |||
@Nonnull | |||
public Object[] apply(Object input) { | |||
return new Object[]{input}; | |||
} | |||
} |