Skip to content

Commit

Permalink
[#690] Test coverage: Improve sonar quality metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
opatrascoiu committed Jul 24, 2024
1 parent baed162 commit 55bd754
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class AbstractVisitor<C, R> implements Visitor<C, R> {
protected final BuildLogger logger;
protected final ErrorHandler errorHandler;

public AbstractVisitor(BuildLogger logger, ErrorHandler errorHandler) {
protected AbstractVisitor(BuildLogger logger, ErrorHandler errorHandler) {
this.logger = logger;
this.errorHandler = errorHandler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ public Element<T> visit(FunctionTypeExpression<T> element, C context) {
return element;
}

@Override
public Element<T> visit(ListTypeExpression<T> element, C context) {
if (element == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,7 @@ Object evaluateFunctionInvocation(Object functionDefinition, FunctionType functi
Object secondArg = argList.get(1);
if (secondArg instanceof Function) {
Function sortFunction = (Function) secondArg;
List result = ((StandardFEELLib) lib).sort((List) argList.get(0), makeLambdaExpression(sortFunction));
return result;
return ((StandardFEELLib) lib).sort((List) argList.get(0), makeLambdaExpression(sortFunction));
} else {
handleError(String.format("'%s' is not supported yet", secondArg.getClass()));
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void setEventListener(EventListener eventListener) {

protected InterpreterVisitor visitor;

public AbstractDMNInterpreter(BasicDMNToNativeTransformer<Type, DMNContext> dmnTransformer, FEELLib<NUMBER, DATE, TIME, DATE_TIME, DURATION> feelLib) {
protected AbstractDMNInterpreter(BasicDMNToNativeTransformer<Type, DMNContext> dmnTransformer, FEELLib<NUMBER, DATE, TIME, DATE_TIME, DURATION> feelLib) {
this.logger = new Slf4jBuildLogger(LOGGER);
this.errorHandler = new LogErrorHandler(LOGGER);
this.dmnTransformer = dmnTransformer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.gs.dmn.feel.analysis.semantics.type.CompositeDataType;
import com.gs.dmn.feel.analysis.semantics.type.ListType;
import com.gs.dmn.runtime.Context;
import com.gs.dmn.runtime.interpreter.Result;
import com.gs.dmn.runtime.DMNRuntimeException;
import com.gs.dmn.transformation.basic.BasicDMNToNativeTransformer;

import java.util.List;
Expand All @@ -38,7 +38,7 @@ static Object validateConstraint(Object value, Type expectedType, ELInterpreter<
} else if (expectedType instanceof ListType) {
Type expectedElementType = ((ListType) expectedType).getElementType();
if (value instanceof List) {
for (Object element: (List) value) {
for (Object element: (List<?>) value) {
boolean validElement = checkConstraint(element, expectedElementType, elInterpreter, dmnTransformer);
if (!validElement) {
return null;
Expand Down Expand Up @@ -73,7 +73,7 @@ static boolean checkConstraint(Object value, Type expectedType, ELInterpreter<Ty
} else if (expectedType instanceof ListType) {
Type expectedElementType = ((ListType) expectedType).getElementType();
if (value instanceof List) {
for (Object element: (List) value) {
for (Object element: (List<?>) value) {
boolean res = checkConstraint(element, expectedElementType, elInterpreter, dmnTransformer);
if (!res) {
return false;
Expand Down Expand Up @@ -110,6 +110,10 @@ private static boolean evaluateConstraint(Object value, Type expectedType, ELInt
String unaryTests = ((ConstraintType) expectedType).getUnaryTests();
Result result = elInterpreter.evaluateUnaryTests(unaryTests, constraintContext);
Object resultValue = Result.value(result);
return resultValue instanceof Boolean ? (Boolean) resultValue : true;
if (resultValue instanceof Boolean) {
return (Boolean) resultValue;
} else {
throw new DMNRuntimeException(String.format("Unary tests '%s' evaluated to '%s', expected boolean", unaryTests, resultValue));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ public class TypeChecker {
private final ELInterpreter<Type, DMNContext> elInterpreter;
protected final FEELLib<?, ?, ?, ?, ?> lib;
private final boolean checkConstraints;
private final boolean throwError = true;
private final boolean throwError;

public TypeChecker(BasicDMNToNativeTransformer<Type, DMNContext> dmnTransformer, ELInterpreter<Type, DMNContext> elInterpreter, FEELLib<?, ?, ?, ?, ?> lib) {
this.dmnTransformer = dmnTransformer;
this.elInterpreter = elInterpreter;
this.lib = lib;
this.checkConstraints = dmnTransformer.isCheckConstraints();
this.throwError = true;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public static TCKVersion fromVersion(String key) {
private final String schemaLocation;
private final String prefix;
private final String namespace;
private final LinkedHashMap<String, String> namespaceToPrefixMap;
private final LinkedHashMap<String, String> prefixToNamespaceMap;
private final Map<String, String> namespaceToPrefixMap;
private final Map<String, String> prefixToNamespaceMap;
private final String javaPackage;

TCKVersion(String version, String schemaLocation, String prefix, String namespace, Map<String, String> otherNamespaces, String javaPackage) {
Expand Down Expand Up @@ -87,7 +87,7 @@ public Map<String, String> getNamespaceToPrefixMap() {
return this.namespaceToPrefixMap;
}

public LinkedHashMap<String, String> getPrefixToNamespaceMap() {
public Map<String, String> getPrefixToNamespaceMap() {
return prefixToNamespaceMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private boolean validateXMLSchema(Source source, String schemaPath) {
validator.validate(source);
return true;
} catch (Exception e){
LOGGER.error("Invalid DMN file: " + e.getMessage());
LOGGER.error(String.format("Invalid DMN file: %s", e.getMessage()));
throw new DMNRuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext
writeChildrenNode(writer, context, filter.getMatch(), MATCH);
}

@Override
protected void parseElements(HierarchicalStreamReader reader, UnmarshallingContext context, Object parent) {
mvDownConvertAnotherMvUpAssignChildElement(reader, context, parent, IN, TChildExpression.class);
mvDownConvertAnotherMvUpAssignChildElement(reader, context, parent, MATCH, TChildExpression.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext
writeChildrenNode(writer, context, i.getReturn(), RETURN);
}

@Override
protected void parseElements(HierarchicalStreamReader reader, UnmarshallingContext context, Object parent) {
mvDownConvertAnotherMvUpAssignChildElement(reader, context, parent, IN, TTypedChildExpression.class);
mvDownConvertAnotherMvUpAssignChildElement(reader, context, parent, RETURN, TChildExpression.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext
writeChildrenNode(writer, context, i.getSatisfies(), SATISFIES);
}

@Override
protected void parseElements(HierarchicalStreamReader reader, UnmarshallingContext context, Object parent) {
mvDownConvertAnotherMvUpAssignChildElement(reader, context, parent, IN, TTypedChildExpression.class);
mvDownConvertAnotherMvUpAssignChildElement(reader, context, parent, SATISFIES, TChildExpression.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ protected AbstractTestCasesToJUnitTransformer(DMNDialectDefinition<NUMBER, DATE,
super(dialectDefinition, dmnValidator, dmnTransformer, templateProvider, lazyEvaluationDetector, typeDeserializationConfigurer, inputParameters, logger);
}

@Override
protected abstract String getFileExtension();
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ void processTemplate(TDefinitions definitions, TItemDefinition itemDefinition, S

// Make output file
String relativeFilePath = javaPackageName.replace('.', '/');
String fileExtension = this.fileExtension;
File outputFile = makeOutputFile(outputPath, relativeFilePath, javaClassName, fileExtension);
File outputFile = makeOutputFile(outputPath, relativeFilePath, javaClassName, this.fileExtension);

// Process template
processTemplate(baseTemplatePath, templateName, params, outputFile, false);
Expand All @@ -116,8 +115,7 @@ void processTemplate(TDefinitions definitions, TInvocable in, String baseTemplat

// Make output file
String relativeFilePath = javaPackageName.replace('.', '/');
String fileExtension = this.fileExtension;
File outputFile = makeOutputFile(outputPath, relativeFilePath, javaClassName, fileExtension);
File outputFile = makeOutputFile(outputPath, relativeFilePath, javaClassName, this.fileExtension);

// Process template
processTemplate(baseTemplatePath, templateName, params, outputFile, true);
Expand All @@ -133,8 +131,7 @@ void processTemplate(TDefinitions definitions, TDecision decision, String baseTe

// Make output file
String relativeFilePath = javaPackageName.replace('.', '/');
String fileExtension = this.fileExtension;
File outputFile = makeOutputFile(outputPath, relativeFilePath, javaClassName, fileExtension);
File outputFile = makeOutputFile(outputPath, relativeFilePath, javaClassName, this.fileExtension);

// Process template
processTemplate(baseTemplatePath, templateName, params, outputFile, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.gs.dmn.ast.visitor.TraversalVisitor;
import com.gs.dmn.context.DMNContext;
import com.gs.dmn.dialect.DMNDialectDefinition;
import com.gs.dmn.dialect.StandardDMNDialectDefinition;
import com.gs.dmn.dialect.JavaTimeDMNDialectDefinition;
import com.gs.dmn.el.analysis.semantics.type.Type;
import com.gs.dmn.el.synthesis.ELTranslator;
import com.gs.dmn.error.ErrorHandler;
Expand Down Expand Up @@ -45,7 +45,7 @@ public SweepValidator() {

public SweepValidator(BuildLogger logger) {
super(logger);
this.dmnDialectDefinition = new StandardDMNDialectDefinition();
this.dmnDialectDefinition = new JavaTimeDMNDialectDefinition();
this.inputParameters = new InputParameters(makeInputParametersMap());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.gs.dmn.ast.visitor.TraversalVisitor;
import com.gs.dmn.context.DMNContext;
import com.gs.dmn.dialect.DMNDialectDefinition;
import com.gs.dmn.dialect.StandardDMNDialectDefinition;
import com.gs.dmn.dialect.JavaTimeDMNDialectDefinition;
import com.gs.dmn.el.analysis.semantics.type.Type;
import com.gs.dmn.error.ErrorHandler;
import com.gs.dmn.feel.analysis.semantics.type.FEELTypes;
Expand Down Expand Up @@ -48,7 +48,7 @@ public TypeRefValidator() {

public TypeRefValidator(BuildLogger logger) {
super(logger);
this.dmnDialectDefinition = new StandardDMNDialectDefinition();
this.dmnDialectDefinition = new JavaTimeDMNDialectDefinition();
this.inputParameters = new InputParameters(makeInputParametersMap());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void testConversionFunctions() {
}

@Test
@Override
public void testDateTimeFunctions() {
super.testDateTimeFunctions();

Expand All @@ -79,6 +80,7 @@ public void testDateTimeFunctions() {
}

@Test
@Override
public void testDateAndTimeProperties() {
List<EnvironmentEntry> entries = Arrays.asList(
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void testConversionFunctions() {
}

@Test
@Override
public void testDateTimeFunctions() {
super.testDateTimeFunctions();

Expand All @@ -79,6 +80,7 @@ public void testDateTimeFunctions() {
}

@Test
@Override
public void testDateAndTimeProperties() {
List<EnvironmentEntry> entries = Collections.emptyList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void testConversionFunctions() {
}

@Test
@Override
public void testDateTimeFunctions() {
super.testDateTimeFunctions();

Expand All @@ -84,6 +85,7 @@ public void testDateTimeFunctions() {
}

@Test
@Override
public void testDateAndTimeProperties() {
List<EnvironmentEntry> entries = Arrays.asList(
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ default Integer compare(T first, T second) {
}
}

@Override
default Boolean equalTo(T first, T second) {
return applyOperator(first, second, new Supplier[] {
() -> TRUE,
Expand All @@ -38,6 +39,7 @@ default Boolean equalTo(T first, T second) {
});
}

@Override
default Boolean lessThan(T first, T second) {
return applyOperator(first, second, new Supplier[] {
() -> null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public Double min(List<?> list) {
return result;
}

@Override
public Double mode(List<?> list) {
if (!SignavioUtil.verifyValidityOfListArgument(list)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected DefaultFEELLib getLib() {
// Date operators
//
@Test
@Override
public void testDateSubtract() {
super.testDateSubtract();

Expand All @@ -38,6 +39,7 @@ public void testDateSubtract() {
}

@Test
@Override
public void testDateAddDuration() {
super.testDateAddDuration();

Expand All @@ -51,6 +53,7 @@ public void testDateAddDuration() {
}

@Test
@Override
public void testDateSubtractDuration() {
super.testDateSubtractDuration();

Expand Down Expand Up @@ -82,6 +85,7 @@ public void testTimeIs() {
}

@Test
@Override
public void testTimeSubtract() {
super.testTimeSubtract();

Expand All @@ -90,6 +94,7 @@ public void testTimeSubtract() {
}

@Test
@Override
public void testTimeAddDuration() {
super.testTimeAddDuration();

Expand All @@ -113,6 +118,7 @@ public void testDateTimeIs() {
}

@Test
@Override
public void testDateTimeSubtract() {
super.testDateTimeSubtract();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected DoubleMixedJavaTimeFEELLib getLib() {
// Date operators
//
@Test
@Override
public void testDateSubtract() {
super.testDateSubtract();

Expand All @@ -39,6 +40,7 @@ public void testDateSubtract() {
}

@Test
@Override
public void testDateAddDuration() {
super.testDateAddDuration();

Expand All @@ -52,6 +54,7 @@ public void testDateAddDuration() {
}

@Test
@Override
public void testDateSubtractDuration() {
super.testDateSubtractDuration();

Expand Down Expand Up @@ -83,6 +86,7 @@ public void testTimeIs() {
}

@Test
@Override
public void testTimeSubtract() {
super.testTimeSubtract();

Expand All @@ -91,6 +95,7 @@ public void testTimeSubtract() {
}

@Test
@Override
public void testTimeAddDuration() {
super.testTimeAddDuration();

Expand All @@ -114,6 +119,7 @@ public void testDateTimeIs() {
}

@Test
@Override
public void testDateTimeSubtract() {
super.testDateTimeSubtract();

Expand Down
Loading

0 comments on commit 55bd754

Please sign in to comment.