From 556bb9e43c9b5119c8830bf4abcffef8c56256a3 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 5 Mar 2014 10:28:40 +0100 Subject: Move WorkDuration API to internal package as it will be refactored is 4.3 --- .../java/org/sonar/plugins/core/CorePlugin.java | 2 +- .../plugins/core/issue/IssueTrackingDecorator.java | 2 +- .../core/issue/IssueTrackingDecoratorTest.java | 2 +- .../NewTechnicalDebtDecoratorTest.java | 2 +- .../sonar/batch/bootstrap/BootstrapContainer.java | 2 +- .../org/sonar/batch/debt/RuleDebtCalculator.java | 2 +- .../org/sonar/batch/scan/ProjectScanContainer.java | 30 +-- .../org/sonar/batch/debt/DebtModelLoaderTest.java | 2 +- .../sonar/batch/debt/RuleDebtCalculatorTest.java | 2 +- .../org/sonar/core/i18n/WorkDurationFormatter.java | 4 +- .../technicaldebt/TechnicalDebtXMLImporter.java | 2 +- .../core/technicaldebt/db/CharacteristicDto.java | 2 +- .../sonar/core/i18n/WorkDurationFormatterTest.java | 2 +- .../DefaultTechnicalDebtManagerTest.java | 2 +- .../DefaultTechnicalDebtModelTest.java | 2 +- .../TechnicalDebtModelSynchronizerTest.java | 2 +- .../TechnicalDebtXMLImporterTest.java | 2 +- .../technicaldebt/db/CharacteristicDtoTest.java | 2 +- .../sonar/api/technicaldebt/batch/Requirement.java | 2 +- .../batch/internal/DefaultRequirement.java | 2 +- .../api/technicaldebt/server/Characteristic.java | 2 +- .../server/internal/DefaultCharacteristic.java | 2 +- .../java/org/sonar/api/utils/WorkDuration.java | 199 -------------------- .../org/sonar/api/utils/WorkDurationFactory.java | 66 ------- .../org/sonar/api/utils/internal/WorkDuration.java | 200 ++++++++++++++++++++ .../api/utils/internal/WorkDurationFactory.java | 66 +++++++ .../batch/internal/DefaultRequirementTest.java | 2 +- .../server/internal/DefaultCharacteristicTest.java | 2 +- .../sonar/api/utils/WorkDurationFactoryTest.java | 67 ------- .../java/org/sonar/api/utils/WorkDurationTest.java | 201 --------------------- .../utils/internal/WorkDurationFactoryTest.java | 67 +++++++ .../sonar/api/utils/internal/WorkDurationTest.java | 201 +++++++++++++++++++++ .../java/org/sonar/server/platform/Platform.java | 2 +- .../sonar/server/technicaldebt/DebtService.java | 4 +- .../server/technicaldebt/DebtServiceTest.java | 4 +- 35 files changed, 567 insertions(+), 588 deletions(-) delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDuration.java create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDurationFactory.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java delete mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java create mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/WorkDurationFactoryTest.java create mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/WorkDurationTest.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index 0031a119e2e..2125611d25b 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -24,7 +24,7 @@ import org.sonar.api.*; import org.sonar.api.checks.NoSonarFilter; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.resources.Qualifiers; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.batch.components.PastSnapshotFinder; import org.sonar.batch.debt.IssueChangelogDebtCalculator; import org.sonar.batch.issue.ignore.IssueExclusionsConfiguration; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java index f6cbb572a0d..67c362054a1 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java @@ -39,7 +39,7 @@ import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.utils.KeyValueFormat; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.LastSnapshots; import org.sonar.core.issue.IssueUpdater; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java index 3f9531b9baa..95e42c2f698 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java @@ -38,7 +38,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.LastSnapshots; import org.sonar.core.issue.IssueUpdater; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java index df2c8944b0b..184086d9f3a 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java @@ -41,7 +41,7 @@ import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; import org.sonar.api.resources.Resource; import org.sonar.api.test.IsMeasure; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.batch.components.Period; import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.batch.debt.IssueChangelogDebtCalculator; diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java index da73f5f7e95..88a43090fbd 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java @@ -26,8 +26,8 @@ import org.sonar.api.platform.ComponentContainer; import org.sonar.api.platform.PluginMetadata; import org.sonar.api.utils.HttpDownloader; import org.sonar.api.utils.UriReader; -import org.sonar.api.utils.WorkDurationFactory; import org.sonar.api.utils.internal.TempFolderCleaner; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.batch.components.*; import org.sonar.core.config.Logback; import org.sonar.core.i18n.DefaultI18n; diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/RuleDebtCalculator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/RuleDebtCalculator.java index e3e6449a4d4..2352e791984 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/RuleDebtCalculator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/RuleDebtCalculator.java @@ -27,7 +27,7 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.batch.Requirement; import org.sonar.api.technicaldebt.batch.TechnicalDebtModel; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import javax.annotation.CheckForNull; import javax.annotation.Nullable; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index c86e1fc25c6..e6ac170f8f2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -31,41 +31,19 @@ import org.sonar.api.resources.Languages; import org.sonar.api.resources.Project; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.SonarException; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.batch.DefaultFileLinesContextFactory; import org.sonar.batch.DefaultResourceCreationLock; import org.sonar.batch.ProjectConfigurator; import org.sonar.batch.ProjectTree; -import org.sonar.batch.bootstrap.BootstrapSettings; -import org.sonar.batch.bootstrap.ExtensionInstaller; -import org.sonar.batch.bootstrap.ExtensionMatcher; -import org.sonar.batch.bootstrap.ExtensionUtils; -import org.sonar.batch.bootstrap.MetricProvider; +import org.sonar.batch.bootstrap.*; import org.sonar.batch.components.PeriodsDefinition; import org.sonar.batch.debt.DebtModelLoader; import org.sonar.batch.debt.DebtModelProvider; import org.sonar.batch.debt.IssueChangelogDebtCalculator; import org.sonar.batch.debt.RuleDebtCalculator; -import org.sonar.batch.index.Caches; -import org.sonar.batch.index.ComponentDataCache; -import org.sonar.batch.index.ComponentDataPersister; -import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.index.DefaultPersistenceManager; -import org.sonar.batch.index.DefaultResourcePersister; -import org.sonar.batch.index.DependencyPersister; -import org.sonar.batch.index.EventPersister; -import org.sonar.batch.index.LinkPersister; -import org.sonar.batch.index.MeasurePersister; -import org.sonar.batch.index.MemoryOptimizer; -import org.sonar.batch.index.ResourceCache; -import org.sonar.batch.index.ResourceKeyMigration; -import org.sonar.batch.index.SnapshotCache; -import org.sonar.batch.index.SourcePersister; -import org.sonar.batch.issue.DefaultProjectIssues; -import org.sonar.batch.issue.DeprecatedViolations; -import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.issue.IssuePersister; -import org.sonar.batch.issue.ScanIssueStorage; +import org.sonar.batch.index.*; +import org.sonar.batch.issue.*; import org.sonar.batch.phases.GraphPersister; import org.sonar.batch.profiling.PhasesSumUpTimeProfiler; import org.sonar.batch.qualitygate.ProjectAlerts; diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelLoaderTest.java index e22c6c978f9..2de08c8f77a 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelLoaderTest.java @@ -31,7 +31,7 @@ import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel; import org.sonar.core.technicaldebt.db.CharacteristicDao; import org.sonar.core.technicaldebt.db.CharacteristicDto; diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java index 96ecfd2edf0..59cd9c3efbd 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/debt/RuleDebtCalculatorTest.java @@ -30,7 +30,7 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.batch.TechnicalDebtModel; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/WorkDurationFormatter.java b/sonar-core/src/main/java/org/sonar/core/i18n/WorkDurationFormatter.java index af7b709e5d5..93d652c2757 100644 --- a/sonar-core/src/main/java/org/sonar/core/i18n/WorkDurationFormatter.java +++ b/sonar-core/src/main/java/org/sonar/core/i18n/WorkDurationFormatter.java @@ -24,8 +24,8 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.BatchExtension; import org.sonar.api.ServerComponent; -import org.sonar.api.utils.WorkDuration; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDuration; +import org.sonar.api.utils.internal.WorkDurationFactory; import javax.annotation.CheckForNull; import javax.annotation.Nullable; diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java index 758e8bb599e..12c307dd004 100644 --- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java +++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java @@ -37,7 +37,7 @@ import org.sonar.api.rules.Rule; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; import org.sonar.api.utils.ValidationMessages; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import org.sonar.core.technicaldebt.db.CharacteristicDto; import javax.annotation.CheckForNull; diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java index acbb5e56245..18a1bb9034d 100644 --- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java +++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java @@ -23,7 +23,7 @@ package org.sonar.core.technicaldebt.db; import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import javax.annotation.CheckForNull; import javax.annotation.Nullable; diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/WorkDurationFormatterTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/WorkDurationFormatterTest.java index 5185afd4d4c..984b2f78364 100644 --- a/sonar-core/src/test/java/org/sonar/core/i18n/WorkDurationFormatterTest.java +++ b/sonar-core/src/test/java/org/sonar/core/i18n/WorkDurationFormatterTest.java @@ -24,7 +24,7 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDurationFactory; import static com.google.common.collect.Lists.newArrayList; import static org.fest.assertions.Assertions.assertThat; diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java index f6369fe9209..9095488504c 100644 --- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java @@ -29,7 +29,7 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.technicaldebt.server.Characteristic; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import org.sonar.core.technicaldebt.db.CharacteristicDao; import org.sonar.core.technicaldebt.db.CharacteristicDto; diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java index 246269c48c3..ef857e167d1 100644 --- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java +++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import static org.fest.assertions.Assertions.assertThat; diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizerTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizerTest.java index 9baa526ce67..5419bb96978 100644 --- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizerTest.java @@ -35,7 +35,7 @@ import org.sonar.api.rules.Rule; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; import org.sonar.api.utils.ValidationMessages; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import org.sonar.core.persistence.MyBatis; import org.sonar.core.technicaldebt.db.CharacteristicDao; import org.sonar.core.technicaldebt.db.CharacteristicDto; diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest.java index 1b5133a94fb..64c5dea9492 100644 --- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest.java +++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest.java @@ -32,7 +32,7 @@ import org.sonar.api.rules.RuleQuery; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; import org.sonar.api.utils.ValidationMessages; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import java.io.IOException; diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java index 9544b529b4f..f6730185360 100644 --- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; -import org.sonar.api.utils.WorkDuration; +import org.sonar.api.utils.internal.WorkDuration; import java.util.Date; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java index 60e41eb5e96..31f2ff781ed 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java @@ -21,8 +21,8 @@ package org.sonar.api.technicaldebt.batch; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.WorkDuration; import org.sonar.api.utils.WorkUnit; +import org.sonar.api.utils.internal.WorkDuration; import java.util.Date; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java index a028a567e73..b46196312a2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java @@ -25,8 +25,8 @@ import org.apache.commons.lang.builder.ToStringStyle; import org.picocontainer.annotations.Nullable; import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.batch.Requirement; -import org.sonar.api.utils.WorkDuration; import org.sonar.api.utils.WorkUnit; +import org.sonar.api.utils.internal.WorkDuration; import javax.annotation.CheckForNull; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java index 0b016e172bc..1befa3cb282 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java @@ -21,8 +21,8 @@ package org.sonar.api.technicaldebt.server; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.WorkDuration; import org.sonar.api.utils.WorkUnit; +import org.sonar.api.utils.internal.WorkDuration; import javax.annotation.CheckForNull; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java index 5f95d54fff7..12e8d64d562 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java @@ -24,8 +24,8 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.server.Characteristic; -import org.sonar.api.utils.WorkDuration; import org.sonar.api.utils.WorkUnit; +import org.sonar.api.utils.internal.WorkDuration; import javax.annotation.CheckForNull; import javax.annotation.Nullable; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java deleted file mode 100644 index 1f8703ebfe5..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDuration.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.utils; - -import com.google.common.annotations.VisibleForTesting; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; - -import javax.annotation.Nullable; -import java.io.Serializable; - -/** - * @since 4.2 - */ -public class WorkDuration implements Serializable { - - static final int DAY_POSITION_IN_LONG = 10000; - static final int HOUR_POSITION_IN_LONG = 100; - static final int MINUTE_POSITION_IN_LONG = 1; - - public static enum UNIT { - DAYS, HOURS, MINUTES - } - - private int hoursInDay; - - private long durationInMinutes; - private int days; - private int hours; - private int minutes; - - private WorkDuration(long durationInMinutes, int days, int hours, int minutes, int hoursInDay) { - this.durationInMinutes = durationInMinutes; - this.days = days; - this.hours = hours; - this.minutes = minutes; - this.hoursInDay = hoursInDay; - } - - public static WorkDuration create(int days, int hours, int minutes, int hoursInDay) { - long durationInSeconds = 60L * days * hoursInDay; - durationInSeconds += 60L * hours; - durationInSeconds += minutes; - return new WorkDuration(durationInSeconds, days, hours, minutes, hoursInDay); - } - - public static WorkDuration createFromValueAndUnit(int value, UNIT unit, int hoursInDay) { - switch (unit) { - case DAYS: - return create(value, 0, 0, hoursInDay); - case HOURS: - return create(0, value, 0, hoursInDay); - case MINUTES: - return create(0, 0, value, hoursInDay); - default: - throw new IllegalStateException("Cannot create work duration"); - } - } - - static WorkDuration createFromLong(long duration, int hoursInDay) { - int days = 0, hours = 0, minutes = 0; - - long time = duration; - Long currentTime = time / WorkDuration.DAY_POSITION_IN_LONG; - if (currentTime > 0) { - days = (currentTime.intValue()); - time = time - (currentTime * WorkDuration.DAY_POSITION_IN_LONG); - } - - currentTime = time / WorkDuration.HOUR_POSITION_IN_LONG; - if (currentTime > 0) { - hours = currentTime.intValue(); - time = time - (currentTime * WorkDuration.HOUR_POSITION_IN_LONG); - } - - currentTime = time / WorkDuration.MINUTE_POSITION_IN_LONG; - if (currentTime > 0) { - minutes = currentTime.intValue(); - } - return WorkDuration.create(days, hours, minutes, hoursInDay); - } - - static WorkDuration createFromMinutes(long duration, int hoursInDay) { - int days = ((Double) (duration / hoursInDay / 60d)).intValue(); - Long currentDurationInMinutes = duration - (60L * days * hoursInDay); - int hours = ((Double) (currentDurationInMinutes / 60d)).intValue(); - currentDurationInMinutes = currentDurationInMinutes - (60L * hours); - return new WorkDuration(duration, days, hours, currentDurationInMinutes.intValue(), hoursInDay); - } - - /** - * Return the duration in number of working days. - * For instance, 3 days and 4 hours will return 3.5 days (if hoursIndDay is 8). - */ - public double toWorkingDays() { - return durationInMinutes / 60d / hoursInDay; - } - - /** - * Return the duration using the following format DDHHMM, where DD is the number of days, HH is the number of months, and MM the number of minutes. - * For instance, 3 days and 4 hours will return 030400 (if hoursIndDay is 8). - */ - public long toLong() { - int workingDays = days; - int workingHours = hours; - if (hours >= hoursInDay) { - int nbAdditionalDays = hours / hoursInDay; - workingDays += nbAdditionalDays; - workingHours = hours - (nbAdditionalDays * hoursInDay); - } - return workingDays * DAY_POSITION_IN_LONG + workingHours * HOUR_POSITION_IN_LONG + minutes * MINUTE_POSITION_IN_LONG; - } - - public long toMinutes() { - return durationInMinutes; - } - - public WorkDuration add(@Nullable WorkDuration with) { - if (with != null) { - return WorkDuration.createFromMinutes(this.toMinutes() + with.toMinutes(), this.hoursInDay); - } else { - return this; - } - } - - public WorkDuration subtract(@Nullable WorkDuration with) { - if (with != null) { - return WorkDuration.createFromMinutes(this.toMinutes() - with.toMinutes(), this.hoursInDay); - } else { - return this; - } - } - - public WorkDuration multiply(int factor) { - return WorkDuration.createFromMinutes(this.toMinutes() * factor, this.hoursInDay); - } - - public int days() { - return days; - } - - public int hours() { - return hours; - } - - public int minutes() { - return minutes; - } - - @VisibleForTesting - int hoursInDay() { - return hoursInDay; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - WorkDuration that = (WorkDuration) o; - if (durationInMinutes != that.durationInMinutes) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - return (int) (durationInMinutes ^ (durationInMinutes >>> 32)); - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java deleted file mode 100644 index 13175191bb7..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WorkDurationFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.utils; - -import org.sonar.api.BatchComponent; -import org.sonar.api.CoreProperties; -import org.sonar.api.ServerComponent; -import org.sonar.api.config.Settings; - -/** - * @since 4.2 - */ -public final class WorkDurationFactory implements BatchComponent, ServerComponent { - - private final Settings settings; - - public WorkDurationFactory(Settings settings) { - this.settings = settings; - } - - /** - * @deprecated since 4.3 - */ - @Deprecated - public WorkDuration createFromWorkingValue(int value, WorkDuration.UNIT unit) { - return WorkDuration.createFromValueAndUnit(value, unit, hoursInDay()); - } - - /** - * @deprecated since 4.3 - */ - @Deprecated - public WorkDuration createFromWorkingLong(long duration) { - return WorkDuration.createFromLong(duration, hoursInDay()); - } - - /** - * @since 4.3 - */ - public WorkDuration createFromMinutes(long duration) { - return WorkDuration.createFromMinutes(duration, hoursInDay()); - } - - private int hoursInDay(){ - return settings.getInt(CoreProperties.HOURS_IN_DAY); - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDuration.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDuration.java new file mode 100644 index 00000000000..c6c0319495f --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDuration.java @@ -0,0 +1,200 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.utils.internal; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +import javax.annotation.Nullable; + +import java.io.Serializable; + +/** + * @since 4.2 + */ +public class WorkDuration implements Serializable { + + static final int DAY_POSITION_IN_LONG = 10000; + static final int HOUR_POSITION_IN_LONG = 100; + static final int MINUTE_POSITION_IN_LONG = 1; + + public static enum UNIT { + DAYS, HOURS, MINUTES + } + + private int hoursInDay; + + private long durationInMinutes; + private int days; + private int hours; + private int minutes; + + private WorkDuration(long durationInMinutes, int days, int hours, int minutes, int hoursInDay) { + this.durationInMinutes = durationInMinutes; + this.days = days; + this.hours = hours; + this.minutes = minutes; + this.hoursInDay = hoursInDay; + } + + public static WorkDuration create(int days, int hours, int minutes, int hoursInDay) { + long durationInSeconds = 60L * days * hoursInDay; + durationInSeconds += 60L * hours; + durationInSeconds += minutes; + return new WorkDuration(durationInSeconds, days, hours, minutes, hoursInDay); + } + + public static WorkDuration createFromValueAndUnit(int value, UNIT unit, int hoursInDay) { + switch (unit) { + case DAYS: + return create(value, 0, 0, hoursInDay); + case HOURS: + return create(0, value, 0, hoursInDay); + case MINUTES: + return create(0, 0, value, hoursInDay); + default: + throw new IllegalStateException("Cannot create work duration"); + } + } + + static WorkDuration createFromLong(long duration, int hoursInDay) { + int days = 0, hours = 0, minutes = 0; + + long time = duration; + Long currentTime = time / WorkDuration.DAY_POSITION_IN_LONG; + if (currentTime > 0) { + days = (currentTime.intValue()); + time = time - (currentTime * WorkDuration.DAY_POSITION_IN_LONG); + } + + currentTime = time / WorkDuration.HOUR_POSITION_IN_LONG; + if (currentTime > 0) { + hours = currentTime.intValue(); + time = time - (currentTime * WorkDuration.HOUR_POSITION_IN_LONG); + } + + currentTime = time / WorkDuration.MINUTE_POSITION_IN_LONG; + if (currentTime > 0) { + minutes = currentTime.intValue(); + } + return WorkDuration.create(days, hours, minutes, hoursInDay); + } + + static WorkDuration createFromMinutes(long duration, int hoursInDay) { + int days = ((Double) (duration / hoursInDay / 60d)).intValue(); + Long currentDurationInMinutes = duration - (60L * days * hoursInDay); + int hours = ((Double) (currentDurationInMinutes / 60d)).intValue(); + currentDurationInMinutes = currentDurationInMinutes - (60L * hours); + return new WorkDuration(duration, days, hours, currentDurationInMinutes.intValue(), hoursInDay); + } + + /** + * Return the duration in number of working days. + * For instance, 3 days and 4 hours will return 3.5 days (if hoursIndDay is 8). + */ + public double toWorkingDays() { + return durationInMinutes / 60d / hoursInDay; + } + + /** + * Return the duration using the following format DDHHMM, where DD is the number of days, HH is the number of months, and MM the number of minutes. + * For instance, 3 days and 4 hours will return 030400 (if hoursIndDay is 8). + */ + public long toLong() { + int workingDays = days; + int workingHours = hours; + if (hours >= hoursInDay) { + int nbAdditionalDays = hours / hoursInDay; + workingDays += nbAdditionalDays; + workingHours = hours - (nbAdditionalDays * hoursInDay); + } + return workingDays * DAY_POSITION_IN_LONG + workingHours * HOUR_POSITION_IN_LONG + minutes * MINUTE_POSITION_IN_LONG; + } + + public long toMinutes() { + return durationInMinutes; + } + + public WorkDuration add(@Nullable WorkDuration with) { + if (with != null) { + return WorkDuration.createFromMinutes(this.toMinutes() + with.toMinutes(), this.hoursInDay); + } else { + return this; + } + } + + public WorkDuration subtract(@Nullable WorkDuration with) { + if (with != null) { + return WorkDuration.createFromMinutes(this.toMinutes() - with.toMinutes(), this.hoursInDay); + } else { + return this; + } + } + + public WorkDuration multiply(int factor) { + return WorkDuration.createFromMinutes(this.toMinutes() * factor, this.hoursInDay); + } + + public int days() { + return days; + } + + public int hours() { + return hours; + } + + public int minutes() { + return minutes; + } + + @VisibleForTesting + int hoursInDay() { + return hoursInDay; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + WorkDuration that = (WorkDuration) o; + if (durationInMinutes != that.durationInMinutes) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return (int) (durationInMinutes ^ (durationInMinutes >>> 32)); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDurationFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDurationFactory.java new file mode 100644 index 00000000000..442f68998f9 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDurationFactory.java @@ -0,0 +1,66 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.utils.internal; + +import org.sonar.api.BatchComponent; +import org.sonar.api.CoreProperties; +import org.sonar.api.ServerComponent; +import org.sonar.api.config.Settings; + +/** + * @since 4.2 + */ +public final class WorkDurationFactory implements BatchComponent, ServerComponent { + + private final Settings settings; + + public WorkDurationFactory(Settings settings) { + this.settings = settings; + } + + /** + * @deprecated since 4.3 + */ + @Deprecated + public WorkDuration createFromWorkingValue(int value, WorkDuration.UNIT unit) { + return WorkDuration.createFromValueAndUnit(value, unit, hoursInDay()); + } + + /** + * @deprecated since 4.3 + */ + @Deprecated + public WorkDuration createFromWorkingLong(long duration) { + return WorkDuration.createFromLong(duration, hoursInDay()); + } + + /** + * @since 4.3 + */ + public WorkDuration createFromMinutes(long duration) { + return WorkDuration.createFromMinutes(duration, hoursInDay()); + } + + private int hoursInDay(){ + return settings.getInt(CoreProperties.HOURS_IN_DAY); + } + +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java index 57cb94e3ec6..5420f55fa73 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java @@ -22,8 +22,8 @@ package org.sonar.api.technicaldebt.batch.internal; import org.junit.Test; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.WorkDuration; import org.sonar.api.utils.WorkUnit; +import org.sonar.api.utils.internal.WorkDuration; import java.text.SimpleDateFormat; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java index 4ae4d77241b..fbba16605f3 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java @@ -22,8 +22,8 @@ package org.sonar.api.technicaldebt.server.internal; import org.junit.Test; import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.WorkDuration; import org.sonar.api.utils.WorkUnit; +import org.sonar.api.utils.internal.WorkDuration; import static org.fest.assertions.Assertions.assertThat; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java deleted file mode 100644 index c9b1652903d..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.utils; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; - -import static org.fest.assertions.Assertions.assertThat; - -public class WorkDurationFactoryTest { - - WorkDurationFactory factory; - - static final int HOURS_IN_DAY = 8; - static final Long ONE_HOUR_IN_MINUTES = 1L * 60; - - @Before - public void setUp() throws Exception { - Settings settings = new Settings(); - settings.setProperty(CoreProperties.HOURS_IN_DAY, HOURS_IN_DAY); - factory = new WorkDurationFactory(settings); - } - - @Test - public void create_from_working_value() throws Exception { - // 1 working day -> 8 hours - assertThat(factory.createFromWorkingValue(1, WorkDuration.UNIT.DAYS).toMinutes()).isEqualTo(8L * ONE_HOUR_IN_MINUTES); - // 8 hours - assertThat(factory.createFromWorkingValue(8, WorkDuration.UNIT.HOURS).toMinutes()).isEqualTo(8L * ONE_HOUR_IN_MINUTES); - } - - @Test - public void create_from_working_long() throws Exception { - WorkDuration workDuration = factory.createFromWorkingLong(1l); - assertThat(workDuration.days()).isEqualTo(0); - assertThat(workDuration.hours()).isEqualTo(0); - assertThat(workDuration.minutes()).isEqualTo(1); - } - - @Test - public void create_from_seconds() throws Exception { - WorkDuration workDuration = factory.createFromMinutes(8L * ONE_HOUR_IN_MINUTES); - assertThat(workDuration.days()).isEqualTo(1); - assertThat(workDuration.hours()).isEqualTo(0); - assertThat(workDuration.minutes()).isEqualTo(0); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java deleted file mode 100644 index ddf60903360..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 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.api.utils; - -import org.junit.Test; - -import static org.fest.assertions.Assertions.assertThat; - -public class WorkDurationTest { - - static final int HOURS_IN_DAY = 8; - - static final Long ONE_MINUTE = 1L; - static final Long ONE_HOUR_IN_MINUTES = ONE_MINUTE * 60; - static final Long ONE_DAY_IN_MINUTES = ONE_HOUR_IN_MINUTES * HOURS_IN_DAY; - - @Test - public void create_from_days_hours_minutes() throws Exception { - WorkDuration workDuration = WorkDuration.create(1, 1, 1, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(1); - assertThat(workDuration.hours()).isEqualTo(1); - assertThat(workDuration.minutes()).isEqualTo(1); - assertThat(workDuration.toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE); - assertThat(workDuration.hoursInDay()).isEqualTo(HOURS_IN_DAY); - } - - @Test - public void create_from_value_and_unit() throws Exception { - WorkDuration result = WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY); - assertThat(result.days()).isEqualTo(1); - assertThat(result.hours()).isEqualTo(0); - assertThat(result.minutes()).isEqualTo(0); - assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); - assertThat(result.toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES); - - assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES); - assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_HOUR_IN_MINUTES); - assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_MINUTE); - } - - @Test - public void create_from_minutes() throws Exception { - WorkDuration workDuration = WorkDuration.createFromMinutes(ONE_MINUTE, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(0); - assertThat(workDuration.hours()).isEqualTo(0); - assertThat(workDuration.minutes()).isEqualTo(1); - - workDuration = WorkDuration.createFromMinutes(ONE_HOUR_IN_MINUTES, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(0); - assertThat(workDuration.hours()).isEqualTo(1); - assertThat(workDuration.minutes()).isEqualTo(0); - - workDuration = WorkDuration.createFromMinutes(ONE_DAY_IN_MINUTES, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(1); - assertThat(workDuration.hours()).isEqualTo(0); - assertThat(workDuration.minutes()).isEqualTo(0); - } - - @Test - public void create_from_working_long() throws Exception { - // 1 minute - WorkDuration workDuration = WorkDuration.createFromLong(1L, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(0); - assertThat(workDuration.hours()).isEqualTo(0); - assertThat(workDuration.minutes()).isEqualTo(1); - - // 1 hour - workDuration = WorkDuration.createFromLong(100L, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(0); - assertThat(workDuration.hours()).isEqualTo(1); - assertThat(workDuration.minutes()).isEqualTo(0); - - // 1 day - workDuration = WorkDuration.createFromLong(10000L, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(1); - assertThat(workDuration.hours()).isEqualTo(0); - assertThat(workDuration.minutes()).isEqualTo(0); - } - - @Test - public void convert_to_seconds() throws Exception { - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_MINUTE); - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_HOUR_IN_MINUTES); - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_DAY_IN_MINUTES); - } - - @Test - public void convert_to_working_days() throws Exception { - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d / 60d / 8d); - assertThat(WorkDuration.createFromValueAndUnit(240, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toWorkingDays()).isEqualTo(0.5); - assertThat(WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(0.5); - assertThat(WorkDuration.createFromValueAndUnit(8, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(1d); - assertThat(WorkDuration.createFromValueAndUnit(16, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d); - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d); - } - - @Test - public void convert_to_working_long() throws Exception { - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toLong()).isEqualTo(2l); - assertThat(WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(400l); - assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(10200l); - assertThat(WorkDuration.createFromValueAndUnit(8, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(10000l); - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toLong()).isEqualTo(20000l); - } - - @Test - public void add() throws Exception { - // 4h + 5h = 1d 1h - WorkDuration result = WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).add(WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY)); - assertThat(result.days()).isEqualTo(1); - assertThat(result.hours()).isEqualTo(1); - assertThat(result.minutes()).isEqualTo(0); - assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); - - // 40 m + 30m = 1h 10m - result = WorkDuration.createFromValueAndUnit(40, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)); - assertThat(result.days()).isEqualTo(0); - assertThat(result.hours()).isEqualTo(1); - assertThat(result.minutes()).isEqualTo(10); - assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); - - // 10 m + 20m = 30m - assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add( - WorkDuration.createFromValueAndUnit(20, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY) - ).minutes()).isEqualTo(30); - - assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add(null).minutes()).isEqualTo(10); - } - - @Test - public void subtract() throws Exception { - // 1d 1h - 5h = 4h - WorkDuration result = WorkDuration.create(1, 1, 0, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY)); - assertThat(result.days()).isEqualTo(0); - assertThat(result.hours()).isEqualTo(4); - assertThat(result.minutes()).isEqualTo(0); - assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); - - // 1h 10m - 30m = 40m - result = WorkDuration.create(0, 1, 10, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)); - assertThat(result.days()).isEqualTo(0); - assertThat(result.hours()).isEqualTo(0); - assertThat(result.minutes()).isEqualTo(40); - assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); - - // 30m - 20m = 10m - assertThat(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(20, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)) - .minutes()).isEqualTo(10); - - assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).subtract(null).minutes()).isEqualTo(10); - } - - @Test - public void multiply() throws Exception { - // 5h * 2 = 1d 2h - WorkDuration result = WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).multiply(2); - assertThat(result.days()).isEqualTo(1); - assertThat(result.hours()).isEqualTo(2); - assertThat(result.minutes()).isEqualTo(0); - assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); - } - - @Test - public void test_equals_and_hashcode() throws Exception { - WorkDuration duration = WorkDuration.createFromLong(28800, HOURS_IN_DAY); - WorkDuration durationWithSameValue = WorkDuration.createFromLong(28800, HOURS_IN_DAY); - WorkDuration durationWithDifferentValue = WorkDuration.createFromLong(14400, HOURS_IN_DAY); - - assertThat(duration).isEqualTo(duration); - assertThat(durationWithSameValue).isEqualTo(duration); - assertThat(durationWithDifferentValue).isNotEqualTo(duration); - assertThat(duration).isNotEqualTo(null); - - assertThat(duration.hashCode()).isEqualTo(duration.hashCode()); - assertThat(durationWithSameValue.hashCode()).isEqualTo(duration.hashCode()); - assertThat(durationWithDifferentValue.hashCode()).isNotEqualTo(duration.hashCode()); - } - - @Test - public void test_toString() throws Exception { - assertThat(WorkDuration.createFromLong(28800, HOURS_IN_DAY).toString()).isNotNull(); - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/WorkDurationFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/WorkDurationFactoryTest.java new file mode 100644 index 00000000000..735ab46fc8c --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/WorkDurationFactoryTest.java @@ -0,0 +1,67 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.utils.internal; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.CoreProperties; +import org.sonar.api.config.Settings; + +import static org.fest.assertions.Assertions.assertThat; + +public class WorkDurationFactoryTest { + + WorkDurationFactory factory; + + static final int HOURS_IN_DAY = 8; + static final Long ONE_HOUR_IN_MINUTES = 1L * 60; + + @Before + public void setUp() throws Exception { + Settings settings = new Settings(); + settings.setProperty(CoreProperties.HOURS_IN_DAY, HOURS_IN_DAY); + factory = new WorkDurationFactory(settings); + } + + @Test + public void create_from_working_value() throws Exception { + // 1 working day -> 8 hours + assertThat(factory.createFromWorkingValue(1, WorkDuration.UNIT.DAYS).toMinutes()).isEqualTo(8L * ONE_HOUR_IN_MINUTES); + // 8 hours + assertThat(factory.createFromWorkingValue(8, WorkDuration.UNIT.HOURS).toMinutes()).isEqualTo(8L * ONE_HOUR_IN_MINUTES); + } + + @Test + public void create_from_working_long() throws Exception { + WorkDuration workDuration = factory.createFromWorkingLong(1l); + assertThat(workDuration.days()).isEqualTo(0); + assertThat(workDuration.hours()).isEqualTo(0); + assertThat(workDuration.minutes()).isEqualTo(1); + } + + @Test + public void create_from_seconds() throws Exception { + WorkDuration workDuration = factory.createFromMinutes(8L * ONE_HOUR_IN_MINUTES); + assertThat(workDuration.days()).isEqualTo(1); + assertThat(workDuration.hours()).isEqualTo(0); + assertThat(workDuration.minutes()).isEqualTo(0); + } +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/WorkDurationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/WorkDurationTest.java new file mode 100644 index 00000000000..c52aac96b8e --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/WorkDurationTest.java @@ -0,0 +1,201 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 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.api.utils.internal; + +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class WorkDurationTest { + + static final int HOURS_IN_DAY = 8; + + static final Long ONE_MINUTE = 1L; + static final Long ONE_HOUR_IN_MINUTES = ONE_MINUTE * 60; + static final Long ONE_DAY_IN_MINUTES = ONE_HOUR_IN_MINUTES * HOURS_IN_DAY; + + @Test + public void create_from_days_hours_minutes() throws Exception { + WorkDuration workDuration = WorkDuration.create(1, 1, 1, HOURS_IN_DAY); + assertThat(workDuration.days()).isEqualTo(1); + assertThat(workDuration.hours()).isEqualTo(1); + assertThat(workDuration.minutes()).isEqualTo(1); + assertThat(workDuration.toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE); + assertThat(workDuration.hoursInDay()).isEqualTo(HOURS_IN_DAY); + } + + @Test + public void create_from_value_and_unit() throws Exception { + WorkDuration result = WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY); + assertThat(result.days()).isEqualTo(1); + assertThat(result.hours()).isEqualTo(0); + assertThat(result.minutes()).isEqualTo(0); + assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); + assertThat(result.toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES); + + assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES); + assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_HOUR_IN_MINUTES); + assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toMinutes()).isEqualTo(ONE_MINUTE); + } + + @Test + public void create_from_minutes() throws Exception { + WorkDuration workDuration = WorkDuration.createFromMinutes(ONE_MINUTE, HOURS_IN_DAY); + assertThat(workDuration.days()).isEqualTo(0); + assertThat(workDuration.hours()).isEqualTo(0); + assertThat(workDuration.minutes()).isEqualTo(1); + + workDuration = WorkDuration.createFromMinutes(ONE_HOUR_IN_MINUTES, HOURS_IN_DAY); + assertThat(workDuration.days()).isEqualTo(0); + assertThat(workDuration.hours()).isEqualTo(1); + assertThat(workDuration.minutes()).isEqualTo(0); + + workDuration = WorkDuration.createFromMinutes(ONE_DAY_IN_MINUTES, HOURS_IN_DAY); + assertThat(workDuration.days()).isEqualTo(1); + assertThat(workDuration.hours()).isEqualTo(0); + assertThat(workDuration.minutes()).isEqualTo(0); + } + + @Test + public void create_from_working_long() throws Exception { + // 1 minute + WorkDuration workDuration = WorkDuration.createFromLong(1L, HOURS_IN_DAY); + assertThat(workDuration.days()).isEqualTo(0); + assertThat(workDuration.hours()).isEqualTo(0); + assertThat(workDuration.minutes()).isEqualTo(1); + + // 1 hour + workDuration = WorkDuration.createFromLong(100L, HOURS_IN_DAY); + assertThat(workDuration.days()).isEqualTo(0); + assertThat(workDuration.hours()).isEqualTo(1); + assertThat(workDuration.minutes()).isEqualTo(0); + + // 1 day + workDuration = WorkDuration.createFromLong(10000L, HOURS_IN_DAY); + assertThat(workDuration.days()).isEqualTo(1); + assertThat(workDuration.hours()).isEqualTo(0); + assertThat(workDuration.minutes()).isEqualTo(0); + } + + @Test + public void convert_to_seconds() throws Exception { + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_MINUTE); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_HOUR_IN_MINUTES); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toMinutes()).isEqualTo(2L * ONE_DAY_IN_MINUTES); + } + + @Test + public void convert_to_working_days() throws Exception { + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d / 60d / 8d); + assertThat(WorkDuration.createFromValueAndUnit(240, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toWorkingDays()).isEqualTo(0.5); + assertThat(WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(0.5); + assertThat(WorkDuration.createFromValueAndUnit(8, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(1d); + assertThat(WorkDuration.createFromValueAndUnit(16, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d); + } + + @Test + public void convert_to_working_long() throws Exception { + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toLong()).isEqualTo(2l); + assertThat(WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(400l); + assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(10200l); + assertThat(WorkDuration.createFromValueAndUnit(8, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(10000l); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toLong()).isEqualTo(20000l); + } + + @Test + public void add() throws Exception { + // 4h + 5h = 1d 1h + WorkDuration result = WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).add(WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY)); + assertThat(result.days()).isEqualTo(1); + assertThat(result.hours()).isEqualTo(1); + assertThat(result.minutes()).isEqualTo(0); + assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); + + // 40 m + 30m = 1h 10m + result = WorkDuration.createFromValueAndUnit(40, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)); + assertThat(result.days()).isEqualTo(0); + assertThat(result.hours()).isEqualTo(1); + assertThat(result.minutes()).isEqualTo(10); + assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); + + // 10 m + 20m = 30m + assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add( + WorkDuration.createFromValueAndUnit(20, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY) + ).minutes()).isEqualTo(30); + + assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add(null).minutes()).isEqualTo(10); + } + + @Test + public void subtract() throws Exception { + // 1d 1h - 5h = 4h + WorkDuration result = WorkDuration.create(1, 1, 0, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY)); + assertThat(result.days()).isEqualTo(0); + assertThat(result.hours()).isEqualTo(4); + assertThat(result.minutes()).isEqualTo(0); + assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); + + // 1h 10m - 30m = 40m + result = WorkDuration.create(0, 1, 10, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)); + assertThat(result.days()).isEqualTo(0); + assertThat(result.hours()).isEqualTo(0); + assertThat(result.minutes()).isEqualTo(40); + assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); + + // 30m - 20m = 10m + assertThat(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(20, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)) + .minutes()).isEqualTo(10); + + assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).subtract(null).minutes()).isEqualTo(10); + } + + @Test + public void multiply() throws Exception { + // 5h * 2 = 1d 2h + WorkDuration result = WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).multiply(2); + assertThat(result.days()).isEqualTo(1); + assertThat(result.hours()).isEqualTo(2); + assertThat(result.minutes()).isEqualTo(0); + assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); + } + + @Test + public void test_equals_and_hashcode() throws Exception { + WorkDuration duration = WorkDuration.createFromLong(28800, HOURS_IN_DAY); + WorkDuration durationWithSameValue = WorkDuration.createFromLong(28800, HOURS_IN_DAY); + WorkDuration durationWithDifferentValue = WorkDuration.createFromLong(14400, HOURS_IN_DAY); + + assertThat(duration).isEqualTo(duration); + assertThat(durationWithSameValue).isEqualTo(duration); + assertThat(durationWithDifferentValue).isNotEqualTo(duration); + assertThat(duration).isNotEqualTo(null); + + assertThat(duration.hashCode()).isEqualTo(duration.hashCode()); + assertThat(durationWithSameValue.hashCode()).isEqualTo(duration.hashCode()); + assertThat(durationWithDifferentValue.hashCode()).isNotEqualTo(duration.hashCode()); + } + + @Test + public void test_toString() throws Exception { + assertThat(WorkDuration.createFromLong(28800, HOURS_IN_DAY).toString()).isNotNull(); + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 17ab1030baa..1fb708fb730 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -35,8 +35,8 @@ import org.sonar.api.rules.XMLRuleParser; import org.sonar.api.utils.HttpDownloader; import org.sonar.api.utils.TimeProfiler; import org.sonar.api.utils.UriReader; -import org.sonar.api.utils.WorkDurationFactory; import org.sonar.api.utils.internal.TempFolderCleaner; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.core.component.SnapshotPerspectives; import org.sonar.core.component.db.ComponentDao; import org.sonar.core.config.Logback; diff --git a/sonar-server/src/main/java/org/sonar/server/technicaldebt/DebtService.java b/sonar-server/src/main/java/org/sonar/server/technicaldebt/DebtService.java index 540193cd19f..d7c838eccfa 100644 --- a/sonar-server/src/main/java/org/sonar/server/technicaldebt/DebtService.java +++ b/sonar-server/src/main/java/org/sonar/server/technicaldebt/DebtService.java @@ -22,8 +22,8 @@ package org.sonar.server.technicaldebt; import org.sonar.api.ServerComponent; import org.sonar.api.technicaldebt.server.Characteristic; -import org.sonar.api.utils.WorkDuration; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDuration; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager; import javax.annotation.CheckForNull; diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtServiceTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtServiceTest.java index d5292636a74..f60b78dae01 100644 --- a/sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtServiceTest.java @@ -25,8 +25,8 @@ import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.api.technicaldebt.server.Characteristic; import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic; -import org.sonar.api.utils.WorkDuration; -import org.sonar.api.utils.WorkDurationFactory; +import org.sonar.api.utils.internal.WorkDuration; +import org.sonar.api.utils.internal.WorkDurationFactory; import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager; import java.util.List; -- cgit v1.2.3