Skip to content

Commit

Permalink
Move percentage number formatting to ftl
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonInDMinor committed Sep 12, 2024
1 parent ebe6b75 commit 26a4645
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DurationFormatUtils;

import java.text.*;

/**
* @author kadehar
* @since 4.0
Expand Down Expand Up @@ -38,20 +36,6 @@ public static String formatDuration(Long durationMillis, String format) {
return formattedDuration;
}

public static double formatDouble(double value) {
log.info("Formatting value {}", value);
DecimalFormat df = new DecimalFormat("##.#");
String tmp = df.format(value);
NumberFormat numberFormat = NumberFormat.getInstance();
try {
double result = numberFormat.parse(tmp).doubleValue();
log.info("Formatted value is {}", result);
return result;
} catch (ParseException e) {
return 0.0;
}
}

public static String formatReportLink(String link) {
return link != null && link.endsWith("/") ? link + "allure" : link;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package guru.qa.allure.notifications.util;

import guru.qa.allure.notifications.formatters.Formatters;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -13,7 +12,6 @@ public class Percentage {
public double eval(int result, int total) {
log.info("Calculate percentage for result {} by total {}", result,
total);
double value = (result * 100.00) / total;
return Formatters.formatDouble(value);
return (result * 100.00) / total;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<b>${phrases.scenario.duration}: </b>${time}<br/>
<b>${phrases.scenario.totalScenarios}: </b>${total}
<ul>
<#if passed != 0 ><li><b>${phrases.scenario.totalPassed}: </b>${passed} (${passedPercentage} %)</li></#if>
<#if failed != 0 ><li><b>${phrases.scenario.totalFailed}: </b>${failed} (${failedPercentage} %)</li></#if>
<#if passed != 0 ><li><b>${phrases.scenario.totalPassed}: </b>${passed} (${passedPercentage?string("##.#")} %)</li></#if>
<#if failed != 0 ><li><b>${phrases.scenario.totalFailed}: </b>${failed} (${failedPercentage?string("##.#")} %)</li></#if>
<#if broken != 0 ><li><b>${phrases.scenario.totalBroken}: </b>${broken}</li></#if>
<#if unknown != 0 ><li><b>${phrases.scenario.totalUnknown}: </b>${unknown}</li></#if>
<#if skipped != 0 ><li><b>${phrases.scenario.totalSkipped}: </b>${skipped}</li></#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*${phrases.comment}:* ${comm}
*${phrases.scenario.duration}:* ${time}
*${phrases.scenario.totalScenarios}:* ${total}
<#if passed != 0 > *${phrases.scenario.totalPassed}:* ${passed} (${passedPercentage} %)</#if>
<#if failed != 0 > *${phrases.scenario.totalFailed}:* ${failed} (${failedPercentage} %)</#if>
<#if passed != 0 > *${phrases.scenario.totalPassed}:* ${passed} (${passedPercentage?string("##.#")} %)</#if>
<#if failed != 0 > *${phrases.scenario.totalFailed}:* ${failed} (${failedPercentage?string("##.#")} %)</#if>
<#if broken != 0 > *${phrases.scenario.totalBroken}:* ${broken} </#if>
<#if unknown != 0 >*${phrases.scenario.totalUnknown}:* ${unknown} </#if>
<#if skipped != 0 >*${phrases.scenario.totalSkipped}:* ${skipped} </#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
**-${phrases.comment}:** ${comm}
**-${phrases.scenario.duration}:** **${time}**
**-${phrases.scenario.totalScenarios}:** ${total}
<#if passed != 0 > **-${phrases.scenario.totalPassed}:** ${passed} **(${passedPercentage} %)**</#if>
<#if failed != 0 > **-${phrases.scenario.totalFailed}:** ${failed} **(${failedPercentage} %)** </#if>
<#if passed != 0 > **-${phrases.scenario.totalPassed}:** ${passed} **(${passedPercentage?string("##.#")} %)**</#if>
<#if failed != 0 > **-${phrases.scenario.totalFailed}:** ${failed} **(${failedPercentage?string("##.#")} %)** </#if>
<#if broken != 0 > **-${phrases.scenario.totalBroken}:** ${broken} </#if>
<#if unknown != 0 > **-${phrases.scenario.totalUnknown}:** ${unknown} </#if>
<#if skipped != 0 > **-${phrases.scenario.totalSkipped}:** ${skipped} </#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<b>${phrases.comment}: </b>${comm}
<b>${phrases.scenario.duration}: </b>${time}
<b>${phrases.scenario.totalScenarios}: </b>${total}
<#if passed != 0 ><b>${phrases.scenario.totalPassed}: </b>${passed} (${passedPercentage} %)</#if>
<#if failed != 0 ><b>${phrases.scenario.totalFailed}: </b>${failed} (${failedPercentage} %)</#if>
<#if passed != 0 ><b>${phrases.scenario.totalPassed}: </b>${passed} (${passedPercentage?string("##.#")} %)</#if>
<#if failed != 0 ><b>${phrases.scenario.totalFailed}: </b>${failed} (${failedPercentage?string("##.#")} %)</#if>
<#if broken != 0 ><b>${phrases.scenario.totalBroken}: </b>${broken}</#if>
<#if unknown != 0 ><b>${phrases.scenario.totalUnknown}: </b>${unknown}</#if>
<#if skipped != 0 ><b>${phrases.scenario.totalSkipped}: </b>${skipped}</#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<b>${duration}: </b>${time}<br/>
<b>${totalScenarios}: </b>${total}
<ul>
<#if passed != 0 ><li><b>${totalPassed}: </b>${passed} (${passedPercentage} %)</li></#if>
<#if failed != 0 ><li><b>${totalFailed}: </b>${failed} (${failedPercentage} %)</li></#if>
<#if passed != 0 ><li><b>${totalPassed}: </b>${passed} (${passedPercentage?string("##.#")} %)</li></#if>
<#if failed != 0 ><li><b>${totalFailed}: </b>${failed} (${failedPercentage?string("##.#")} %)</li></#if>
<#if broken != 0 ><li><b>${totalBroken}: </b>${broken}</li></#if>
<#if unknown != 0 ><li><b>${totalUnknown}: </b>${unknown}</li></#if>
<#if skipped != 0 ><li><b>${totalSkipped}: </b>${skipped}</li></#if>
Expand Down

0 comments on commit 26a4645

Please sign in to comment.