TestSuiteHelper.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package de.jplag.endtoend.helper;
  2. import java.io.File;
  3. import java.util.List;
  4. import java.util.stream.Collectors;
  5. import de.jplag.JPlagComparison;
  6. import de.jplag.Language;
  7. import de.jplag.Submission;
  8. import de.jplag.endtoend.constants.TestDirectoryConstants;
  9. /**
  10. * Helper class to perform all necessary additional functions for the endToEnd tests.
  11. */
  12. public class TestSuiteHelper {
  13. /**
  14. * private constructor to prevent instantiation
  15. */
  16. private TestSuiteHelper() {
  17. // For Serialization
  18. }
  19. /**
  20. * Creates a unique identifier from the submissions in the JPlagComparison object which is used to find the results in
  21. * the json files.
  22. * @param jPlagComparison object from which the hash should be generated
  23. * @return unique identifier for test case recognition
  24. */
  25. public static String getTestIdentifier(JPlagComparison jPlagComparison) {
  26. return List.of(jPlagComparison.firstSubmission(), jPlagComparison.secondSubmission()).stream().map(Submission::getRoot)
  27. .map(FileHelper::getFileNameWithoutFileExtension).sorted().collect(Collectors.joining("-"));
  28. }
  29. /**
  30. * Returns the file pointing to the directory of the submissions for the given language and result json. The result
  31. * json's name is expected to be equal to the test suite identifier.
  32. * @param language is the language for the tests
  33. * @param resultJSON is the json containing the expected values
  34. * @return returns the directory of the submissions
  35. */
  36. public static File getSubmissionDirectory(Language language, File resultJSON) {
  37. return getSubmissionDirectory(language, FileHelper.getFileNameWithoutFileExtension(resultJSON));
  38. }
  39. /**
  40. * Returns the file pointing to the directory of the submissions for the given language and test suite identifier as
  41. * described in the Readme.md.
  42. * @param language is the langauge for the tests
  43. * @param testSuiteIdentifier is the test suite identifier of the tests
  44. * @return returns the directory of the submissions
  45. */
  46. public static File getSubmissionDirectory(Language language, String testSuiteIdentifier) {
  47. return TestDirectoryConstants.BASE_PATH_TO_LANGUAGE_RESOURCES.resolve(language.getIdentifier()).resolve(testSuiteIdentifier).toFile();
  48. }
  49. }