*
* TODO must have syntax highlighting
* TODO must have duplications
- * TODO must have issues with SQALE characteristic and debt
- * TODO must have rules with characteristic
+ * TODO must have issues with debt
* TODO must have tests
* TODO must have coverage
*/
/**
* @since 4.3
+ * @deprecated since 5.1 debt model will soon be unavailable on batch side
*/
+@Deprecated
public interface DebtCharacteristic {
String key();
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.debt.internal;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.batch.debt.DebtCharacteristic;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Date;
-
-public class DefaultDebtCharacteristic implements DebtCharacteristic {
-
- private Integer id;
- private String key;
- private String name;
- private Integer order;
- private Integer parentId;
- private Date createdAt;
- private Date updatedAt;
-
- public Integer id() {
- return id;
- }
-
- public DefaultDebtCharacteristic setId(Integer id) {
- this.id = id;
- return this;
- }
-
- @Override
- public String key() {
- return key;
- }
-
- public DefaultDebtCharacteristic setKey(String key) {
- this.key = key;
- return this;
- }
-
- @Override
- public String name() {
- return name;
- }
-
- public DefaultDebtCharacteristic setName(String name) {
- this.name = name;
- return this;
- }
-
- @Override
- @CheckForNull
- public Integer order() {
- return order;
- }
-
- public DefaultDebtCharacteristic setOrder(@Nullable Integer order) {
- this.order = order;
- return this;
- }
-
- @CheckForNull
- public Integer parentId() {
- return parentId;
- }
-
- public DefaultDebtCharacteristic setParentId(@Nullable Integer parentId) {
- this.parentId = parentId;
- return this;
- }
-
- public Date createdAt() {
- return createdAt;
- }
-
- public DefaultDebtCharacteristic setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- @CheckForNull
- public Date updatedAt() {
- return updatedAt;
- }
-
- public DefaultDebtCharacteristic setUpdatedAt(@Nullable Date updatedAt) {
- this.updatedAt = updatedAt;
- return this;
- }
-
- @Override
- public boolean isSub(){
- return parentId != null;
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
- }
-}
*/
package org.sonar.api.batch.debt.internal;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Multimap;
+import java.util.Collections;
import java.util.List;
import javax.annotation.CheckForNull;
import org.sonar.api.batch.debt.DebtCharacteristic;
import org.sonar.api.batch.debt.DebtModel;
-import static com.google.common.collect.Lists.newArrayList;
-
public class DefaultDebtModel implements DebtModel {
- /**
- * Sub-characteristics list can be retrieved with the characteristic key
- * Characteristics list can be retrieved by with the null key
- */
- private Multimap<String, DebtCharacteristic> characteristicsByKey;
-
- public DefaultDebtModel() {
- characteristicsByKey = ArrayListMultimap.create();
- }
-
- public DefaultDebtModel addCharacteristic(DebtCharacteristic characteristic) {
- characteristicsByKey.put(null, characteristic);
- return this;
- }
-
-
- public DefaultDebtModel addSubCharacteristic(DebtCharacteristic subCharacteristic, String characteristicKey) {
- characteristicsByKey.put(characteristicKey, subCharacteristic);
- return this;
- }
-
@Override
public List<DebtCharacteristic> characteristics() {
- return newArrayList(characteristicsByKey.get(null));
+ return Collections.emptyList();
}
@Override
public List<DebtCharacteristic> subCharacteristics(String characteristicKey) {
- return newArrayList(characteristicsByKey.get(characteristicKey));
+ return Collections.emptyList();
}
@Override
public List<DebtCharacteristic> allCharacteristics() {
- return newArrayList(characteristicsByKey.values());
+ return Collections.emptyList();
}
@Override
@CheckForNull
public DebtCharacteristic characteristicByKey(final String key) {
- return Iterables.find(characteristicsByKey.values(), new MatchDebtCharacteristicKey(key), null);
+ return null;
}
@CheckForNull
public DebtCharacteristic characteristicById(int id) {
- return Iterables.find(characteristicsByKey.values(), new MatchDebtCharacteristicId(id), null);
- }
-
- private static class MatchDebtCharacteristicKey implements Predicate<DebtCharacteristic> {
- private final String key;
-
- public MatchDebtCharacteristicKey(String key) {
- this.key = key;
- }
-
- @Override
- public boolean apply(DebtCharacteristic input) {
- return key.equals(input.key());
- }
- }
-
- private static class MatchDebtCharacteristicId implements Predicate<DebtCharacteristic> {
- private final int id;
-
- public MatchDebtCharacteristicId(int id) {
- this.id = id;
- }
-
- @Override
- public boolean apply(DebtCharacteristic input) {
- return id == ((DefaultDebtCharacteristic) input).id();
- }
+ return null;
}
}
import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.math.NumberUtils;
-import org.sonar.api.technicaldebt.batch.Characteristic;
-import org.sonar.api.technicaldebt.batch.Requirement;
/**
* A class to handle measures.
protected Double variation4;
protected Double variation5;
protected String url;
- protected Characteristic characteristic;
- protected Requirement requirement;
protected Integer personId;
protected PersistenceMode persistenceMode = PersistenceMode.FULL;
private boolean fromCore;
return this;
}
- /**
- * @since 4.1
- */
- @CheckForNull
- public final Characteristic getCharacteristic() {
- return characteristic;
- }
-
- /**
- * @since 4.1
- */
- public final Measure<G> setCharacteristic(@Nullable Characteristic characteristic) {
- this.characteristic = characteristic;
- return this;
- }
-
- /**
- * @since 4.1
- * @deprecated since 4.3.
- */
- @Deprecated
- @CheckForNull
- public final Requirement getRequirement() {
- return requirement;
- }
-
- /**
- * @since 4.1
- * @deprecated since 4.3
- */
- @Deprecated
- public final Measure<G> setRequirement(@Nullable Requirement requirement) {
- this.requirement = requirement;
- return this;
- }
-
/**
* @since 2.14
*/
if (metricKey != null ? !metricKey.equals(measure.metricKey) : (measure.metricKey != null)) {
return false;
}
- if (characteristic != null ? !characteristic.equals(measure.characteristic) : (measure.characteristic != null)) {
- return false;
- }
return !(personId != null ? !personId.equals(measure.personId) : (measure.personId != null));
}
@Override
public int hashCode() {
int result = metricKey != null ? metricKey.hashCode() : 0;
- result = 31 * result + (characteristic != null ? characteristic.hashCode() : 0);
result = 31 * result + (personId != null ? personId.hashCode() : 0);
return result;
}
*/
package org.sonar.api.measures;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.technicaldebt.batch.Characteristic;
-import org.sonar.api.technicaldebt.batch.Requirement;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.Rule;
/**
* @since 1.10
for (Measure measure : measures) {
if (measure.getClass().equals(Measure.class) &&
measure.getMetricKey().equals(metricKey) &&
- measure.getCharacteristic() == null &&
measure.getPersonId() == null) {
return measure;
}
};
}
- public static MeasuresFilter<Measure> characteristic(final Metric metric, final Characteristic characteristic) {
- return new MetricFilter<Measure>(metric) {
-
- @Override
- public Measure filter(Collection<Measure> measures) {
- if (measures == null) {
- return null;
- }
- for (Measure measure : measures) {
- if (measure.getClass().equals(Measure.class) &&
- measure.getMetric().equals(metric) &&
- measure.getPersonId() == null &&
- isSameCharacteristic(measure, characteristic)) {
- return measure;
- }
- }
- return null;
- }
- };
- }
-
- private static boolean isSameCharacteristic(Measure measure, final Characteristic characteristic) {
- Characteristic measureCharacteristic = measure.getCharacteristic();
- return measureCharacteristic != null &&
- measureCharacteristic.equals(characteristic);
- }
-
- /**
- * @deprecated since 4.3
- */
- @Deprecated
- public static MeasuresFilter<Measure> requirement(final Metric metric, final Requirement requirement) {
- return new MetricFilter<Measure>(metric) {
-
- @Override
- public Measure filter(Collection<Measure> measures) {
- if (measures == null) {
- return null;
- }
- for (Measure measure : measures) {
- if (measure.getClass().equals(Measure.class) &&
- measure.getMetric().equals(metric) &&
- measure.getPersonId() == null &&
- isSameRequirement(measure, requirement)) {
- return measure;
- }
- }
- return null;
- }
- };
- }
-
- private static boolean isSameRequirement(Measure measure, final Requirement requirement) {
- Requirement measureRequirement = measure.getRequirement();
- return measureRequirement != null &&
- measureRequirement.equals(requirement);
- }
-
/**
* @since 2.0
*/
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.batch;
-
-import javax.annotation.CheckForNull;
-
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-
-/**
- * @since 4.1
- * @deprecated since 4.3
- */
-@Deprecated
-public interface Characteristic extends Serializable {
-
- Integer id();
-
- String key();
-
- String name();
-
- Integer order();
-
- @CheckForNull
- Characteristic parent();
-
- List<? extends Characteristic> children();
-
- boolean isRoot();
-
- Date createdAt();
-
- Date updatedAt();
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.batch;
-
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.utils.WorkUnit;
-import org.sonar.api.utils.internal.WorkDuration;
-
-import java.io.Serializable;
-import java.util.Date;
-
-/**
- * @since 4.1
- * @deprecated since 4.3
- */
-@Deprecated
-public interface Requirement extends Serializable {
-
- Integer id();
-
- RuleKey ruleKey();
-
- Characteristic characteristic();
-
- Characteristic rootCharacteristic();
-
- String function();
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- WorkUnit factor();
-
- /**
- * @since 4.2
- */
- int factorValue();
-
- /**
- * @since 4.2
- */
- WorkDuration.UNIT factorUnit();
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- WorkUnit offset();
-
- /**
- * @since 4.2
- */
- int offsetValue();
-
- /**
- * @since 4.2
- */
- WorkDuration.UNIT offsetUnit();
-
- Date createdAt();
-
- Date updatedAt();
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.batch.internal;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.technicaldebt.batch.Characteristic;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Date;
-import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-/**
- * @deprecated since 4.3
- */
-@Deprecated
-public class DefaultCharacteristic implements Characteristic {
-
- private Integer id;
- private String key;
- private String name;
- private Integer order;
- private DefaultCharacteristic parent;
- private DefaultCharacteristic root;
- private List<DefaultCharacteristic> children;
- private List<DefaultRequirement> requirements;
-
- private Date createdAt;
- private Date updatedAt;
-
- public DefaultCharacteristic() {
- this.children = newArrayList();
- this.requirements = newArrayList();
- }
-
- @Override
- public Integer id() {
- return id;
- }
-
- public DefaultCharacteristic setId(Integer id) {
- this.id = id;
- return this;
- }
-
- @Override
- public String key() {
- return key;
- }
-
- public DefaultCharacteristic setKey(String key) {
- this.key = StringUtils.trimToNull(key);
- return this;
- }
-
- @Override
- public String name() {
- return name;
- }
-
- public DefaultCharacteristic setName(String name) {
- this.name = name;
- return this;
- }
-
- public DefaultCharacteristic setName(String s, boolean asKey) {
- this.name = StringUtils.trimToNull(s);
- if (asKey) {
- this.key = StringUtils.upperCase(this.name);
- this.key = StringUtils.replaceChars(this.key, ' ', '_');
- }
- return this;
- }
-
- @Override
- @CheckForNull
- public Integer order() {
- return order;
- }
-
- public DefaultCharacteristic setOrder(@Nullable Integer order) {
- this.order = order;
- return this;
- }
-
- @Override
- @CheckForNull
- public DefaultCharacteristic parent() {
- return parent;
- }
-
- public DefaultCharacteristic setParent(@Nullable DefaultCharacteristic parent) {
- if (parent != null) {
- this.parent = parent;
- parent.addChild(this);
- }
- return this;
- }
-
- @CheckForNull
- public DefaultCharacteristic root() {
- return root;
- }
-
- public DefaultCharacteristic setRoot(@Nullable DefaultCharacteristic root) {
- this.root = root;
- return this;
- }
-
- @Override
- public List<DefaultCharacteristic> children() {
- return children;
- }
-
- private DefaultCharacteristic addChild(DefaultCharacteristic child) {
- this.children.add(child);
- return this;
- }
-
- public List<DefaultRequirement> requirements() {
- return requirements;
- }
-
- public DefaultCharacteristic addRequirement(DefaultRequirement requirement) {
- this.requirements.add(requirement);
- return this;
- }
-
- @Override
- public boolean isRoot() {
- return parent == null;
- }
-
- @Override
- public Date createdAt() {
- return createdAt;
- }
-
- public DefaultCharacteristic setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- @Override
- @CheckForNull
- public Date updatedAt() {
- return updatedAt;
- }
-
- public DefaultCharacteristic setUpdatedAt(@Nullable Date updatedAt) {
- this.updatedAt = updatedAt;
- return this;
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- DefaultCharacteristic that = (DefaultCharacteristic) o;
- return key.equals(that.key);
- }
-
- @Override
- public int hashCode() {
- return key.hashCode();
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.batch.internal;
-
-import java.util.Date;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-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.batch.Requirement;
-import org.sonar.api.utils.WorkUnit;
-import org.sonar.api.utils.internal.WorkDuration;
-
-/**
- * @deprecated since 4.3
- */
-@Deprecated
-public class DefaultRequirement implements Requirement {
-
- public static final String FUNCTION_LINEAR = "linear";
- public static final String FUNCTION_LINEAR_WITH_OFFSET = "linear_offset";
- public static final String CONSTANT_ISSUE = "constant_issue";
-
- private Integer id;
- private RuleKey ruleKey;
- private DefaultCharacteristic characteristic;
- private DefaultCharacteristic rootCharacteristic;
-
- private String function;
- private int factorValue;
- private WorkDuration.UNIT factorUnit;
- private int offsetValue;
- private WorkDuration.UNIT offsetUnit;
-
- private Date createdAt;
- private Date updatedAt;
-
- @Override
- public Integer id() {
- return id;
- }
-
- public DefaultRequirement setId(Integer id) {
- this.id = id;
- return this;
- }
-
- @Override
- public RuleKey ruleKey() {
- return ruleKey;
- }
-
- public DefaultRequirement setRuleKey(RuleKey ruleKey) {
- this.ruleKey = ruleKey;
- return this;
- }
-
- @Override
- public DefaultCharacteristic characteristic() {
- return characteristic;
- }
-
- public DefaultRequirement setCharacteristic(DefaultCharacteristic characteristic) {
- this.characteristic = characteristic;
- this.characteristic.addRequirement(this);
- return this;
- }
-
- @Override
- public DefaultCharacteristic rootCharacteristic() {
- return rootCharacteristic;
- }
-
- public DefaultRequirement setRootCharacteristic(DefaultCharacteristic rootCharacteristic) {
- this.rootCharacteristic = rootCharacteristic;
- return this;
- }
-
- @Override
- public String function() {
- return function;
- }
-
- public DefaultRequirement setFunction(String function) {
- this.function = function;
- return this;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Override
- @Deprecated
- public WorkUnit factor() {
- return WorkUnit.create((double) factorValue, fromUnit(factorUnit));
- }
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- public DefaultRequirement setFactor(WorkUnit factor) {
- this.factorValue = (int) factor.getValue();
- this.factorUnit = toUnit(factor.getUnit());
- return this;
- }
-
- @Override
- public int factorValue() {
- return factorValue;
- }
-
- public DefaultRequirement setFactorValue(int factorValue) {
- this.factorValue = factorValue;
- return this;
- }
-
- @Override
- @CheckForNull
- public WorkDuration.UNIT factorUnit() {
- return factorUnit;
- }
-
- public DefaultRequirement setFactorUnit(@Nullable WorkDuration.UNIT factorUnit) {
- this.factorUnit = factorUnit;
- return this;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Override
- @Deprecated
- public WorkUnit offset() {
- return WorkUnit.create((double) offsetValue, fromUnit(offsetUnit));
- }
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- public DefaultRequirement setOffset(WorkUnit offset) {
- this.offsetValue = (int) offset.getValue();
- this.offsetUnit = toUnit(offset.getUnit());
- return this;
- }
-
- @Override
- public int offsetValue() {
- return offsetValue;
- }
-
- public DefaultRequirement setOffsetValue(int offsetValue) {
- this.offsetValue = offsetValue;
- return this;
- }
-
- @Override
- @CheckForNull
- public WorkDuration.UNIT offsetUnit() {
- return offsetUnit;
- }
-
- public DefaultRequirement setOffsetUnit(@Nullable WorkDuration.UNIT offsetUnit) {
- this.offsetUnit = offsetUnit;
- return this;
- }
-
- @Override
- public Date createdAt() {
- return createdAt;
- }
-
- public DefaultRequirement setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- @Override
- public Date updatedAt() {
- return updatedAt;
- }
-
- public DefaultRequirement setUpdatedAt(Date updatedAt) {
- this.updatedAt = updatedAt;
- return this;
- }
-
- public static WorkDuration.UNIT toUnit(String requirementUnit) {
- if (WorkUnit.DAYS.equals(requirementUnit)) {
- return WorkDuration.UNIT.DAYS;
- } else if (WorkUnit.HOURS.equals(requirementUnit)) {
- return WorkDuration.UNIT.HOURS;
- } else if (WorkUnit.MINUTES.equals(requirementUnit)) {
- return WorkDuration.UNIT.MINUTES;
- }
- throw new IllegalStateException("Invalid unit : " + requirementUnit);
- }
-
- private static String fromUnit(WorkDuration.UNIT unit) {
- if (WorkDuration.UNIT.DAYS.equals(unit)) {
- return WorkUnit.DAYS;
- } else if (WorkDuration.UNIT.HOURS.equals(unit)) {
- return WorkUnit.HOURS;
- } else if (WorkDuration.UNIT.MINUTES.equals(unit)) {
- return WorkUnit.MINUTES;
- }
- throw new IllegalStateException("Invalid unit : " + unit);
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- DefaultRequirement that = (DefaultRequirement) o;
-
- if (!characteristic.equals(that.characteristic)) {
- return false;
- }
- return ruleKey.equals(that.ruleKey);
-
- }
-
- @Override
- public int hashCode() {
- int result = ruleKey.hashCode();
- result = 31 * result + characteristic.hashCode();
- return result;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.api.technicaldebt.batch.internal;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.api.technicaldebt.batch;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.server;
-
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.utils.WorkUnit;
-import org.sonar.api.utils.internal.WorkDuration;
-
-import javax.annotation.CheckForNull;
-
-/**
- * @since 4.1
- * @deprecated since 4.3.
- */
-@Deprecated
-public interface Characteristic {
-
- Integer id();
-
- String key();
-
- String name();
-
- Integer order();
-
- @CheckForNull
- Integer parentId();
-
- /**
- * @deprecated since 4.3. return null
- */
- @Deprecated
- @CheckForNull
- Integer rootId();
-
- /**
- * @deprecated since 4.3. return null
- */
- @Deprecated
- RuleKey ruleKey();
-
- /**
- * @deprecated since 4.3. return null
- */
- @Deprecated
- String function();
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- @CheckForNull
- WorkUnit factor();
-
- /**
- * @since 4.2
- */
- @CheckForNull
- Integer factorValue();
-
- /**
- * @since 4.2
- */
- @CheckForNull
- WorkDuration.UNIT factorUnit();
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- @CheckForNull
- WorkUnit offset();
-
- /**
- * @since 4.2
- */
- @CheckForNull
- Integer offsetValue();
-
- /**
- * @since 4.2
- */
- @CheckForNull
- WorkDuration.UNIT offsetUnit();
-
- boolean isRoot();
-
- /**
- * @deprecated since 4.3
- */
- @Deprecated
- boolean isRequirement();
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.server.internal;
-
-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.WorkUnit;
-import org.sonar.api.utils.internal.WorkDuration;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-/**
- * @since 4.1
- * @deprecated since 4.3.
- */
-@Deprecated
-public class DefaultCharacteristic implements Characteristic {
-
- private Integer id;
- private String key;
- private String name;
- private Integer order;
- private Integer parentId;
- private Integer rootId;
- private RuleKey ruleKey;
- private String function;
- private Integer factorValue;
- private WorkDuration.UNIT factorUnit;
- private Integer offsetValue;
- private WorkDuration.UNIT offsetUnit;
-
- @Override
- public Integer id() {
- return id;
- }
-
- public DefaultCharacteristic setId(Integer id) {
- this.id = id;
- return this;
- }
-
- @Override
- @CheckForNull
- public String key() {
- return key;
- }
-
- public DefaultCharacteristic setKey(@Nullable String key) {
- this.key = key;
- return this;
- }
-
- @Override
- @CheckForNull
- public String name() {
- return name;
- }
-
- public DefaultCharacteristic setName(@Nullable String name) {
- this.name = name;
- return this;
- }
-
- @Override
- @CheckForNull
- public Integer order() {
- return order;
- }
-
- public DefaultCharacteristic setOrder(@Nullable Integer order) {
- this.order = order;
- return this;
- }
-
- @Override
- @CheckForNull
- public Integer parentId() {
- return parentId;
- }
-
- public DefaultCharacteristic setParentId(@Nullable Integer parentId) {
- this.parentId = parentId;
- return this;
- }
-
- @Override
- @CheckForNull
- public Integer rootId() {
- return rootId;
- }
-
- public DefaultCharacteristic setRootId(@Nullable Integer rootId) {
- this.rootId = rootId;
- return this;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Override
- @Deprecated
- @CheckForNull
- public RuleKey ruleKey() {
- return ruleKey;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- public DefaultCharacteristic setRuleKey(@Nullable RuleKey ruleKey) {
- this.ruleKey = ruleKey;
- return this;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Override
- @Deprecated
- @CheckForNull
- public String function() {
- return function;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- public DefaultCharacteristic setFunction(@Nullable String function) {
- this.function = function;
- return this;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Override
- @Deprecated
- @CheckForNull
- public WorkUnit factor() {
- if (factorValue != null && factorUnit != null) {
- return WorkUnit.create((double) factorValue, fromUnit(factorUnit));
- }
- return null;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- public DefaultCharacteristic setFactor(@Nullable WorkUnit factor) {
- if (factor != null) {
- this.factorValue = (int) factor.getValue();
- this.factorUnit = toUnit(factor.getUnit());
- }
- return this;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Override
- @Deprecated
- @CheckForNull
- public Integer factorValue() {
- return factorValue;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Deprecated
- public DefaultCharacteristic setFactorValue(@Nullable Integer factorValue) {
- this.factorValue = factorValue;
- return this;
- }
-
- @Override
- @CheckForNull
- public WorkDuration.UNIT factorUnit() {
- return factorUnit;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Deprecated
- public DefaultCharacteristic setFactorUnit(@Nullable WorkDuration.UNIT factorUnit) {
- this.factorUnit = factorUnit;
- return this;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Override
- @Deprecated
- public WorkUnit offset() {
- if (offsetValue != null && offsetUnit != null) {
- return WorkUnit.create((double) offsetValue, fromUnit(offsetUnit));
- }
- return null;
- }
-
- /**
- * @deprecated since 4.2
- */
- @Deprecated
- public DefaultCharacteristic setOffset(@Nullable WorkUnit offset) {
- if (offset != null) {
- this.offsetValue = (int) offset.getValue();
- this.offsetUnit = toUnit(offset.getUnit());
- }
- return this;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Override
- @Deprecated
- @CheckForNull
- public Integer offsetValue() {
- return offsetValue;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Deprecated
- public DefaultCharacteristic setOffsetValue(@Nullable Integer offsetValue) {
- this.offsetValue = offsetValue;
- return this;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Override
- @Deprecated
- @CheckForNull
- public WorkDuration.UNIT offsetUnit() {
- return offsetUnit;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Deprecated
- public DefaultCharacteristic setOffsetUnit(@Nullable WorkDuration.UNIT offsetUnit) {
- this.offsetUnit = offsetUnit;
- return this;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Deprecated
- public static WorkDuration.UNIT toUnit(@Nullable String requirementUnit) {
- if (requirementUnit != null) {
- if (WorkUnit.DAYS.equals(requirementUnit)) {
- return WorkDuration.UNIT.DAYS;
- } else if (WorkUnit.HOURS.equals(requirementUnit)) {
- return WorkDuration.UNIT.HOURS;
- } else if (WorkUnit.MINUTES.equals(requirementUnit)) {
- return WorkDuration.UNIT.MINUTES;
- }
- throw new IllegalStateException("Invalid unit : " + requirementUnit);
- }
- return null;
- }
-
- private static String fromUnit(WorkDuration.UNIT unit) {
- if (WorkDuration.UNIT.DAYS.equals(unit)) {
- return WorkUnit.DAYS;
- } else if (WorkDuration.UNIT.HOURS.equals(unit)) {
- return WorkUnit.HOURS;
- } else if (WorkDuration.UNIT.MINUTES.equals(unit)) {
- return WorkUnit.MINUTES;
- }
- throw new IllegalStateException("Invalid unit : " + unit);
- }
-
- @Override
- public boolean isRoot() {
- return parentId == null;
- }
-
- /**
- * @deprecated since 4.3
- */
- @Override
- @Deprecated
- public boolean isRequirement() {
- return ruleKey != null;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- DefaultCharacteristic that = (DefaultCharacteristic) o;
-
- if ((key != null) ? !key.equals(that.key) : (that.key != null)) {
- return false;
- }
- return !((ruleKey != null) ? !ruleKey.equals(that.ruleKey) : (that.ruleKey != null));
-
- }
-
- @Override
- public int hashCode() {
- int result = (key != null) ? key.hashCode() : 0;
- result = 31 * result + ((ruleKey != null) ? ruleKey.hashCode() : 0);
- return result;
- }
-
- @Override
- public String toString() {
- return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.api.technicaldebt.server.internal;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.api.technicaldebt.server;
-
-import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.debt.internal;
-
-import org.junit.Test;
-
-import java.util.Date;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultDebtCharacteristicTest {
-
- @Test
- public void setter_and_getter_on_characteristic() {
- DefaultDebtCharacteristic debtCharacteristic = new DefaultDebtCharacteristic()
- .setId(1)
- .setKey("PORTABILITY")
- .setName("Portability")
- .setOrder(1)
- .setCreatedAt(new Date())
- .setUpdatedAt(new Date());
-
- assertThat(debtCharacteristic.id()).isEqualTo(1);
- assertThat(debtCharacteristic.key()).isEqualTo("PORTABILITY");
- assertThat(debtCharacteristic.name()).isEqualTo("Portability");
- assertThat(debtCharacteristic.order()).isEqualTo(1);
- assertThat(debtCharacteristic.parentId()).isNull();
- assertThat(debtCharacteristic.isSub()).isFalse();
- assertThat(debtCharacteristic.createdAt()).isNotNull();
- assertThat(debtCharacteristic.updatedAt()).isNotNull();
- }
-
- @Test
- public void setter_and_getter_on_sub_characteristic() {
- DefaultDebtCharacteristic debtCharacteristic = new DefaultDebtCharacteristic()
- .setId(1)
- .setKey("COMPILER")
- .setName("Compiler")
- .setParentId(2)
- .setCreatedAt(new Date())
- .setUpdatedAt(new Date());
-
- assertThat(debtCharacteristic.id()).isEqualTo(1);
- assertThat(debtCharacteristic.key()).isEqualTo("COMPILER");
- assertThat(debtCharacteristic.name()).isEqualTo("Compiler");
- assertThat(debtCharacteristic.order()).isNull();
- assertThat(debtCharacteristic.parentId()).isEqualTo(2);
- assertThat(debtCharacteristic.isSub()).isTrue();
- assertThat(debtCharacteristic.createdAt()).isNotNull();
- assertThat(debtCharacteristic.updatedAt()).isNotNull();
- }
-
- @Test
- public void to_string() {
- assertThat(new DefaultDebtCharacteristic()
- .setId(1)
- .setKey("PORTABILITY")
- .setName("Portability")
- .setOrder(1)
- .setCreatedAt(new Date())
- .setUpdatedAt(new Date())).isNotNull();
- }
-}
*/
package org.sonar.api.batch.debt.internal;
-import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultDebtModelTest {
- private DefaultDebtModel debtModel;
-
- @Before
- public void setUp() {
- debtModel = new DefaultDebtModel()
- .addCharacteristic(
- new DefaultDebtCharacteristic().setId(1)
- .setKey("MEMORY_EFFICIENCY")
- .setName("Memory use")
- .setOrder(1)
- )
- .addSubCharacteristic(
- new DefaultDebtCharacteristic().setId(2)
- .setKey("EFFICIENCY")
- .setName("Efficiency")
- .setParentId(1),
- "MEMORY_EFFICIENCY"
- );
- }
-
- @Test
- public void all_characteristics() {
- assertThat(debtModel.allCharacteristics()).hasSize(2);
- }
+ DefaultDebtModel underTest = new DefaultDebtModel();
@Test
- public void characteristics() {
- assertThat(debtModel.characteristics()).hasSize(1);
- }
-
- @Test
- public void sub_characteristics() {
- assertThat(debtModel.subCharacteristics("MEMORY_EFFICIENCY")).hasSize(1);
- }
-
- @Test
- public void characteristic_by_id() {
- DefaultDebtCharacteristic debtCharacteristic = (DefaultDebtCharacteristic) debtModel.characteristicById(1);
- assertThat(debtCharacteristic).isNotNull();
- assertThat(debtCharacteristic.id()).isEqualTo(1);
- assertThat(debtCharacteristic.key()).isEqualTo("MEMORY_EFFICIENCY");
- assertThat(debtCharacteristic.name()).isEqualTo("Memory use");
- assertThat(debtCharacteristic.order()).isEqualTo(1);
- assertThat(debtCharacteristic.parentId()).isNull();
- assertThat(debtCharacteristic.isSub()).isFalse();
-
-
- assertThat(debtModel.characteristicById(555)).isNull();
- }
-
- @Test
- public void characteristic_by_key() {
- DefaultDebtCharacteristic debtCharacteristic = (DefaultDebtCharacteristic) debtModel.characteristicByKey("EFFICIENCY");
- assertThat(debtCharacteristic).isNotNull();
- assertThat(debtCharacteristic.id()).isEqualTo(2);
- assertThat(debtCharacteristic.key()).isEqualTo("EFFICIENCY");
- assertThat(debtCharacteristic.name()).isEqualTo("Efficiency");
- assertThat(debtCharacteristic.order()).isNull();
- assertThat(debtCharacteristic.parentId()).isEqualTo(1);
- assertThat(debtCharacteristic.isSub()).isTrue();
-
- assertThat(debtModel.characteristicByKey("UNKNOWN")).isNull();
+ public void is_Deprecated() {
+ assertThat(underTest.characteristicByKey("xxx")).isNull();
+ assertThat(underTest.characteristicById(1)).isNull();
+ assertThat(underTest.characteristics()).isEmpty();
+ assertThat(underTest.allCharacteristics()).isEmpty();
+ assertThat(underTest.subCharacteristics("xxx")).isEmpty();
}
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.batch.internal;
-
-import org.junit.Test;
-import org.sonar.api.rule.RuleKey;
-
-import java.text.SimpleDateFormat;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultCharacteristicTest {
-
- @Test
- public void test_setters_and_getters_for_characteristic() throws Exception {
- DefaultCharacteristic root = new DefaultCharacteristic().setKey("REUSABILITY");
-
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("MODULARITY")
- .setName("Modularity")
- .setOrder(5)
- .setParent(root)
- .setRoot(root)
- .setCreatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"))
- .setUpdatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
-
- assertThat(characteristic.id()).isEqualTo(1);
- assertThat(characteristic.key()).isEqualTo("MODULARITY");
- assertThat(characteristic.name()).isEqualTo("Modularity");
- assertThat(characteristic.order()).isEqualTo(5);
- assertThat(characteristic.parent()).isEqualTo(root);
- assertThat(characteristic.root()).isEqualTo(root);
- assertThat(characteristic.createdAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
- assertThat(characteristic.updatedAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
- }
-
- @Test
- public void set_name_as_key() {
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setName("Compiler related portability", true);
-
- assertThat(characteristic.key()).isEqualTo("COMPILER_RELATED_PORTABILITY");
- assertThat(characteristic.name()).isEqualTo("Compiler related portability");
- }
-
- @Test
- public void add_requirement() {
- DefaultRequirement requirement = new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule"));
-
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("MODULARITY")
- .addRequirement(requirement);
-
- assertThat(characteristic.requirements()).hasSize(1);
- }
-
- @Test
- public void add_child() {
- DefaultCharacteristic root = new DefaultCharacteristic()
- .setId(1)
- .setKey("REUSABILITY");
-
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("MODULARITY")
- .setParent(root);
-
- assertThat(root.children()).hasSize(1);
- assertThat(characteristic.parent()).isEqualTo(root);
- }
-
-
-
- @Test
- public void is_root() {
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("NETWORK_USE")
- .setName("Network use")
- .setOrder(5)
- .setParent(null)
- .setRoot(null);
-
- assertThat(characteristic.isRoot()).isTrue();
- }
-
- @Test
- public void test_equals() throws Exception {
- assertThat(new DefaultCharacteristic().setKey("NETWORK_USE")).isEqualTo(new DefaultCharacteristic().setKey("NETWORK_USE"));
- assertThat(new DefaultCharacteristic().setKey("NETWORK_USE")).isNotEqualTo(new DefaultCharacteristic().setKey("MAINTABILITY"));
- }
-
- @Test
- public void test_hascode() throws Exception {
- assertThat(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode()).isEqualTo(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode());
- assertThat(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode()).isNotEqualTo(new DefaultCharacteristic().setKey("MAINTABILITY").hashCode());
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.batch.internal;
-
-import org.junit.Test;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.utils.WorkUnit;
-import org.sonar.api.utils.internal.WorkDuration;
-
-import java.text.SimpleDateFormat;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultRequirementTest {
-
- @Test
- public void test_setters_and_getters_for_characteristic() throws Exception {
- DefaultCharacteristic root = new DefaultCharacteristic().setId(1).setKey("REUSABILITY");
-
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("MODULARITY")
- .setName("Modularity")
- .setParent(root)
- .setRoot(root);
-
- DefaultRequirement requirement = new DefaultRequirement()
- .setId(3)
- .setRuleKey(RuleKey.of("repo", "rule"))
- .setCharacteristic(characteristic)
- .setRootCharacteristic(root)
- .setFunction("linear_offset")
- .setFactorValue(2)
- .setFactorUnit(WorkDuration.UNIT.MINUTES)
- .setOffsetValue(1)
- .setOffsetUnit(WorkDuration.UNIT.HOURS)
- .setCreatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"))
- .setUpdatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
-
- assertThat(requirement.id()).isEqualTo(3);
- assertThat(requirement.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
- assertThat(requirement.characteristic()).isEqualTo(characteristic);
- assertThat(requirement.rootCharacteristic()).isEqualTo(root);
- assertThat(requirement.function()).isEqualTo("linear_offset");
- assertThat(requirement.factorValue()).isEqualTo(2);
- assertThat(requirement.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
- assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
- assertThat(requirement.offsetValue()).isEqualTo(1);
- assertThat(requirement.offsetUnit()).isEqualTo(WorkDuration.UNIT.HOURS);
- assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
- assertThat(requirement.createdAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
- assertThat(requirement.updatedAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
- }
-
- @Test
- public void test_equals() throws Exception {
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("MODULARITY");
-
- assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic))
- .isEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic));
- assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic))
- .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo2", "rule2")).setCharacteristic(characteristic));
-
- assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic))
- .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(
- new DefaultCharacteristic()
- .setId(2)
- .setKey("REUSABILITY")));
-
- }
-
- @Test
- public void test_hashcode() throws Exception {
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("MODULARITY")
- .setName("Modularity")
- .setOrder(5);
-
- assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic).hashCode())
- .isEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic).hashCode());
- assertThat(new DefaultRequirement().setRuleKey(RuleKey.of("repo", "rule")).setCharacteristic(characteristic).hashCode())
- .isNotEqualTo(new DefaultRequirement().setRuleKey(RuleKey.of("repo2", "rule2")).setCharacteristic(characteristic).hashCode());
- }
-
- @Test
- public void test_deprecated_setters_and_getters_for_characteristic() throws Exception {
- DefaultCharacteristic root = new DefaultCharacteristic().setId(1).setKey("REUSABILITY");
-
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("MODULARITY")
- .setName("Modularity")
- .setParent(root)
- .setRoot(root);
-
- DefaultRequirement requirement = new DefaultRequirement()
- .setId(3)
- .setRuleKey(RuleKey.of("repo", "rule"))
- .setCharacteristic(characteristic)
- .setRootCharacteristic(root)
- .setFunction("linear_offset")
- .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
- .setOffset(WorkUnit.create(1d, WorkUnit.HOURS));
-
- assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
- assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
-
- assertThat(new DefaultRequirement()
- .setId(3)
- .setRuleKey(RuleKey.of("repo", "rule"))
- .setCharacteristic(characteristic)
- .setRootCharacteristic(root)
- .setFunction("linear_offset")
- .setFactor(WorkUnit.create(2d, WorkUnit.DAYS))
- .factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.DAYS));
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.technicaldebt.server.internal;
-
-import org.junit.Test;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.utils.WorkUnit;
-import org.sonar.api.utils.internal.WorkDuration;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultCharacteristicTest {
-
- @Test
- public void test_setters_and_getters_for_characteristic() throws Exception {
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("NETWORK_USE")
- .setName("Network use")
- .setOrder(5)
- .setParentId(2)
- .setRootId(2);
-
- assertThat(characteristic.id()).isEqualTo(1);
- assertThat(characteristic.key()).isEqualTo("NETWORK_USE");
- assertThat(characteristic.name()).isEqualTo("Network use");
- assertThat(characteristic.order()).isEqualTo(5);
- assertThat(characteristic.ruleKey()).isNull();
- assertThat(characteristic.function()).isNull();
- assertThat(characteristic.factorValue()).isNull();
- assertThat(characteristic.factorUnit()).isNull();
- assertThat(characteristic.offsetValue()).isNull();
- assertThat(characteristic.offsetUnit()).isNull();
- assertThat(characteristic.parentId()).isEqualTo(2);
- assertThat(characteristic.rootId()).isEqualTo(2);
- }
-
- @Test
- public void test_setters_and_getters_for_requirement() throws Exception {
- DefaultCharacteristic requirement = new DefaultCharacteristic()
- .setId(1)
- .setRuleKey(RuleKey.of("repo", "rule"))
- .setFunction("linear_offset")
- .setFactorValue(2)
- .setFactorUnit(WorkDuration.UNIT.MINUTES)
- .setOffsetValue(1)
- .setOffsetUnit(WorkDuration.UNIT.HOURS)
- .setRootId(3)
- .setParentId(2);
-
- assertThat(requirement.id()).isEqualTo(1);
- assertThat(requirement.key()).isNull();
- assertThat(requirement.name()).isNull();
- assertThat(requirement.order()).isNull();
- assertThat(requirement.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
- assertThat(requirement.function()).isEqualTo("linear_offset");
- assertThat(requirement.factorValue()).isEqualTo(2);
- assertThat(requirement.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
- assertThat(requirement.offsetValue()).isEqualTo(1);
- assertThat(requirement.offsetUnit()).isEqualTo(WorkDuration.UNIT.HOURS);
- assertThat(requirement.parentId()).isEqualTo(2);
- assertThat(requirement.rootId()).isEqualTo(3);
- }
-
- @Test
- public void is_root() {
- DefaultCharacteristic characteristic = new DefaultCharacteristic()
- .setId(1)
- .setKey("NETWORK_USE")
- .setName("Network use")
- .setOrder(5)
- .setParentId(null)
- .setRootId(null);
-
- assertThat(characteristic.isRoot()).isTrue();
- }
-
- @Test
- public void is_requirement() {
- DefaultCharacteristic requirement = new DefaultCharacteristic()
- .setId(1)
- .setRuleKey(RuleKey.of("repo", "rule"))
- .setFunction("linear_offset")
- .setFactorValue(2)
- .setFactorUnit(WorkDuration.UNIT.MINUTES)
- .setOffsetValue(1)
- .setOffsetUnit(WorkDuration.UNIT.HOURS)
- .setRootId(3)
- .setParentId(2);
-
- assertThat(requirement.isRequirement()).isTrue();
- }
-
- @Test
- public void test_equals() throws Exception {
- assertThat(new DefaultCharacteristic().setKey("NETWORK_USE")).isEqualTo(new DefaultCharacteristic().setKey("NETWORK_USE"));
- assertThat(new DefaultCharacteristic().setKey("NETWORK_USE")).isNotEqualTo(new DefaultCharacteristic().setKey("MAINTABILITY"));
-
- assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule"))).isEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")));
- assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule"))).isNotEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo2", "rule2")));
- }
-
- @Test
- public void test_hascode() throws Exception {
- assertThat(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode()).isEqualTo(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode());
- assertThat(new DefaultCharacteristic().setKey("NETWORK_USE").hashCode()).isNotEqualTo(new DefaultCharacteristic().setKey("MAINTABILITY").hashCode());
-
- assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")).hashCode()).isEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")).hashCode());
- assertThat(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo", "rule")).hashCode()).isNotEqualTo(new DefaultCharacteristic().setRuleKey(RuleKey.of("repo2", "rule2")).hashCode());
- }
-
- @Test
- public void test_deprecated_setters_and_getters_for_characteristic() throws Exception {
- DefaultCharacteristic requirement = new DefaultCharacteristic()
- .setId(1)
- .setRuleKey(RuleKey.of("repo", "rule"))
- .setFunction("linear_offset")
- .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
- .setOffset(WorkUnit.create(1d, WorkUnit.HOURS));
-
- assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
- assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
-
- assertThat(new DefaultCharacteristic()
- .setId(1)
- .setRuleKey(RuleKey.of("repo", "rule"))
- .setFunction("linear")
- .setFactor(WorkUnit.create(2d, WorkUnit.DAYS))
- .factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.DAYS));
- }
-
-}