Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from testproject-io/bugs/TP-11941
Browse files Browse the repository at this point in the history
Use unnamed entry for project name when there is no package to infer from
  • Loading branch information
Marat Strelets authored Jul 15, 2020
2 parents 388ebba + 641df77 commit 9994050
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ReportSettings inferReportSettings() {
return getUnnamedEntries();
}

String projectName = clazz.getPackageName();
String projectName = getPackageName(clazz);
String jobName = firstTrace.getClassName();

return new ReportSettings(projectName, jobName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ReportSettings inferReportSettings() {
// If JUnit's DisplayName annotation was found -> return it.
// Otherwise -> return clazz package name and clazz simple name
return Objects.requireNonNullElseGet(result, () ->
new ReportSettings(clazz.getPackageName(), clazz.getSimpleName()));
new ReportSettings(getPackageName(clazz), clazz.getSimpleName()));
}
}

Expand All @@ -117,9 +117,7 @@ private ReportSettings inspectDisplayName(final Class<?> clazz) {

try {
Method valueMethod = annotation.get().annotationType().getDeclaredMethod(JUNIT5_DISPLAY_NAME_VALUE);
return new ReportSettings(
clazz.getPackageName(),
valueMethod.invoke(annotation.get()).toString());
return new ReportSettings(getPackageName(clazz), valueMethod.invoke(annotation.get()).toString());
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
LOG.error("Failed to infer JobName from DisplayName annotation", e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package io.testproject.sdk.internal.reporting.inferrers;

import io.testproject.sdk.internal.rest.ReportSettings;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -49,6 +50,16 @@ default ReportSettings getUnnamedEntries() {
return new ReportSettings("Unnamed Project", "Unnamed Job");
}

/**
* Get class package name, or if it's empty, the unnamed entry.
* @param clazz Class to infer it's package name.
* @return class package name, or if it's empty, the unnamed entry.
*/
default String getPackageName(Class<?> clazz) {
return StringUtils.isEmpty(clazz.getPackageName())
? getUnnamedEntries().getProjectName() : clazz.getPackageName();
}

/**
* Infers Test name using specific Unit Test framework annotations.
* @return A name of the Test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ReportSettings inferReportSettings() {
// If TestNG @BeforeClass or @BeforeSuite annotations with description were found -> return it.
// Otherwise -> return clazz package name and clazz simple name
return Objects.requireNonNullElseGet(result, () ->
new ReportSettings(clazz.getPackageName(), clazz.getSimpleName()));
new ReportSettings(getPackageName(clazz), clazz.getSimpleName()));
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ private ReportSettings inspectAnnotation(final Class<?> clazz, final String anno
String description = descriptionMethod.invoke(annotation.get()).toString();

if (!StringUtils.isEmpty(description)) {
return new ReportSettings(clazz.getPackageName(), description);
return new ReportSettings(getPackageName(clazz), description);
}

// Description is empty
Expand Down

0 comments on commit 9994050

Please sign in to comment.