import java.util.ArrayList;
import java.util.List;
import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
@Override
public String getUuid() {
- if (uuid == null) {
- throw new UnsupportedOperationException(String.format("Component uuid of ref '%s' has not be fed yet", this.reportAttributes.getRef()));
- }
return uuid;
}
@Override
public String getKey() {
- if (key == null) {
- throw new UnsupportedOperationException(String.format("Component key of ref '%s' has not be fed yet", this.reportAttributes.getRef()));
- }
return key;
}
", reportAttributes=" + reportAttributes +
'}';
}
+
+ @Override
+ public boolean equals(@Nullable Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ComponentImpl component = (ComponentImpl) o;
+ return uuid.equals(component.uuid);
+ }
+
+ @Override
+ public int hashCode() {
+ return uuid.hashCode();
+ }
}
return builder(reportComponent).setKey(KEY).setUuid(UUID).build();
}
+ @Test
+ public void equals_compares_on_uuid_only() {
+ ComponentImpl.Builder builder = builder(BatchReport.Component.newBuilder().build()).setUuid(UUID);
+
+ assertThat(builder.setKey("1").build()).isEqualTo(builder.setKey("1").build());
+ assertThat(builder.setKey("1").build()).isEqualTo(builder.setKey("2").build());
+ }
+
+ @Test
+ public void hashCode_is_hashcode_of_uuid() {
+ ComponentImpl.Builder builder = builder(BatchReport.Component.newBuilder().build()).setUuid(UUID);
+
+ assertThat(builder.setKey("1").build().hashCode()).isEqualTo(builder.setKey("1").build().hashCode());
+ assertThat(builder.setKey("1").build().hashCode()).isEqualTo(builder.setKey("2").build().hashCode());
+ assertThat(builder.setKey("1").build().hashCode()).isEqualTo(UUID.hashCode());
+ }
}