@@ -50,7 +50,7 @@ public class ChecksSensor implements Sensor { | |||
@Override | |||
public void execute(SensorContext context) { | |||
Checks<Check> checks = checkFactory.create(XooRulesDefinition.XOO_REPOSITORY); | |||
checks.addAnnotatedChecks((Object[]) Check.ALL); | |||
checks.addAnnotatedChecks(Check.ALL); | |||
FilePredicates p = context.fileSystem().predicates(); | |||
for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) { | |||
for (Check check : checks.all()) { |
@@ -21,11 +21,11 @@ package org.sonar.xoo.rule; | |||
import com.google.common.collect.HashBasedTable; | |||
import com.google.common.collect.Lists; | |||
import com.google.common.collect.Maps; | |||
import com.google.common.collect.Table; | |||
import java.io.IOException; | |||
import java.nio.file.Files; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.regex.Matcher; | |||
@@ -70,10 +70,10 @@ public class MultilineIssuesSensor implements Sensor { | |||
} | |||
private static void createIssues(InputFile file, SensorContext context) { | |||
Map<Integer, TextPointer> startIssuesPositions = Maps.newHashMap(); | |||
Map<Integer, TextPointer> endIssuesPositions = Maps.newHashMap(); | |||
Map<Integer, Table<Integer, Integer, TextPointer>> startFlowsPositions = Maps.newHashMap(); | |||
Map<Integer, Table<Integer, Integer, TextPointer>> endFlowsPositions = Maps.newHashMap(); | |||
Map<Integer, TextPointer> startIssuesPositions = new HashMap<>(); | |||
Map<Integer, TextPointer> endIssuesPositions = new HashMap<>(); | |||
Map<Integer, Table<Integer, Integer, TextPointer>> startFlowsPositions = new HashMap<>(); | |||
Map<Integer, Table<Integer, Integer, TextPointer>> endFlowsPositions = new HashMap<>(); | |||
parseIssues(file, context, startIssuesPositions, endIssuesPositions); | |||
parseFlows(file, startFlowsPositions, endFlowsPositions); |
@@ -42,7 +42,6 @@ public class AnalysisErrorSensorTest { | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
private AnalysisErrorSensor sensor; | |||
private SensorContextTester context; | |||
@Before | |||
public void setUp() { | |||
@@ -74,7 +73,7 @@ public class AnalysisErrorSensorTest { | |||
.setModuleBaseDir(baseDir) | |||
.setLines(4) | |||
.build(); | |||
context = SensorContextTester.create(baseDir); | |||
SensorContextTester context = SensorContextTester.create(baseDir); | |||
context.fileSystem().add(inputFile); | |||
sensor.execute(context); |
@@ -142,7 +142,7 @@ public class GitHubSettings { | |||
.category(CATEGORY) | |||
.subCategory(SUBCATEGORY) | |||
.type(STRING) | |||
.defaultValue(valueOf("https://api.github.com/")) | |||
.defaultValue("https://api.github.com/") | |||
.index(7) | |||
.build(), | |||
PropertyDefinition.builder(WEB_URL) | |||
@@ -152,7 +152,7 @@ public class GitHubSettings { | |||
.category(CATEGORY) | |||
.subCategory(SUBCATEGORY) | |||
.type(STRING) | |||
.defaultValue(valueOf("https://github.com/")) | |||
.defaultValue("https://github.com/") | |||
.index(8) | |||
.build(), | |||
PropertyDefinition.builder(ORGANIZATIONS) |
@@ -32,7 +32,7 @@ public class Krb5LoginConfiguration extends Configuration { | |||
static { | |||
String loginModule = "com.sun.security.auth.module.Krb5LoginModule"; | |||
AppConfigurationEntry.LoginModuleControlFlag flag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; | |||
CONFIG_LIST[0] = new AppConfigurationEntry(loginModule, flag, new HashMap<String, Object>()); | |||
CONFIG_LIST[0] = new AppConfigurationEntry(loginModule, flag, new HashMap<>()); | |||
} | |||
/** |
@@ -73,7 +73,7 @@ public class LdapAutodiscoveryTest { | |||
Attribute attribute = mock(Attribute.class); | |||
NamingEnumeration namingEnumeration = mock(NamingEnumeration.class); | |||
when(context.getAttributes(Mockito.anyString(), Mockito.<String[]>anyObject())).thenReturn(attributes); | |||
when(context.getAttributes(Mockito.anyString(), Mockito.anyObject())).thenReturn(attributes); | |||
when(attributes.get(Mockito.eq("srv"))).thenReturn(attribute); | |||
when(attribute.getAll()).thenReturn(namingEnumeration); | |||
when(namingEnumeration.hasMore()).thenReturn(true, true, true, true, true, false); |
@@ -44,7 +44,7 @@ public class LdapGroupsProviderTest { | |||
public static LdapServer infosupportServer = new LdapServer(USERS_INFOSUPPORT_COM_LDIF, "infosupport.com", "dc=infosupport,dc=com"); | |||
@Test | |||
public void defaults() throws Exception { | |||
public void defaults() { | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, null); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); |
@@ -62,7 +62,7 @@ public class LdapSettingsManagerTest { | |||
} | |||
@Test | |||
public void testContextFactoriesWithSingleLdap() throws Exception { | |||
public void testContextFactoriesWithSingleLdap() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateSingleLdapSettingsWithUserAndGroupMapping(), new LdapAutodiscovery()); | |||
assertThat(settingsManager.getContextFactories().size()).isEqualTo(1); | |||
@@ -71,11 +71,9 @@ public class LdapSettingsManagerTest { | |||
/** | |||
* Test there are 2 @link{org.sonar.plugins.ldap.LdapContextFactory}s found. | |||
* | |||
* @throws Exception | |||
* This is not expected. | |||
*/ | |||
@Test | |||
public void testContextFactoriesWithMultipleLdap() throws Exception { | |||
public void testContextFactoriesWithMultipleLdap() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateMultipleLdapSettingsWithUserAndGroupMapping(), new LdapAutodiscovery()); | |||
assertThat(settingsManager.getContextFactories().size()).isEqualTo(2); | |||
@@ -84,7 +82,7 @@ public class LdapSettingsManagerTest { | |||
} | |||
@Test | |||
public void testAutodiscover() throws Exception { | |||
public void testAutodiscover() { | |||
LdapAutodiscovery ldapAutodiscovery = mock(LdapAutodiscovery.class); | |||
LdapSrvRecord ldap1 = new LdapSrvRecord("ldap://localhost:189", 1, 1); | |||
LdapSrvRecord ldap2 = new LdapSrvRecord("ldap://localhost:1899", 1, 1); | |||
@@ -95,9 +93,9 @@ public class LdapSettingsManagerTest { | |||
} | |||
@Test | |||
public void testAutodiscoverFailed() throws Exception { | |||
public void testAutodiscoverFailed() { | |||
LdapAutodiscovery ldapAutodiscovery = mock(LdapAutodiscovery.class); | |||
when(ldapAutodiscovery.getLdapServers("example.org")).thenReturn(Collections.<LdapSrvRecord>emptyList()); | |||
when(ldapAutodiscovery.getLdapServers("example.org")).thenReturn(Collections.emptyList()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateAutodiscoverSettings(), ldapAutodiscovery); | |||
@@ -110,11 +108,9 @@ public class LdapSettingsManagerTest { | |||
/** | |||
* Test there are 2 @link{org.sonar.plugins.ldap.LdapUserMapping}s found. | |||
* | |||
* @throws Exception | |||
* This is not expected. | |||
*/ | |||
@Test | |||
public void testUserMappings() throws Exception { | |||
public void testUserMappings() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateMultipleLdapSettingsWithUserAndGroupMapping(), new LdapAutodiscovery()); | |||
assertThat(settingsManager.getUserMappings().size()).isEqualTo(2); | |||
@@ -125,11 +121,9 @@ public class LdapSettingsManagerTest { | |||
/** | |||
* Test there are 2 @link{org.sonar.plugins.ldap.LdapGroupMapping}s found. | |||
* | |||
* @throws Exception | |||
* This is not expected. | |||
*/ | |||
@Test | |||
public void testGroupMappings() throws Exception { | |||
public void testGroupMappings() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateMultipleLdapSettingsWithUserAndGroupMapping(), new LdapAutodiscovery()); | |||
assertThat(settingsManager.getGroupMappings().size()).isEqualTo(2); | |||
@@ -140,10 +134,9 @@ public class LdapSettingsManagerTest { | |||
/** | |||
* Test what happens when no configuration is set. | |||
* Normally there will be a contextFactory, but the autodiscovery doesn't work for the test server. | |||
* @throws Exception | |||
*/ | |||
@Test | |||
public void testEmptySettings() throws Exception { | |||
public void testEmptySettings() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
new MapSettings(), new LdapAutodiscovery()); | |||
@@ -43,7 +43,7 @@ public class LdapUsersProviderTest { | |||
public static LdapServer infosupportServer = new LdapServer(USERS_INFOSUPPORT_COM_LDIF, "infosupport.com", "dc=infosupport,dc=com"); | |||
@Test | |||
public void test() throws Exception { | |||
public void test() { | |||
Settings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, infosupportServer); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapUsersProvider usersProvider = new LdapUsersProvider(settingsManager.getContextFactories(), settingsManager.getUserMappings()); |
@@ -54,8 +54,7 @@ public class CloseIssuesOnRemovedComponentsVisitor extends TypeAwareVisitorAdapt | |||
} | |||
private void closeIssuesForDeletedComponentUuids(Set<String> deletedComponentUuids) { | |||
DiskCache<DefaultIssue>.DiskAppender cacheAppender = issueCache.newAppender(); | |||
try { | |||
try (DiskCache<DefaultIssue>.DiskAppender cacheAppender = issueCache.newAppender()) { | |||
for (String deletedComponentUuid : deletedComponentUuids) { | |||
List<DefaultIssue> issues = issuesLoader.loadOpenIssues(deletedComponentUuid); | |||
for (DefaultIssue issue : issues) { | |||
@@ -66,8 +65,6 @@ public class CloseIssuesOnRemovedComponentsVisitor extends TypeAwareVisitorAdapt | |||
cacheAppender.append(issue); | |||
} | |||
} | |||
} finally { | |||
cacheAppender.close(); | |||
} | |||
} | |||
} |
@@ -196,7 +196,7 @@ public class ComponentIssuesLoader { | |||
i.addComment(c.toComment()); | |||
break; | |||
default: | |||
throw new IllegalStateException("Unknow change type: " + c.getChangeType()); | |||
throw new IllegalStateException("Unknown change type: " + c.getChangeType()); | |||
} | |||
} | |||
@@ -200,7 +200,7 @@ public class IssueCounter extends IssueVisitor { | |||
if (!periodHolder.hasPeriod() && !analysisMetadataHolder.isPullRequest()) { | |||
return; | |||
} | |||
double unresolvedVariations = (double) currentCounters.counterForPeriod().unresolved; | |||
double unresolvedVariations = currentCounters.counterForPeriod().unresolved; | |||
measureRepository.add(component, metricRepository.getByKey(NEW_VIOLATIONS_KEY), Measure.newMeasureBuilder() | |||
.setVariation(unresolvedVariations) | |||
.createNoValue()); | |||
@@ -211,7 +211,7 @@ public class IssueCounter extends IssueVisitor { | |||
Multiset<String> bag = currentCounters.counterForPeriod().severityBag; | |||
Metric metric = metricRepository.getByKey(metricKey); | |||
measureRepository.add(component, metric, Measure.newMeasureBuilder() | |||
.setVariation((double) bag.count(severity)) | |||
.setVariation(bag.count(severity)) | |||
.createNoValue()); | |||
} | |||
@@ -223,7 +223,7 @@ public class IssueCounter extends IssueVisitor { | |||
Multiset<RuleType> bag = currentCounters.counterForPeriod().typeBag; | |||
Metric metric = metricRepository.getByKey(metricKey); | |||
measureRepository.add(component, metric, Measure.newMeasureBuilder() | |||
.setVariation((double) bag.count(type)) | |||
.setVariation(bag.count(type)) | |||
.createNoValue()); | |||
} | |||
} |
@@ -31,7 +31,6 @@ import org.sonar.core.issue.DefaultIssueComment; | |||
import org.sonar.core.issue.FieldDiffs; | |||
import org.sonar.core.issue.IssueChangeContext; | |||
import org.sonar.core.util.Uuids; | |||
import org.sonar.db.component.KeyType; | |||
import org.sonar.server.issue.IssueFieldsSetter; | |||
import org.sonar.server.issue.workflow.IssueWorkflow; | |||
@@ -77,7 +77,7 @@ public class LiveMeasureDtoToMeasure { | |||
} | |||
return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto) | |||
.create(value.doubleValue(), org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE, data)); | |||
.create(value, org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE, data)); | |||
} | |||
private static Optional<Measure> toBooleanMeasure(LiveMeasureDto measureDto, @Nullable Double value, @Nullable String data) { |
@@ -458,7 +458,7 @@ public interface Measure { | |||
} | |||
public Measure create(int value, @Nullable String data) { | |||
return createInternal(ValueType.INT, (double) value, data); | |||
return createInternal(ValueType.INT, value, data); | |||
} | |||
public Measure create(int value) { |
@@ -77,7 +77,7 @@ public class MeasureDtoToMeasure { | |||
} | |||
return of(setCommonProperties(Measure.newMeasureBuilder(), measureDto) | |||
.create(value.doubleValue(), org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE, data)); | |||
.create(value, org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE, data)); | |||
} | |||
private static Optional<Measure> toBooleanMeasure(MeasureDto measureDto, @Nullable Double value, String data) { |
@@ -48,13 +48,10 @@ public class MetricRepositoryImpl implements MetricRepository, Startable { | |||
@Override | |||
public void start() { | |||
DbSession dbSession = dbClient.openSession(false); | |||
try { | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
List<MetricDto> metricList = dbClient.metricDao().selectEnabled(dbSession); | |||
this.metricsByKey = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToKey.INSTANCE); | |||
this.metricsById = from(metricList).transform(MetricDtoToMetric.INSTANCE).uniqueIndex(MetricToId.INSTANCE); | |||
} finally { | |||
dbSession.close(); | |||
} | |||
} | |||
@@ -27,6 +27,7 @@ import org.sonar.api.notifications.Notification; | |||
import org.sonar.server.issue.notification.EmailMessage; | |||
import org.sonar.server.issue.notification.EmailTemplate; | |||
import static java.nio.charset.StandardCharsets.UTF_8; | |||
import static org.sonar.api.utils.DateUtils.formatDateTime; | |||
public class ReportAnalysisFailureNotificationEmailTemplate implements EmailTemplate { | |||
@@ -94,7 +95,7 @@ public class ReportAnalysisFailureNotificationEmailTemplate implements EmailTemp | |||
private static String encode(String toEncode) { | |||
try { | |||
return URLEncoder.encode(toEncode, "UTF-8"); | |||
return URLEncoder.encode(toEncode, UTF_8.name()); | |||
} catch (UnsupportedEncodingException e) { | |||
throw new IllegalStateException("Encoding not supported", e); | |||
} |
@@ -109,7 +109,7 @@ public class PostProjectAnalysisTasksExecutorTest { | |||
new PostProjectAnalysisTask[] {postProjectAnalysisTask}); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
qualityGateHolder.setQualityGate(new QualityGate(QUALITY_GATE_ID, QUALITY_GATE_NAME, of(CONDITION_1, CONDITION_2))); | |||
qualityGateStatusHolder.setStatus(QualityGateStatus.OK, ImmutableMap.of( | |||
CONDITION_1, ConditionStatus.create(ConditionStatus.EvaluationStatus.OK, "value"), |
@@ -20,13 +20,13 @@ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import com.google.common.base.Function; | |||
import com.google.common.base.Predicate; | |||
import com.google.common.collect.ImmutableSet; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Arrays; | |||
import java.util.Set; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
@@ -43,18 +43,8 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
@RunWith(DataProviderRunner.class) | |||
public class CrawlerDepthLimitTest { | |||
private static final Set<Type> REPORT_TYPES = from(asList(Type.values())).filter(new Predicate<Type>() { | |||
@Override | |||
public boolean apply(Type input) { | |||
return input.isReportType(); | |||
} | |||
}).toSet(); | |||
private static final Set<Type> VIEWS_TYPES = from(asList(Type.values())).filter(new Predicate<Type>() { | |||
@Override | |||
public boolean apply(Type input) { | |||
return input.isViewsType(); | |||
} | |||
}).toSet(); | |||
private static final Set<Type> REPORT_TYPES = Arrays.stream(Type.values()).filter(Type::isReportType).collect(Collectors.toSet()); | |||
private static final Set<Type> VIEWS_TYPES = Arrays.stream(Type.values()).filter(Type::isViewsType).collect(Collectors.toSet()); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@@ -258,7 +248,7 @@ public class CrawlerDepthLimitTest { | |||
for (Type type : types) { | |||
assertThat(depthLimit.isHigherThan(type)).as("isHigherThan(%s)", type).isTrue(); | |||
} | |||
for (Type reportType : from(REPORT_TYPES).filter(not(in(Arrays.asList(types))))) { | |||
for (Type reportType : from(REPORT_TYPES).filter(not(in(asList(types))))) { | |||
assertThat(depthLimit.isHigherThan(reportType)).as("isHigherThan(%s)", reportType).isFalse(); | |||
} | |||
} | |||
@@ -267,7 +257,7 @@ public class CrawlerDepthLimitTest { | |||
for (Type type : types) { | |||
assertThat(depthLimit.isHigherThan(type)).as("isHigherThan(%s)", type).isTrue(); | |||
} | |||
for (Type reportType : from(VIEWS_TYPES).filter(not(in(Arrays.asList(types))))) { | |||
for (Type reportType : from(VIEWS_TYPES).filter(not(in(asList(types))))) { | |||
assertThat(depthLimit.isHigherThan(reportType)).as("isHigherThan(%s)", reportType).isFalse(); | |||
} | |||
} | |||
@@ -276,7 +266,7 @@ public class CrawlerDepthLimitTest { | |||
for (Type type : types) { | |||
assertThat(depthLimit.isDeeperThan(type)).as("isDeeperThan(%s)", type).isTrue(); | |||
} | |||
for (Type reportType : from(REPORT_TYPES).filter(not(in(Arrays.asList(types))))) { | |||
for (Type reportType : from(REPORT_TYPES).filter(not(in(asList(types))))) { | |||
assertThat(depthLimit.isDeeperThan(reportType)).as("isDeeperThan(%s)", reportType).isFalse(); | |||
} | |||
} | |||
@@ -285,7 +275,7 @@ public class CrawlerDepthLimitTest { | |||
for (Type type : types) { | |||
assertThat(depthLimit.isDeeperThan(type)).as("isDeeperThan(%s)", type).isTrue(); | |||
} | |||
for (Type reportType : from(VIEWS_TYPES).filter(not(in(Arrays.asList(types))))) { | |||
for (Type reportType : from(VIEWS_TYPES).filter(not(in(asList(types))))) { | |||
assertThat(depthLimit.isDeeperThan(reportType)).as("isDeeperThan(%s)", reportType).isFalse(); | |||
} | |||
} |
@@ -64,7 +64,7 @@ public class ScoreMatrixDumperImplTest { | |||
} | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
FileUtils.listFiles(tempDir.toFile(), new AbstractFileFilter() { | |||
@Override | |||
public boolean accept(File file) { | |||
@@ -119,7 +119,7 @@ public class ScoreMatrixDumperImplTest { | |||
}; | |||
} | |||
private static Collection<File> listDumpFilesForTaskUuid(String taskUuid) throws IOException { | |||
private static Collection<File> listDumpFilesForTaskUuid(String taskUuid) { | |||
return FileUtils.listFiles(tempDir.toFile(), new AbstractFileFilter() { | |||
@Override | |||
public boolean accept(File file) { |
@@ -57,10 +57,10 @@ public class AverageFormulaExecutionTest { | |||
@Rule | |||
public PeriodHolderRule periodsHolder = new PeriodHolderRule(); | |||
FormulaExecutorComponentVisitor underTest; | |||
private FormulaExecutorComponentVisitor underTest; | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
underTest = FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository) | |||
.buildFor(Lists.newArrayList( | |||
AverageFormula.Builder.newBuilder() |
@@ -315,7 +315,7 @@ public class ReportFormulaExecutorComponentVisitorTest { | |||
} | |||
} | |||
private class FakeCounter implements Counter<FakeCounter> { | |||
private static class FakeCounter implements Counter<FakeCounter> { | |||
private int value = 0; | |||
@Override | |||
@@ -364,7 +364,7 @@ public class ReportFormulaExecutorComponentVisitorTest { | |||
} | |||
} | |||
private class FakeVariationCounter implements Counter<FakeVariationCounter> { | |||
private static class FakeVariationCounter implements Counter<FakeVariationCounter> { | |||
private final IntValue values = new IntValue(); | |||
@Override |
@@ -53,7 +53,7 @@ public class SumFormulaExecutionTest { | |||
FormulaExecutorComponentVisitor underTest; | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
underTest = FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository) | |||
.buildFor(Lists.newArrayList(createIntSumFormula(LINES_KEY))); | |||
} |
@@ -152,7 +152,6 @@ public class IntegrateIssuesVisitorTest { | |||
tracker = new TrackerExecution(baseInputFactory, rawInputFactory, closedIssuesInputFactory, new Tracker<>(), issuesLoader, analysisMetadataHolder); | |||
prBranchTracker = new PullRequestTrackerExecution(baseInputFactory, rawInputFactory, new Tracker<>(), newLinesRepository); | |||
mergeBranchTracker = new ReferenceBranchTrackerExecution(rawInputFactory, mergeInputFactory, new Tracker<>()); | |||
trackingDelegator = new IssueTrackingDelegator(prBranchTracker, mergeBranchTracker, tracker, analysisMetadataHolder); | |||
treeRootHolder.setRoot(PROJECT); | |||
issueCache = new IssueCache(temp.newFile(), System2.INSTANCE); |
@@ -57,7 +57,7 @@ public class IssuesRepositoryVisitorTest { | |||
IssuesRepositoryVisitor underTest = new IssuesRepositoryVisitor(componentIssuesRepository); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
treeRootHolder.setRoot(PROJECT); | |||
} | |||
@@ -60,7 +60,7 @@ public class MovedIssueVisitorTest { | |||
private MovedIssueVisitor underTest = new MovedIssueVisitor(analysisMetadataHolder, movedFilesRepository, new IssueFieldsSetter()); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
analysisMetadataHolder.setAnalysisDate(ANALYSIS_DATE); | |||
when(movedFilesRepository.getOriginalFile(any(Component.class))) | |||
.thenReturn(Optional.absent()); |
@@ -66,7 +66,7 @@ public class PullRequestTrackerExecutionTest { | |||
private List<DefaultIssue> baseIssues = new ArrayList<>(); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
when(rawFactory.create(FILE)).thenReturn(createInput(rawIssues)); | |||
when(baseFactory.create(FILE)).thenReturn(createInput(baseIssues)); | |||
@@ -81,7 +81,7 @@ public class RuleRepositoryImplTest { | |||
private RuleRepositoryImpl underTest = new RuleRepositoryImpl(adHocRuleCreator, dbClient, analysisMetadataHolder); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
when(dbClient.openSession(anyBoolean())).thenReturn(dbSession); | |||
when(dbClient.ruleDao()).thenReturn(ruleDao); | |||
when(ruleDao.selectAll(any(DbSession.class), eq(ORGANIZATION_UUID))).thenReturn(ImmutableList.of(AB_RULE)); |
@@ -81,7 +81,7 @@ public class RuleRepositoryRule extends ExternalResource implements RuleReposito | |||
public RuleRepositoryRule add(DumbRule rule) { | |||
rulesByKey.put(requireNonNull(rule.getKey()), rule); | |||
rulesById.put(requireNonNull(rule.getId()), rule); | |||
rulesById.put(rule.getId(), rule); | |||
return this; | |||
} | |||
@@ -61,7 +61,7 @@ public class TrackerBaseInputFactoryTest { | |||
new IssueFieldsSetter(), mock(ComponentsWithUnprocessedIssues.class)); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
when(dbClient.openSession(false)).thenReturn(dbSession); | |||
when(dbClient.fileSourceDao()).thenReturn(fileSourceDao); | |||
when(movedFilesRepository.getOriginalFile(any(Component.class))) |
@@ -146,9 +146,9 @@ public class BestValueOptimizationTest { | |||
Predicate<Measure> underTest = BestValueOptimization.from(createMetric(Metric.MetricType.RATING, A.getIndex()), FILE_COMPONENT); | |||
assertThat(underTest.test(newMeasureBuilder().create(A.getIndex()))).isTrue(); | |||
assertThat(underTest.test(newMeasureBuilder().setVariation((double) A.getIndex()).createNoValue())).isTrue(); | |||
assertThat(underTest.test(newMeasureBuilder().setVariation(A.getIndex()).createNoValue())).isTrue(); | |||
assertThat(underTest.test(newMeasureBuilder().create(B.getIndex()))).isFalse(); | |||
assertThat(underTest.test(newMeasureBuilder().setVariation((double) B.getIndex()).createNoValue())).isFalse(); | |||
assertThat(underTest.test(newMeasureBuilder().setVariation(B.getIndex()).createNoValue())).isFalse(); | |||
} | |||
@Test |
@@ -20,7 +20,6 @@ | |||
package org.sonar.ce.task.projectanalysis.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; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
@@ -277,12 +276,7 @@ public class MeasureRepositoryImplTest { | |||
} | |||
private Measure getSomeMeasureByValueType(final Metric.MetricType metricType) { | |||
return from(MEASURES).filter(new Predicate<Measure>() { | |||
@Override | |||
public boolean apply(@Nullable Measure input) { | |||
return input.getValueType() == metricType.getValueType(); | |||
} | |||
}).first().get(); | |||
return from(MEASURES).filter(input -> input.getValueType() == metricType.getValueType()).first().get(); | |||
} | |||
@Test |
@@ -218,7 +218,7 @@ public class MeasureTest { | |||
assertThat(newMeasureBuilder().setQualityGateStatus(someStatus).create(false, null).getQualityGateStatus()).isEqualTo(someStatus); | |||
assertThat(newMeasureBuilder().setQualityGateStatus(someStatus).create(1, null).getQualityGateStatus()).isEqualTo(someStatus); | |||
assertThat(newMeasureBuilder().setQualityGateStatus(someStatus).create((long) 1, null).getQualityGateStatus()).isEqualTo(someStatus); | |||
assertThat(newMeasureBuilder().setQualityGateStatus(someStatus).create((double) 1, 1, null).getQualityGateStatus()).isEqualTo(someStatus); | |||
assertThat(newMeasureBuilder().setQualityGateStatus(someStatus).create(1, 1, null).getQualityGateStatus()).isEqualTo(someStatus); | |||
assertThat(newMeasureBuilder().setQualityGateStatus(someStatus).create("str").getQualityGateStatus()).isEqualTo(someStatus); | |||
assertThat(newMeasureBuilder().setQualityGateStatus(someStatus).create(Measure.Level.OK).getQualityGateStatus()).isEqualTo(someStatus); | |||
} | |||
@@ -263,7 +263,7 @@ public class MeasureTest { | |||
assertThat(newMeasureBuilder().create(false, someData).getData()).isEqualTo(someData); | |||
assertThat(newMeasureBuilder().create(1, someData).getData()).isEqualTo(someData); | |||
assertThat(newMeasureBuilder().create((long) 1, someData).getData()).isEqualTo(someData); | |||
assertThat(newMeasureBuilder().create((double) 1, 1, someData).getData()).isEqualTo(someData); | |||
assertThat(newMeasureBuilder().create(1, 1, someData).getData()).isEqualTo(someData); | |||
} | |||
@Test |
@@ -61,7 +61,7 @@ public class MeasureToMeasureDtoTest { | |||
private MeasureToMeasureDto underTest = new MeasureToMeasureDto(analysisMetadataHolder, treeRootHolder); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
analysisMetadataHolder.setUuid(ANALYSIS_UUID); | |||
} | |||
@@ -81,7 +81,7 @@ public class MeasureToMeasureDtoTest { | |||
{Measure.newMeasureBuilder().create(true, SOME_DATA), SOME_BOOLEAN_METRIC}, | |||
{Measure.newMeasureBuilder().create(1, SOME_DATA), SOME_INT_METRIC}, | |||
{Measure.newMeasureBuilder().create((long) 1, SOME_DATA), SOME_LONG_METRIC}, | |||
{Measure.newMeasureBuilder().create((double) 2, 1, SOME_DATA), SOME_DOUBLE_METRIC}, | |||
{Measure.newMeasureBuilder().create(2, 1, SOME_DATA), SOME_DOUBLE_METRIC}, | |||
{Measure.newMeasureBuilder().create(SOME_STRING), SOME_STRING_METRIC}, | |||
{Measure.newMeasureBuilder().create(Measure.Level.OK), SOME_LEVEL_METRIC} | |||
}; | |||
@@ -160,7 +160,7 @@ public class MeasureToMeasureDtoTest { | |||
@Test | |||
public void toMeasureDto_maps_value_and_data_from_data_field_for_DOUBLE_metric() { | |||
MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create((double) 789, 1, SOME_DATA), SOME_DOUBLE_METRIC, SOME_COMPONENT); | |||
MeasureDto trueMeasureDto = underTest.toMeasureDto(Measure.newMeasureBuilder().create(789, 1, SOME_DATA), SOME_DOUBLE_METRIC, SOME_COMPONENT); | |||
assertThat(trueMeasureDto.getValue()).isEqualTo(789); | |||
assertThat(trueMeasureDto.getData()).isEqualTo(SOME_DATA); |
@@ -60,7 +60,7 @@ public class QualityGateServiceImplTest { | |||
private QualityGateServiceImpl underTest = new QualityGateServiceImpl(dbClient, metricRepository); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
when(dbClient.qualityGateDao()).thenReturn(qualityGateDao); | |||
when(dbClient.gateConditionDao()).thenReturn(qualityGateConditionDao); | |||
@@ -92,7 +92,7 @@ public class NewMaintainabilityMeasuresVisitorTest { | |||
private VisitorsCrawler underTest; | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
when(ratingSettings.getDebtRatingGrid()).thenReturn(new DebtRatingGrid(RATING_GRID)); | |||
underTest = new VisitorsCrawler(Arrays.asList(new NewMaintainabilityMeasuresVisitor(metricRepository, measureRepository, newLinesRepository, ratingSettings))); | |||
} |
@@ -43,7 +43,6 @@ import org.sonar.db.source.FileSourceDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.api.utils.log.LoggerLevel.TRACE; | |||
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder; |
@@ -49,7 +49,7 @@ public class ScmInfoRepositoryRule extends ExternalResource implements ScmInfoRe | |||
} | |||
public ScmInfoRepositoryRule setScmInfo(int fileRef, Map<Integer, Changeset> changesets) { | |||
scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changesets.values().stream().toArray(Changeset[]::new))); | |||
scmInfoByFileRef.put(fileRef, new ScmInfoImpl(changesets.values().toArray(new Changeset[0]))); | |||
return this; | |||
} | |||
} |
@@ -62,7 +62,7 @@ public class SourceLinesDiffImplTest { | |||
}; | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
when(dbClient.openSession(false)).thenReturn(dbSession); | |||
when(dbClient.componentDao()).thenReturn(componentDao); | |||
when(dbClient.fileSourceDao()).thenReturn(fileSourceDao); |
@@ -52,7 +52,7 @@ public class DbMigrationsStepTest { | |||
ProjectAnalysisDataChange[] dataChanges = IntStream.range(0, 5 + new Random().nextInt(5)) | |||
.mapToObj(i -> mock(ProjectAnalysisDataChange.class)) | |||
.toArray(ProjectAnalysisDataChange[]::new); | |||
InOrder inOrder = Mockito.inOrder((Object[]) dataChanges); | |||
InOrder inOrder = Mockito.inOrder(dataChanges); | |||
when(projectAnalysisDataChanges.getDataChanges()).thenReturn(Arrays.asList(dataChanges)); | |||
underTest.execute(new TestComputationStepContext()); |
@@ -207,7 +207,7 @@ public class ExecuteVisitorsStepTest { | |||
} | |||
} | |||
public class Counter { | |||
public static class Counter { | |||
private int value = 0; | |||
public void add(int value) { |
@@ -103,7 +103,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { | |||
integrateCrossProjectDuplications, dbClient); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()); | |||
dbClient.componentDao().insert(dbSession, project); | |||
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project); |
@@ -101,7 +101,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
} | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
organization = dbTester.organizations().insert(); | |||
project = dbTester.components().insertMainBranch(organization); | |||
@@ -84,7 +84,7 @@ public class PersistCrossProjectDuplicationIndexStepTest { | |||
private ComputationStep underTest; | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
when(baseAnalysis.getUuid()).thenReturn(BASE_ANALYSIS_UUID); | |||
analysisMetadataHolder.setUuid(ANALYSIS_UUID); | |||
analysisMetadataHolder.setBaseAnalysis(baseAnalysis); |
@@ -79,7 +79,7 @@ public class PersistDuplicationDataStepTest extends BaseStepTest { | |||
public MetricRepositoryRule metricRepository = new MetricRepositoryRule(); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
MetricDto metric = db.measures().insertMetric(m -> m.setKey(DUPLICATIONS_DATA_KEY).setValueType(Metric.ValueType.STRING.name())); | |||
insertComponent(PROJECT_KEY, PROJECT_UUID); | |||
insertComponent(FILE_1_KEY, FILE_1_UUID); |
@@ -72,7 +72,7 @@ public class ReportCommentMeasuresStepTest { | |||
ComputationStep underTest = new CommentMeasuresStep(treeRootHolder, metricRepository, measureRepository); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
treeRootHolder.setRoot( | |||
builder(PROJECT, ROOT_REF) | |||
.addChildren( |
@@ -75,7 +75,7 @@ public class ReportCoverageMeasuresStepTest { | |||
CoverageMeasuresStep underTest = new CoverageMeasuresStep(treeRootHolder, metricRepository, measureRepository, reportReader); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
treeRootHolder.setRoot( | |||
builder(PROJECT, ROOT_REF) | |||
.addChildren( |
@@ -66,7 +66,7 @@ public class ReportLanguageDistributionMeasuresStepTest { | |||
ComputationStep underTest = new LanguageDistributionMeasuresStep(treeRootHolder, metricRepository, measureRepository); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
treeRootHolder.setRoot( | |||
builder(PROJECT, ROOT_REF) | |||
.addChildren( |
@@ -87,7 +87,6 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
private Date now; | |||
private MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS); | |||
private PersistComponentsStep underTest; | |||
private BranchPersister branchPersister; | |||
@Before | |||
public void setup() throws Exception { | |||
@@ -95,7 +94,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
when(system2.now()).thenReturn(now.getTime()); | |||
db.organizations().insertForUuid(ORGANIZATION_UUID); | |||
branchPersister = mock(BranchPersister.class); | |||
BranchPersister branchPersister = mock(BranchPersister.class); | |||
underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister); | |||
} | |||
@@ -74,7 +74,7 @@ public class ViewsCommentMeasuresStepTest { | |||
ComputationStep underTest = new CommentMeasuresStep(treeRootHolder, metricRepository, measureRepository); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
treeRootHolder.setRoot( | |||
builder(VIEW, ROOT_REF) | |||
.addChildren( |
@@ -65,7 +65,7 @@ public class ViewsCoverageMeasuresStepTest { | |||
CoverageMeasuresStep underTest = new CoverageMeasuresStep(treeRootHolder, metricRepository, measureRepository); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
treeRootHolder.setRoot( | |||
builder(VIEW, ROOT_REF) | |||
.addChildren( |
@@ -117,7 +117,6 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta | |||
@Override | |||
public AnalysisMetadataHolderRule setAnalysisDate(long date) { | |||
checkNotNull(date, "Date must not be null"); | |||
this.analysisDate.setProperty(date); | |||
return this; | |||
} |
@@ -73,7 +73,6 @@ public class MetricRepositoryRule extends ExternalResource implements MetricRepo | |||
public MetricRepositoryRule add(Metric metric) { | |||
requireNonNull(metric.getKey(), "key can not be null"); | |||
requireNonNull(metric.getId(), "id can not be null"); | |||
checkState(!metricsByKey.containsKey(metric.getKey()), format("Repository already contains a metric for key %s", metric.getKey())); | |||
checkState(!metricsById.containsKey((long) metric.getId()), format("Repository already contains a metric for id %s", metric.getId())); |
@@ -19,21 +19,18 @@ | |||
*/ | |||
package org.sonar.ce.taskprocessor; | |||
import com.google.common.base.Function; | |||
import com.google.common.base.Joiner; | |||
import com.google.common.collect.ArrayListMultimap; | |||
import com.google.common.collect.ImmutableMap; | |||
import com.google.common.collect.Maps; | |||
import com.google.common.collect.Multimap; | |||
import java.util.Collection; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import java.util.function.Function; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.Nonnull; | |||
import org.sonar.ce.task.CeTask; | |||
import org.sonar.ce.task.taskprocessor.CeTaskProcessor; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static java.lang.String.CASE_INSENSITIVE_ORDER; | |||
import static java.lang.String.format; | |||
@@ -42,8 +39,6 @@ import static java.lang.String.format; | |||
* PicoContainer the current object belongs to. | |||
*/ | |||
public class CeTaskProcessorRepositoryImpl implements CeTaskProcessorRepository { | |||
private static final Joiner COMMA_JOINER = Joiner.on(", "); | |||
private final Map<String, CeTaskProcessor> taskProcessorByCeTaskType; | |||
public CeTaskProcessorRepositoryImpl(CeTaskProcessor[] taskProcessors) { | |||
@@ -58,7 +53,7 @@ public class CeTaskProcessorRepositoryImpl implements CeTaskProcessorRepository | |||
private static Map<String, CeTaskProcessor> indexTaskProcessors(CeTaskProcessor[] taskProcessors) { | |||
Multimap<String, CeTaskProcessor> permissiveIndex = buildPermissiveCeTaskProcessorIndex(taskProcessors); | |||
checkUniqueHandlerPerCeTaskType(permissiveIndex); | |||
return ImmutableMap.copyOf(Maps.transformValues(permissiveIndex.asMap(), CeTaskProcessorCollectionToFirstElement.INSTANCE)); | |||
return permissiveIndex.asMap().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, y -> CeTaskProcessorCollectionToFirstElement.INSTANCE.apply(y.getValue()))); | |||
} | |||
private static Multimap<String, CeTaskProcessor> buildPermissiveCeTaskProcessorIndex(CeTaskProcessor[] taskProcessors) { | |||
@@ -79,7 +74,7 @@ public class CeTaskProcessorRepositoryImpl implements CeTaskProcessorRepository | |||
"There can be only one CeTaskProcessor instance registered as the processor for CeTask type %s. " + | |||
"More than one found. Please fix your configuration: %s", | |||
entry.getKey(), | |||
COMMA_JOINER.join(from(entry.getValue()).transform(ToClassName.INSTANCE).toSortedList(CASE_INSENSITIVE_ORDER)))); | |||
entry.getValue().stream().map(ToClassName.INSTANCE).sorted(CASE_INSENSITIVE_ORDER).collect(Collectors.joining(", ")))); | |||
} | |||
} | |||
@@ -104,8 +104,7 @@ public class CeDistributedInformationImplTest { | |||
connectedClients.add(clientUUID1); | |||
connectedClients.add(clientUUID2); | |||
connectedClients.add(clientUUID3); | |||
Map modifiableWorkerMap = new HashMap(); | |||
modifiableWorkerMap.putAll(workerMap); | |||
Map modifiableWorkerMap = new HashMap(workerMap); | |||
when(hzClientWrapper.getUuid()).thenReturn(clientUUID1); | |||
when(hzClientWrapper.getMemberUuids()).thenReturn(connectedClients); |
@@ -89,7 +89,7 @@ public class CePluginJarExploderTest { | |||
return new File("src/test/plugins/sonar-test2-plugin/target/sonar-test2-plugin-0.1-SNAPSHOT.jar"); | |||
} | |||
private class DumbFileSystem implements ServerFileSystem { | |||
private static class DumbFileSystem implements ServerFileSystem { | |||
private final TemporaryFolder temp; | |||
private File tempDir; | |||
@@ -19,9 +19,9 @@ | |||
*/ | |||
package org.sonar.ce.container; | |||
import com.google.common.collect.Maps; | |||
import java.io.File; | |||
import java.util.Collection; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import org.junit.After; | |||
import org.junit.Rule; | |||
@@ -144,7 +144,7 @@ public class CePluginRepositoryTest { | |||
*/ | |||
@Override | |||
public Map<String, Plugin> load(Map<String, PluginInfo> infoByKeys) { | |||
Map<String, Plugin> result = Maps.newHashMap(); | |||
Map<String, Plugin> result = new HashMap<>(); | |||
for (String pluginKey : infoByKeys.keySet()) { | |||
result.put(pluginKey, mock(Plugin.class)); | |||
} |
@@ -138,7 +138,7 @@ public class ComputeEngineContainerImplTest { | |||
.map(ComponentAdapter::getComponentImplementation) | |||
.collect(Collectors.toList())).doesNotContain( | |||
(Class) CeDistributedInformationImpl.class).contains( | |||
(Class) StandaloneCeDistributedInformation.class); | |||
StandaloneCeDistributedInformation.class); | |||
assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull(); | |||
} finally { | |||
underTest.stop(); |
@@ -281,7 +281,7 @@ public class CeProcessingSchedulerImplTest { | |||
processingExecutorService.runFutures(); | |||
} | |||
private class TestCeWorkerFactory implements CeWorkerFactory { | |||
private static class TestCeWorkerFactory implements CeWorkerFactory { | |||
private final Iterator<CeWorker> ceWorkers; | |||
private TestCeWorkerFactory(CeWorker... ceWorkers) { |
@@ -40,7 +40,7 @@ class ProfilingPreparedStatementHandler implements InvocationHandler { | |||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | |||
if (method.getName().startsWith("execute")) { | |||
Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start(); | |||
Object result = null; | |||
Object result; | |||
try { | |||
result = InvocationUtils.invokeQuietly(statement, method, args); | |||
} finally { |
@@ -36,7 +36,7 @@ class ProfilingStatementHandler implements InvocationHandler { | |||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | |||
if (method.getName().startsWith("execute")) { | |||
Profiler profiler = Profiler.create(ProfiledDataSource.SQL_LOGGER).start(); | |||
Object result = null; | |||
Object result; | |||
try { | |||
result = InvocationUtils.invokeQuietly(statement, method, args); | |||
} finally { |
@@ -146,7 +146,7 @@ public class DatabaseUtilsTest { | |||
public void toUniqueAndSortedList_throws_NPE_if_arg_is_a_set_containing_a_null() { | |||
expectedException.expect(NullPointerException.class); | |||
toUniqueAndSortedList(new HashSet<>(asList("A", (String) null, "C"))); | |||
toUniqueAndSortedList(new HashSet<>(asList("A", null, "C"))); | |||
} | |||
@Test |
@@ -37,6 +37,7 @@ import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.Date; | |||
import java.util.HashMap; | |||
import java.util.HashSet; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
@@ -54,8 +55,6 @@ import org.sonar.core.util.stream.MoreCollectors; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static com.google.common.collect.Lists.asList; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
import static com.google.common.collect.Maps.newHashMap; | |||
import static java.sql.ResultSetMetaData.columnNoNulls; | |||
import static java.sql.ResultSetMetaData.columnNullable; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -209,9 +208,9 @@ public class AbstractDbTester<T extends TestDb> extends ExternalResource { | |||
private static List<Map<String, Object>> getHashMap(ResultSet resultSet) throws Exception { | |||
ResultSetMetaData metaData = resultSet.getMetaData(); | |||
int colCount = metaData.getColumnCount(); | |||
List<Map<String, Object>> rows = newArrayList(); | |||
List<Map<String, Object>> rows = new ArrayList<>(); | |||
while (resultSet.next()) { | |||
Map<String, Object> columns = newHashMap(); | |||
Map<String, Object> columns = new HashMap<>(); | |||
for (int i = 1; i <= colCount; i++) { | |||
Object value = resultSet.getObject(i); | |||
if (value instanceof Clob) { |
@@ -22,7 +22,6 @@ package org.sonar.db.component; | |||
import com.google.common.annotations.VisibleForTesting; | |||
import com.google.common.collect.ImmutableSet; | |||
import com.google.common.collect.Lists; | |||
import com.google.common.collect.Maps; | |||
import java.util.Collection; | |||
import java.util.HashMap; | |||
import java.util.HashSet; | |||
@@ -128,7 +127,7 @@ public class ComponentKeyUpdaterDao implements Dao { | |||
branchModules.forEach(module -> branchBaseKeys.put(module.getKey(), branchBaseKey(module.getKey()))); | |||
}); | |||
Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = Maps.newHashMap(); | |||
Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = new HashMap<>(); | |||
for (ResourceDto module : modules) { | |||
allResourcesByModuleMap.put(module, mapper.selectProjectResources(module.getUuid())); | |||
} |
@@ -22,9 +22,9 @@ package org.sonar.db.metric; | |||
import com.google.common.base.Predicate; | |||
import com.google.common.collect.Collections2; | |||
import com.google.common.collect.Lists; | |||
import com.google.common.collect.Maps; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
@@ -68,9 +68,11 @@ public class MetricDao implements Dao { | |||
} | |||
public List<MetricDto> selectEnabled(DbSession session, @Nullable Boolean isCustom, int offset, int limit) { | |||
Map<String, Object> properties = Maps.newHashMapWithExpectedSize(1); | |||
Map<String, Object> properties; | |||
if (isCustom != null) { | |||
properties.put("isCustom", isCustom); | |||
properties = Collections.singletonMap("isCustom", isCustom); | |||
} else { | |||
properties = Collections.emptyMap(); | |||
} | |||
return mapper(session).selectAllEnabled(properties, new RowBounds(offset, limit)); |
@@ -303,9 +303,9 @@ public class PropertiesDao implements Dao { | |||
public void saveGlobalProperties(Map<String, String> properties) { | |||
try (DbSession session = mybatis.openSession(false)) { | |||
PropertiesMapper mapper = getMapper(session); | |||
properties.entrySet().forEach(entry -> { | |||
mapper.deleteGlobalProperty(entry.getKey()); | |||
save(mapper, entry.getKey(), null, null, entry.getValue()); | |||
properties.forEach((key, value) -> { | |||
mapper.deleteGlobalProperty(key); | |||
save(mapper, key, null, null, value); | |||
}); | |||
session.commit(); | |||
} |
@@ -21,10 +21,10 @@ package org.sonar.db.user; | |||
import com.google.common.collect.ArrayListMultimap; | |||
import com.google.common.collect.ImmutableMap; | |||
import com.google.common.collect.Maps; | |||
import com.google.common.collect.Multimap; | |||
import com.google.common.collect.Multiset; | |||
import java.util.Collection; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.ibatis.session.RowBounds; | |||
@@ -56,7 +56,7 @@ public class GroupMembershipDao implements Dao { | |||
} | |||
public Map<String, Integer> countUsersByGroups(DbSession session, Collection<Integer> groupIds) { | |||
Map<String, Integer> result = Maps.newHashMap(); | |||
Map<String, Integer> result = new HashMap<>(); | |||
executeLargeInputs( | |||
groupIds, | |||
input -> { |
@@ -236,7 +236,7 @@ public class ProjectAlmBindingDaoTest { | |||
underTest.insertOrUpdate(dbSession, BITBUCKETCLOUD, ANOTHER_REPO, "foo", null, "http://foo"); | |||
assertThat(underTest.selectByRepoIds(dbSession, GITHUB, Arrays.asList(A_REPO, ANOTHER_REPO, "foo"))) | |||
.extracting(ProjectAlmBindingDto::getUuid, t -> t.getAlm(), ProjectAlmBindingDto::getRepoId, ProjectAlmBindingDto::getProjectUuid, | |||
.extracting(ProjectAlmBindingDto::getUuid, ProjectAlmBindingDto::getAlm, ProjectAlmBindingDto::getRepoId, ProjectAlmBindingDto::getProjectUuid, | |||
ProjectAlmBindingDto::getUrl, ProjectAlmBindingDto::getGithubSlug) | |||
.containsExactlyInAnyOrder( | |||
tuple("uuid1", GITHUB, A_REPO, A_UUID, A_URL, A_GITHUB_SLUG), |
@@ -64,7 +64,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
dbSession.commit(); | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects")) | |||
.extracting(t -> (String) t.get("UUID"), t -> (String) t.get("KEE")) | |||
.extracting(t -> t.get("UUID"), t -> t.get("KEE")) | |||
.containsOnly( | |||
Tuple.tuple("A", "org.struts:struts"), | |||
Tuple.tuple("B", "struts:core"), | |||
@@ -278,7 +278,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
dbSession.commit(); | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects")) | |||
.extracting(t -> (String) t.get("UUID"), t -> (String) t.get("KEE")) | |||
.extracting(t -> t.get("UUID"), t -> t.get("KEE")) | |||
.containsOnly( | |||
Tuple.tuple("A", "org.apache.struts:struts"), | |||
Tuple.tuple("B", "org.apache.struts:struts-core"), | |||
@@ -298,7 +298,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
dbSession.commit(); | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects")) | |||
.extracting(t -> (String) t.get("UUID"), t -> (String) t.get("KEE")) | |||
.extracting(t -> t.get("UUID"), t -> t.get("KEE")) | |||
.containsOnly( | |||
Tuple.tuple("A", "org.struts:struts"), | |||
Tuple.tuple("B", "org.struts:struts-core"), | |||
@@ -337,7 +337,7 @@ public class ComponentKeyUpdaterDaoTest { | |||
dbSession.commit(); | |||
assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects")) | |||
.extracting(t -> (String) t.get("UUID"), t -> (String) t.get("KEE")) | |||
.extracting(t -> t.get("UUID"), t -> t.get("KEE")) | |||
.containsOnly( | |||
Tuple.tuple("A", "org.apache.struts:struts"), | |||
Tuple.tuple("B", "org.apache.struts:struts-core"), |
@@ -25,6 +25,8 @@ import java.nio.charset.Charset; | |||
import java.sql.SQLException; | |||
import org.apache.commons.io.FileUtils; | |||
import static java.nio.charset.StandardCharsets.UTF_8; | |||
public class DumpSQSchema { | |||
public static void main(String[] args) { | |||
@@ -36,7 +38,7 @@ public class DumpSQSchema { | |||
System.exit(1); | |||
} | |||
Charset charset = Charset.forName("UTF8"); | |||
Charset charset = UTF_8; | |||
String oldContent = FileUtils.readFileToString(targetFile, charset); | |||
String newContent = dumper.dumpToText(); | |||
boolean upToDate = newContent.equals(oldContent); |
@@ -73,7 +73,7 @@ public class IssueMapperTest { | |||
private System2 system2 = new AlwaysIncreasingSystem2(); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
project = ComponentTesting.newPrivateProjectDto(organizationDto); | |||
dbTester.getDbClient().componentDao().insert(dbSession, project); | |||
@@ -458,7 +458,7 @@ public class IssueMapperTest { | |||
ComponentDto component = randomComponent(organization); | |||
IssueDto issue = insertNewClosedIssue(component, ruleType); | |||
Date date = new Date(); | |||
IssueChangeDto changes[] = new IssueChangeDto[] { | |||
IssueChangeDto[] changes = new IssueChangeDto[] { | |||
insertToClosedDiff(issue, DateUtils.addDays(date, -10)), | |||
insertToClosedDiff(issue, DateUtils.addDays(date, -60)), | |||
insertToClosedDiff(issue, date), | |||
@@ -485,7 +485,7 @@ public class IssueMapperTest { | |||
ComponentDto component = randomComponent(organization); | |||
IssueDto issue = insertNewClosedIssue(component, ruleType); | |||
Date date = new Date(); | |||
IssueChangeDto changes[] = new IssueChangeDto[] { | |||
IssueChangeDto[] changes = new IssueChangeDto[] { | |||
insertToClosedDiff(issue, DateUtils.addDays(date, -10), Issue.STATUS_CLOSED, Issue.STATUS_REOPENED), | |||
insertToClosedDiff(issue, DateUtils.addDays(date, -60)), | |||
insertToClosedDiff(issue, date), |
@@ -58,7 +58,7 @@ public class LiveMeasureDaoTest { | |||
private MetricDto metric; | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
metric = db.measures().insertMetric(); | |||
} | |||
@@ -77,7 +77,7 @@ public class AuthorizationDaoTest { | |||
private String randomPermission = "p" + random.nextInt(); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
organization = db.organizations().insert(); | |||
user = db.users().insertUser(); | |||
group1 = db.users().insertGroup(organization, "group1"); |
@@ -66,7 +66,7 @@ public class GroupPermissionDaoTest { | |||
private String defaultOrganizationUuid; | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
defaultOrganizationUuid = db.getDefaultOrganization().getUuid(); | |||
} | |||
@@ -745,13 +745,13 @@ public class UserPermissionDaoTest { | |||
assertThat(underTest.selectUserIdsByQuery(dbSession, query)).containsExactly(expectedUserIds.toArray(new Integer[0])); | |||
List<UserPermissionDto> currentPermissions = underTest.selectUserPermissionsByQuery(dbSession, query, expectedUserIds); | |||
assertThat(currentPermissions).hasSize(expectedPermissions.length); | |||
List<Tuple> expectedPermissionsAsTuple = Arrays.stream(expectedPermissions) | |||
Tuple[] expectedPermissionsAsTuple = Arrays.stream(expectedPermissions) | |||
.map(expectedPermission -> tuple(expectedPermission.getUserId(), expectedPermission.getPermission(), expectedPermission.getComponentId(), | |||
expectedPermission.getOrganizationUuid())) | |||
.collect(Collectors.toList()); | |||
.toArray(Tuple[]::new); | |||
assertThat(currentPermissions) | |||
.extracting(UserPermissionDto::getUserId, UserPermissionDto::getPermission, UserPermissionDto::getComponentId, UserPermissionDto::getOrganizationUuid) | |||
.containsOnly(expectedPermissionsAsTuple.toArray(new Tuple[0])); | |||
.containsOnly(expectedPermissionsAsTuple); | |||
// test method "countUsers()" | |||
long distinctUsers = stream(expectedPermissions).mapToLong(UserPermissionDto::getUserId).distinct().count(); |
@@ -65,7 +65,7 @@ public class PermissionTemplateDaoTest { | |||
private PermissionTemplateDao underTest = new PermissionTemplateDao(system2); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
when(system2.now()).thenReturn(NOW.getTime()); | |||
} | |||
@@ -83,7 +83,7 @@ public class PurgeCommandsTest { | |||
} | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
} | |||
@@ -237,7 +237,7 @@ public class PurgeDaoTest { | |||
dbSession.commit(); | |||
assertThat(db.select("select metric_id as \"METRIC\",analysis_uuid as \"ANALYSIS\" from project_measures")) | |||
.extracting(t -> ((Long) t.get("METRIC")).intValue(), t -> (String) t.get("ANALYSIS")) | |||
.extracting(t -> ((Long) t.get("METRIC")).intValue(), t -> t.get("ANALYSIS")) | |||
.containsOnly( | |||
tuple(metricWithHistory.getId(), lastAnalysis.getUuid()), | |||
tuple(metricWithoutHistory.getId(), lastAnalysis.getUuid()), |
@@ -41,7 +41,7 @@ public class PurgeMapperTest { | |||
private PurgeMapper purgeMapper; | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
dbSession = db.getDbClient().openSession(false); | |||
purgeMapper = dbSession.getMapper(PurgeMapper.class); | |||
} |
@@ -80,7 +80,7 @@ public class PurgeProfilerTest { | |||
verify(logger).info(contains("bar: 5ms")); | |||
} | |||
private class MockedClock extends PurgeProfiler.Clock { | |||
private static class MockedClock extends PurgeProfiler.Clock { | |||
private long now = 0; | |||
@Override |
@@ -33,7 +33,6 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | |||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | |||
public class QProfileChangeDaoTest { |
@@ -51,7 +51,7 @@ public class GroupMembershipDaoTest { | |||
private GroupMembershipDao underTest = db.getDbClient().groupMembershipDao(); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
organizationDto = db.organizations().insert(); | |||
user1 = db.users().insertUser(u -> u.setLogin("admin login").setName("Admin name").setEmail("admin@email.com")); | |||
user2 = db.users().insertUser(u -> u.setLogin("not.admin").setName("Not Admin").setEmail("Not Admin")); |
@@ -320,7 +320,7 @@ public class UserDaoTest { | |||
@Test | |||
public void insert_user() { | |||
Long date = DateUtils.parseDate("2014-06-20").getTime(); | |||
long date = DateUtils.parseDate("2014-06-20").getTime(); | |||
UserDto userDto = new UserDto() | |||
.setId(1) |
@@ -172,7 +172,7 @@ public class SQDatabase extends DefaultDatabase { | |||
new MigrationHistoryTableImpl(noopDatabase).start(); | |||
} | |||
private class NoopDatabase implements Database { | |||
private static class NoopDatabase implements Database { | |||
private final Dialect dialect; | |||
private final DataSource dataSource; | |||
@@ -89,7 +89,7 @@ class TestDbImpl extends CoreTestDb { | |||
MyBatisConfExtension[] extensionArray = confExtensions.length == 0 ? null : confExtensions; | |||
if (schemaPath == null) { | |||
if (defaultSchemaBaseTestDb == null) { | |||
defaultSchemaBaseTestDb = new TestDbImpl((String) null); | |||
defaultSchemaBaseTestDb = new TestDbImpl(null); | |||
} | |||
if (extensionArray != null) { | |||
return defaultSchemaTestDbsWithExtensions.computeIfAbsent( |
@@ -34,12 +34,10 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
public class NotificationDbTester { | |||
private static final String PROP_NOTIFICATION_PREFIX = "notification"; | |||
private final DbTester db; | |||
private final DbClient dbClient; | |||
private final DbSession dbSession; | |||
public NotificationDbTester(DbTester db) { | |||
this.db = db; | |||
this.dbClient = db.getDbClient(); | |||
this.dbSession = db.getSession(); | |||
} |
@@ -32,13 +32,12 @@ public class GroupTesting { | |||
} | |||
public static GroupDto newGroupDto() { | |||
GroupDto group = new GroupDto() | |||
return new GroupDto() | |||
.setId(nextInt()) | |||
.setOrganizationUuid(randomAlphanumeric(40)) | |||
.setName(randomAlphanumeric(255)) | |||
.setDescription(randomAlphanumeric(200)) | |||
.setCreatedAt(new Date(nextLong())) | |||
.setUpdatedAt(new Date(nextLong())); | |||
return group; | |||
} | |||
} |
@@ -152,7 +152,7 @@ public class MssqlCharsetHandlerTest { | |||
}); | |||
} | |||
} | |||
return res.stream().toArray(Object[][]::new); | |||
return res.toArray(new Object[0][]); | |||
} | |||
@Test |
@@ -27,12 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
public class MigrationContainerImplTest { | |||
private ComponentContainer parent = new ComponentContainer(); | |||
private MigrationContainerPopulator populator = new MigrationContainerPopulator() { | |||
@Override | |||
public void populateContainer(MigrationContainer container) { | |||
container.add(StartCallCounter.class); | |||
} | |||
}; | |||
private MigrationContainerPopulator populator = container -> container.add(StartCallCounter.class); | |||
private MigrationContainerImpl underTest = new MigrationContainerImpl(parent, populator); | |||
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.engine; | |||
import java.sql.SQLException; | |||
import java.util.stream.Stream; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
@@ -43,7 +42,7 @@ public class MigrationContainerPopulatorImplTest { | |||
private MigrationContainerPopulatorImpl underTest = new MigrationContainerPopulatorImpl(); | |||
@Before | |||
public void setUp() throws Exception { | |||
public void setUp() { | |||
migrationContainer.add(migrationSteps); | |||
} | |||
@@ -116,7 +115,7 @@ public class MigrationContainerPopulatorImplTest { | |||
private static abstract class NoopMigrationStep implements MigrationStep { | |||
@Override | |||
public void execute() throws SQLException { | |||
public void execute() { | |||
throw new UnsupportedOperationException("execute not implemented"); | |||
} | |||
} |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.engine; | |||
import java.sql.SQLException; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import org.junit.Test; | |||
@@ -47,12 +46,7 @@ public class MigrationEngineImplTest { | |||
private MigrationHistory migrationHistory = mock(MigrationHistory.class); | |||
private ComponentContainer serverContainer = new ComponentContainer(); | |||
private MigrationStepsExecutor stepsExecutor = mock(MigrationStepsExecutor.class); | |||
private MigrationContainerPopulator populator = new MigrationContainerPopulator() { | |||
@Override | |||
public void populateContainer(MigrationContainer container) { | |||
container.add(stepsExecutor); | |||
} | |||
}; | |||
private MigrationContainerPopulator populator = container -> container.add(stepsExecutor); | |||
private MigrationSteps migrationSteps = mock(MigrationSteps.class); | |||
private MapSettings settings = new MapSettings(); | |||
@@ -117,7 +111,7 @@ public class MigrationEngineImplTest { | |||
private static class TestBlueGreenMigrationStep implements MigrationStep { | |||
@Override | |||
public void execute() throws SQLException { | |||
public void execute() { | |||
} | |||
} |
@@ -119,11 +119,8 @@ public class DataChangeTest { | |||
new DataChange(db.database()) { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).get(new RowReader<Long>() { | |||
@Override | |||
public Long read(Row row) { | |||
throw new IllegalStateException("Unexpected error"); | |||
} | |||
context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).get((RowReader<Long>) row -> { | |||
throw new IllegalStateException("Unexpected error"); | |||
}); | |||
} | |||
}.execute(); | |||
@@ -140,11 +137,8 @@ public class DataChangeTest { | |||
new DataChange(db.database()) { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).list(new RowReader<Long>() { | |||
@Override | |||
public Long read(Row row) { | |||
throw new IllegalStateException("Unexpected error"); | |||
} | |||
context.prepareSelect("select id from persons where id>=?").setLong(1, 2L).list((RowReader<Long>) row -> { | |||
throw new IllegalStateException("Unexpected error"); | |||
}); | |||
} | |||
}.execute(); | |||
@@ -155,12 +149,11 @@ public class DataChangeTest { | |||
public void bad_parameterized_query() throws Exception { | |||
insertPersons(); | |||
final List<Long> ids = new ArrayList<>(); | |||
DataChange change = new DataChange(db.database()) { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
// parameter value is not set | |||
ids.addAll(context.prepareSelect("select id from persons where id>=?").list(Select.LONG_READER)); | |||
context.prepareSelect("select id from persons where id>=?").list(Select.LONG_READER); | |||
} | |||
}; | |||
@@ -177,12 +170,7 @@ public class DataChangeTest { | |||
new DataChange(db.database()) { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.prepareSelect("select id from persons order by id desc").scroll(new Select.RowHandler() { | |||
@Override | |||
public void handle(Row row) throws SQLException { | |||
ids.add(row.getNullableLong(1)); | |||
} | |||
}); | |||
context.prepareSelect("select id from persons order by id desc").scroll(row -> ids.add(row.getNullableLong(1))); | |||
} | |||
}.execute(); | |||
assertThat(ids).containsExactly(3L, 2L, 1L); | |||
@@ -372,11 +360,8 @@ public class DataChangeTest { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
final Upsert upsert = context.prepareUpsert("update persons set login=?, age=? where id=?"); | |||
context.prepareSelect("select id from persons").scroll(new Select.RowHandler() { | |||
@Override | |||
public void handle(Row row) { | |||
throw new IllegalStateException("Unexpected error"); | |||
} | |||
context.prepareSelect("select id from persons").scroll(row -> { | |||
throw new IllegalStateException("Unexpected error"); | |||
}); | |||
upsert.commit().close(); | |||
} | |||
@@ -393,16 +378,13 @@ public class DataChangeTest { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select id from persons where id>=?").setLong(1, 2L); | |||
massUpdate.update("update persons set login=?, age=? where id=?"); | |||
massUpdate.execute(new MassUpdate.Handler() { | |||
@Override | |||
public boolean handle(Row row, SqlStatement update) throws SQLException { | |||
long id = row.getNullableLong(1); | |||
update | |||
.setString(1, "login" + id) | |||
.setInt(2, 10 + (int) id) | |||
.setLong(3, id); | |||
return true; | |||
} | |||
massUpdate.execute((row, update) -> { | |||
long id = row.getNullableLong(1); | |||
update | |||
.setString(1, "login" + id) | |||
.setInt(2, 10 + (int) id) | |||
.setLong(3, id); | |||
return true; | |||
}); | |||
} | |||
}.execute(); | |||
@@ -425,11 +407,8 @@ public class DataChangeTest { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select id from persons where id>=?").setLong(1, 2L); | |||
massUpdate.update("update persons set login=?, age=? where id=?"); | |||
massUpdate.execute(new MassUpdate.Handler() { | |||
@Override | |||
public boolean handle(Row row, SqlStatement update) { | |||
throw new IllegalStateException("Unexpected error"); | |||
} | |||
massUpdate.execute((row, update) -> { | |||
throw new IllegalStateException("Unexpected error"); | |||
}); | |||
} | |||
}.execute(); | |||
@@ -445,12 +424,7 @@ public class DataChangeTest { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select id from persons where id>=?").setLong(1, 2L); | |||
massUpdate.update("update persons set login=?, age=? where id=?"); | |||
massUpdate.execute(new MassUpdate.Handler() { | |||
@Override | |||
public boolean handle(Row row, SqlStatement update) { | |||
return false; | |||
} | |||
}); | |||
massUpdate.execute((row, update) -> false); | |||
} | |||
}.execute(); | |||
@@ -467,12 +441,7 @@ public class DataChangeTest { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select id from persons where id>=?").setLong(1, 2L); | |||
// update is not set | |||
massUpdate.execute(new MassUpdate.Handler() { | |||
@Override | |||
public boolean handle(Row row, SqlStatement update) { | |||
return false; | |||
} | |||
}); | |||
massUpdate.execute((row, update) -> false); | |||
} | |||
}; | |||
try { |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.step; | |||
import java.sql.SQLException; | |||
import java.util.List; | |||
import java.util.Random; | |||
import org.junit.Rule; | |||
@@ -109,7 +108,7 @@ public class MigrationStepRegistryImplTest { | |||
private static abstract class NoopMigrationStep implements MigrationStep { | |||
@Override | |||
public void execute() throws SQLException { | |||
public void execute() { | |||
throw new IllegalStateException("execute is not implemented"); | |||
} | |||
} |
@@ -165,7 +165,7 @@ public class MigrationStepsExecutorImplTest { | |||
private boolean called = false; | |||
@Override | |||
public void execute() throws SQLException { | |||
public void execute() { | |||
checkState(!called, "execute must not be called twice"); | |||
this.called = true; | |||
calledSteps.add(getClass()); | |||
@@ -205,7 +205,7 @@ public class MigrationStepsExecutorImplTest { | |||
private static final RuntimeException THROWN_EXCEPTION = new RuntimeException("Faking failing migration step"); | |||
@Override | |||
public void execute() throws SQLException { | |||
public void execute() { | |||
throw THROWN_EXCEPTION; | |||
} | |||
} |
@@ -164,7 +164,7 @@ public class ProcessLauncherImplTest { | |||
File homeDir = temp.newFolder(); | |||
File dataDir = temp.newFolder(); | |||
File logDir = temp.newFolder(); | |||
ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> new TestProcessBuilder()); | |||
ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, TestProcessBuilder::new); | |||
EsScriptCommand command = createEsScriptCommand(tempDir, homeDir, dataDir, logDir); | |||
File outdatedEsDir = new File(dataDir, "es"); |
@@ -144,7 +144,7 @@ public class AppNodesClusterHostsConsistencyTest { | |||
return member; | |||
} | |||
private class TestHazelcastMember implements HazelcastMember { | |||
private static class TestHazelcastMember implements HazelcastMember { | |||
private final Map<Member, List<String>> hostsPerMember; | |||
private final Cluster cluster = mock(Cluster.class); | |||
@@ -52,7 +52,7 @@ public class WebJvmOptionsTest { | |||
} | |||
@Test | |||
public void constructor_sets_mandatory_JVM_options_for_java11() throws IOException { | |||
public void constructor_sets_mandatory_JVM_options_for_java11() { | |||
when(javaVersion.isAtLeastJava11()).thenReturn(true); | |||
underTest = new WebJvmOptions(tmpDir, javaVersion); | |||
@@ -125,7 +125,7 @@ public class EsManagedProcessTest { | |||
); | |||
} | |||
private class MemoryAppender<E> extends AppenderBase<E> { | |||
private static class MemoryAppender<E> extends AppenderBase<E> { | |||
private final List<E> events = new ArrayList(); | |||
@Override |