org.conqat.engine.index.shared.TestIndexFindingBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of teamscale-commons-test-fixtures Show documentation
Show all versions of teamscale-commons-test-fixtures Show documentation
Provides common DTOs for Teamscale
/*
* Copyright (c) CQSE GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.conqat.engine.index.shared;
import org.conqat.engine.commons.findings.DetachedFinding;
import org.conqat.engine.commons.findings.StatementPathElement;
import org.conqat.engine.commons.findings.TestDetachedFindingBuilder;
import org.conqat.engine.commons.findings.location.ElementLocation;
import org.conqat.engine.commons.findings.location.TextRegionLocation;
import org.conqat.lib.commons.assessment.ETrafficLightColor;
/**
* Builds {@link IndexFinding}s for test purposes.
*/
public class TestIndexFindingBuilder {
private TestDetachedFindingBuilder detachedFinding = TestDetachedFindingBuilder.someDetachedFinding();
private long analysisTimestamp;
private String typeId;
/**
* @return a builder creating some fresh {@link IndexFinding} whose fields are all initialized with
* valid values.
*/
public static TestIndexFindingBuilder someIndexFinding() {
TestIndexFindingBuilder someIndexFinding = new TestIndexFindingBuilder();
return someIndexFinding.withTypeId(null).withAnalysisTimestamp(-1L);
}
private TestIndexFindingBuilder() {
// Intentionally private. Clients must obtain Builder via someIndexFinding().
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain IndexFinding#getAnalysisTimestamp() analysis timestamp}.
*/
public TestIndexFindingBuilder withAnalysisTimestamp(long analysisTimestamp) {
this.analysisTimestamp = analysisTimestamp;
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain IndexFinding#getTypeId()} () typeId}.
*/
public TestIndexFindingBuilder withTypeId(String typeId) {
this.typeId = typeId;
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain IndexFinding#getAssessment assessment}.
*/
public TestIndexFindingBuilder withAssessment(ETrafficLightColor assessment) {
detachedFinding.withAssessment(assessment);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain IndexFinding#getCategoryName() category}.
*/
public TestIndexFindingBuilder withCategory(String category) {
detachedFinding.withCategory(category);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain IndexFinding#getMessage() message}.
*/
public TestIndexFindingBuilder withMessage(String message) {
detachedFinding.withMessage(message);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain IndexFinding#getLocation() location}.
*/
public TestIndexFindingBuilder withLocation(ElementLocation location) {
detachedFinding.withLocation(location);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with an element location
* that has {@link ElementLocation#getUniformPath()} ()} set to the given uniform path.
*/
public TestIndexFindingBuilder withLocation(String uniformPath) {
detachedFinding.withLocation(uniformPath);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain TextRegionLocation#getRawStartOffset() start} and
* {@linkplain TextRegionLocation#getRawEndOffset() end} offsets
*/
public TestIndexFindingBuilder withStartAndEndOffsets(int startOffset, int endOffset) {
detachedFinding.withStartAndEndOffsets(startOffset, endOffset);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain TextRegionLocation#getRawStartLine() start} and
* {@linkplain TextRegionLocation#getRawEndLine() end} lines
*/
public TestIndexFindingBuilder withStartAndEndLine(int startLine, int endLine) {
detachedFinding.withStartAndEndLine(startLine, endLine);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain IndexFinding#getGroupName() group name}.
*/
public TestIndexFindingBuilder withGroupName(String groupName) {
detachedFinding.withGroupName(groupName);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given
* {@linkplain StatementPathElement}.
*/
public TestIndexFindingBuilder withStatementPathElement(StatementPathElement pathElement) {
detachedFinding.withStatementPathElement(pathElement);
return this;
}
/**
* Ensures that the {@link IndexFinding} is {@linkplain #build() built} with the given property.
*/
public TestIndexFindingBuilder withFindingProperty(String key, Object property) {
detachedFinding.withFindingProperty(key, property);
return this;
}
/**
* Builds the {@link IndexFinding}.
*
* @return {@link IndexFinding} whose fields are all initialized with arbitrary but valid values,
* unless overwritten using this builder's methods.
*/
public IndexFinding build() {
DetachedFinding builtDetachedFinding = detachedFinding.build();
if (typeId == null) {
withTypeId(IndexFinding.makeFindingTypeId(builtDetachedFinding.getCategoryName(),
builtDetachedFinding.getGroupName()));
}
return new IndexFinding(builtDetachedFinding, analysisTimestamp, typeId);
}
}