diff --git a/src/main/java/de/tum/in/www1/artemis/service/hestia/ProgrammingExerciseTaskService.java b/src/main/java/de/tum/in/www1/artemis/service/hestia/ProgrammingExerciseTaskService.java index f743cd4a3e11..78555242aea5 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/hestia/ProgrammingExerciseTaskService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/hestia/ProgrammingExerciseTaskService.java @@ -432,16 +432,15 @@ private String replaceTaskTests(String problemStatement, Set { - // matchResult is fa full task, e.g., [task][Bubble Sort](testBubbleSort,testClass[BubbleSort]) - String fullMatch = matchResult.group(); // group 1: task name, group 2: test names, e.g, testBubbleSort,testClass[BubbleSort] + String taskName = matchResult.group(1); String testNames = matchResult.group(2); // converted testids, e.g., 10,12 String testIds = replacer.apply(testNames, testCases); - // replace the names with their ids - return fullMatch.replace(testNames, testIds); + // construct a new task using the testids + return "[task][%s](%s)".formatted(taskName, testIds); }); } diff --git a/src/test/java/de/tum/in/www1/artemis/hestia/ProgrammingExerciseTaskServiceTest.java b/src/test/java/de/tum/in/www1/artemis/hestia/ProgrammingExerciseTaskServiceTest.java index 2e607ae0b996..2eb63fc57e91 100644 --- a/src/test/java/de/tum/in/www1/artemis/hestia/ProgrammingExerciseTaskServiceTest.java +++ b/src/test/java/de/tum/in/www1/artemis/hestia/ProgrammingExerciseTaskServiceTest.java @@ -381,10 +381,30 @@ void testNameReplacementOnlyWithinTasks() { programmingExerciseTaskService.replaceTestNamesWithIds(programmingExercise); String problemStatement = programmingExercise.getProblemStatement(); - assertThat(problemStatement).contains("[task][Taskname](%s,%s".formatted(test1.getId(), test2.getId())) + assertThat(problemStatement).contains("[task][Taskname](%s,%s)".formatted(test1.getId(), test2.getId())) .contains("This description contains the words test and taskTest, which should not be replaced."); } + @Test + void testNameReplacementTaskNameSameAsTestName() { + var sort = programmingExerciseUtilService.addTestCaseToProgrammingExercise(programmingExercise, "sort"); + + updateProblemStatement(""" + [task][sort](sort) + Sort using the method sort. + @startuml + class LinkedList { + + sort() + } + @enduml"""); + + programmingExerciseTaskService.replaceTestNamesWithIds(programmingExercise); + String problemStatement = programmingExercise.getProblemStatement(); + + assertThat(problemStatement).contains("[task][sort](%s)".formatted(sort.getId())).contains("Sort using the method sort.") + .contains("%s)>+ sort()".formatted(sort.getId())); + } + @Test void testIdReplacementWithNames() { var bubbleSort = programmingExerciseTestCaseRepository.findByExerciseIdAndTestName(programmingExercise.getId(), "testClass[BubbleSort]").orElseThrow();