Skip to content

Commit

Permalink
Renamed getParentGroupName to getParentName + extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisszmundy committed Feb 23, 2024
1 parent b3fa968 commit e7c3ea7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static SurveyUnitUpdateDto getCollectedDataFromSurveyUnit(LunaticXmlSurv
.idVar(lunaticXmlCollectedData.getVariableName())
.values(variableValues)
.idLoop(LoopIdentifier.getLoopIdentifier(lunaticXmlCollectedData.getVariableName(), variablesMap, i))
.idParent(LoopIdentifier.getParentGroupName(lunaticXmlCollectedData.getVariableName(), variablesMap))
.idParent(LoopIdentifier.getParentName(lunaticXmlCollectedData.getVariableName(), variablesMap))
.build());
dataCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ public static String getLoopIdentifier(String variableName, VariablesMap variabl
if(variableName.startsWith(Constants.FILTER_RESULT_PREFIX)
&& variablesMap.hasVariable(variableName.replace(Constants.FILTER_RESULT_PREFIX,""))
){
Variable parentVariable = variablesMap.getVariable(variableName.replace(Constants.FILTER_RESULT_PREFIX,""));
return parentVariable.getGroupName();
return getParentGroupName(variablesMap, variableName, Constants.FILTER_RESULT_PREFIX);
}
if(variableName.endsWith(Constants.MISSING_SUFFIX)
&& variablesMap.hasVariable(variableName.replace(Constants.MISSING_SUFFIX,""))
){
Variable parentVariable = variablesMap.getVariable(variableName.replace(Constants.MISSING_SUFFIX,""));
return parentVariable.getGroupName();
return getParentGroupName(variablesMap, variableName, Constants.MISSING_SUFFIX);
}
log.debug("Variable {} not found in variablesMap and assigned in root group", variableName);
return Constants.ROOT_GROUP_NAME;
Expand All @@ -39,7 +37,12 @@ public static String getLoopIdentifier(String variableName, VariablesMap variabl
return String.format("%s_%d", variable.getGroup().getName() ,index);
}

public static String getParentGroupName(String variableName, VariablesMap variablesMap) {
private static String getParentGroupName(VariablesMap variablesMap, String variableName, String constantToReplace) {
Variable parentVariable = variablesMap.getVariable(variableName.replace(constantToReplace, ""));
return parentVariable.getGroupName();
}

public static String getParentName(String variableName, VariablesMap variablesMap) {
Variable variable = variablesMap.getVariable(variableName);
List<String> varsEno = Arrays.asList(Constants.getEnoVariables());
if ( variable == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ void test03(){
@DisplayName("Should return the root group as parent")
void test04(){
//When + Then
Assertions.assertThat(LoopIdentifier.getParentGroupName("var1", variablesMap)).isEqualTo(Constants.ROOT_GROUP_NAME);
Assertions.assertThat(LoopIdentifier.getParentName("var1", variablesMap)).isEqualTo(Constants.ROOT_GROUP_NAME);
}

@Test
@DisplayName("Should return null as parent")
void test05(){
//When + Then
Assertions.assertThat(LoopIdentifier.getParentGroupName("var2", variablesMap)).isNull();
Assertions.assertThat(LoopIdentifier.getParentName("var2", variablesMap)).isNull();
}

@Test
Expand All @@ -73,7 +73,7 @@ void test06(){
@DisplayName("Should return var1 as parent if missing suffix")
void test07(){
//When + Then
Assertions.assertThat(LoopIdentifier.getParentGroupName("var1_MISSING", variablesMap)).isEqualTo("var1");
Assertions.assertThat(LoopIdentifier.getParentName("var1_MISSING", variablesMap)).isEqualTo("var1");
}

@Test
Expand All @@ -87,14 +87,14 @@ void test08(){
@DisplayName("Should return var1 as parent if filter result prefix")
void test09(){
//When + Then
Assertions.assertThat(LoopIdentifier.getParentGroupName("FILTER_RESULT_var1", variablesMap)).isEqualTo("var1");
Assertions.assertThat(LoopIdentifier.getParentName("FILTER_RESULT_var1", variablesMap)).isEqualTo("var1");
}

@Test
@DisplayName("Should return root as parent if eno variable")
void test10(){
//When + Then
Assertions.assertThat(LoopIdentifier.getParentGroupName(Constants.getEnoVariables()[0], variablesMap)).isEqualTo(Constants.ROOT_GROUP_NAME);
Assertions.assertThat(LoopIdentifier.getParentName(Constants.getEnoVariables()[0], variablesMap)).isEqualTo(Constants.ROOT_GROUP_NAME);
}

}

0 comments on commit e7c3ea7

Please sign in to comment.