package org.knowm.xchart.regressiontests;

import org.junit.Assert;
import org.junit.Test;
import org.knowm.xchart.BitmapEncoder;
import org.knowm.xchart.QuickChart;
import org.knowm.xchart.XYChart;

import java.awt.*;
import java.io.ByteArrayOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.DigestOutputStream;
import java.security.MessageDigest;

public class SimplestExampleTest {

  static String digestType = "md5";

  @Test
  public void testSimplestExampleStaysTheSame() throws Exception {
    // given
    double[] xData = new double[] {0.0, 1.0, 2.0};
    double[] yData = new double[] {2.0, 1.0, 0.0};

    // when
    XYChart chart = QuickChart.getChart("Sample Chart", "X", "Y", "y(x)", xData, yData);
    chart.getStyler().setChartTitleFont(arial());
    chart.getStyler().setAxisTickLabelsFont(arial());
    chart.getStyler().setLegendFont(arial());
    chart.getStyler().setAxisTitleFont(arial());
    DigestOutputStream output =
        new DigestOutputStream(new ByteArrayOutputStream(), MessageDigest.getInstance(digestType));
    BitmapEncoder.saveBitmap(chart, output, BitmapEncoder.BitmapFormat.PNG);
    output.close();

    // test
    assertImagesEquals("simplestExample.png", output);
  }

  private Font arial() {
    return new Font("Arial", Font.PLAIN, 14);
  }

  public void assertImagesEquals(String expectedFileName, DigestOutputStream actual)
      throws Exception {
    String path =
        "/expectedChartRenderings/" + System.getProperty("os.name") + "/" + expectedFileName;
    byte[] expectedBytes = Files.readAllBytes(Paths.get(getClass().getResource(path).toURI()));
    byte[] expectedDigest = MessageDigest.getInstance(digestType).digest(expectedBytes);

    Assert.assertArrayEquals(expectedDigest, actual.getMessageDigest().digest());
  }
}

@@ -40,165 +40,8 @@
 s;%0A%0A
-import org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.knowm.xchart.BitmapEncoder;%0Aimport org.knowm.xchart.QuickChart;%0Aimport org.knowm.xchart.XYChart;%0A%0A
 impo
@@ -225,16 +225,172 @@
 eDigest;
+%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.knowm.xchart.BitmapEncoder;%0Aimport org.knowm.xchart.QuickChart;%0Aimport org.knowm.xchart.XYChart;
 %0A%0Apublic
@@ -1488,16 +1488,28 @@
 erings/%22
+%0A           
  + Syste
@@ -1536,14 +1536,58 @@
 me%22)
- + %22/%22
+.replaceAll(%22 %22, %22%22)%0A            + %22/%22%0A           
  + e

Remove spaces in OS name