All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mockit.coverage.reporting.packages.ListWithFilesAndPercentages Maven / Gradle / Ivy

Go to download

JMockit is a Java toolkit for automated developer testing. It contains APIs for the creation of the objects to be tested, for mocking dependencies, and for faking external APIs; JUnit (4 & 5) and TestNG test runners are supported. It also contains an advanced code coverage tool.

There is a newer version: 1.53.0
Show newest version
/*
 * Copyright (c) 2006 JMockit developers
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.coverage.reporting.packages;

import java.io.*;
import java.util.*;
import javax.annotation.*;

import mockit.coverage.*;

abstract class ListWithFilesAndPercentages
{
   @Nonnull protected final PrintWriter output;
   @Nonnull private final String baseIndent;
   @Nonnegative int totalItems;
   @Nonnegative int coveredItems;

   ListWithFilesAndPercentages(@Nonnull PrintWriter output, @Nonnull String baseIndent) {
      this.output = output;
      this.baseIndent = baseIndent;
   }

   final void writeMetricsForEachFile(@Nullable String packageName, @Nonnull List fileNames) {
      if (fileNames.isEmpty()) {
         return;
      }

      Collections.sort(fileNames);
      totalItems = 0;
      coveredItems = 0;

      for (String fileName : fileNames) {
         writeMetricsForFile(packageName, fileName);
      }
   }

   final void writeRowStart() {
      printIndent();
      output.println("");
   }

   final void writeRowClose() {
      printIndent();
      output.println("");
   }

   final void printIndent() { output.write(baseIndent); }

   protected abstract void writeMetricsForFile(@Nullable String packageName, @Nonnull String fileName);

   final void printCoveragePercentage(@Nonnegative int covered, @Nonnegative int total, int percentage) {
      printIndent();
      output.write("   0) {
         writeRowCellWithCoveragePercentage(covered, total, percentage);
      }
      else {
         output.write("class='nocode'>N/A");
      }

      output.println("");
   }

   private void writeRowCellWithCoveragePercentage(@Nonnegative int covered, @Nonnegative int total, @Nonnegative int percentage) {
      output.write("style='background-color:#");
      output.write(CoveragePercentage.percentageColor(covered, total));
      output.write("' title='Items: ");
      output.print(covered);
      output.write('/');
      output.print(total);
      output.write("'>");
      writePercentageValue(covered, total, percentage);
      output.print("%");
   }

   private void writePercentageValue(@Nonnegative int covered, @Nonnegative int total, @Nonnegative int percentage) {
      if (percentage < 100) {
         output.print(percentage);
      }
      else if (covered == total) {
         output.print("100");
      }
      else {
         output.print(">99");
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy