/*
 * Copyright 2012-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.buildpack.platform.docker;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Tests for {@link TotalProgressBar}.
 *
 * @author Phillip Webb
 */
class TotalProgressBarTests {

	@Test
	void withPrefixAndBookends() {
		TestPrintStream out = new TestPrintStream();
		TotalProgressBar bar = new TotalProgressBar("prefix:", '#', true, out);
		assertThat(out).hasToString("prefix: [ ");
		bar.accept(new TotalProgressEvent(10));
		assertThat(out.toString()).isEqualTo("prefix: [ #####");
		bar.accept(new TotalProgressEvent(50));
		assertThat(out.toString()).isEqualTo("prefix: [ #########################");
		bar.accept(new TotalProgressEvent(100));
		assertThat(out.toString()).isEqualTo("prefix: [ ################################################## ]\n");
	}

	@Test
	void withoutPrefix() {
		TestPrintStream out = new TestPrintStream();
		TotalProgressBar bar = new TotalProgressBar(null, '#', true, out);
		assertThat(out).hasToString("[ ");
		bar.accept(new TotalProgressEvent(10));
		assertThat(out.toString()).isEqualTo("[ #####");
		bar.accept(new TotalProgressEvent(50));
		assertThat(out.toString()).isEqualTo("[ #########################");
		bar.accept(new TotalProgressEvent(100));
		assertThat(out.toString()).isEqualTo("[ ################################################## ]\n");
	}

	@Test
	void withoutBookends() {
		TestPrintStream out = new TestPrintStream();
		TotalProgressBar bar = new TotalProgressBar("", '.', false, out);
		assertThat(out).hasToString("");
		bar.accept(new TotalProgressEvent(10));
		assertThat(out.toString()).isEqualTo(".....");
		bar.accept(new TotalProgressEvent(50));
		assertThat(out.toString()).isEqualTo(".........................");
		bar.accept(new TotalProgressEvent(100));
		assertThat(out.toString()).isEqualTo("..................................................\n");
	}

	static class TestPrintStream extends PrintStream {

		TestPrintStream() {
			super(new ByteArrayOutputStream());
		}

		@Override
		public String toString() {
			return this.out.toString();
		}

	}

}

@@ -1434,32 +1434,37 @@
 (out.toString())
+%0A%09%09%09%09
 .isEqualTo(%22pref
@@ -1450,32 +1450,46 @@
 %0A%09%09%09%09.isEqualTo(
+String.format(
 %22prefix: %5B #####
@@ -1527,36 +1527,37 @@
 ############## %5D
-%5C
+%25
 n%22)
+)
 ;%0A%09%7D%0A%0A%09@Test%0A%09vo
@@ -2010,32 +2010,46 @@
 ng()).isEqualTo(
+String.format(
 %22%5B #############
@@ -2087,20 +2087,21 @@
 ###### %5D
-%5C
+%25
 n%22)
+)
 ;%0A%09%7D%0A%0A%09@
@@ -2557,32 +2557,46 @@
 ng()).isEqualTo(
+String.format(
 %22...............
@@ -2634,12 +2634,13 @@
 ....
-%5C
+%25
 n%22)
+)
 ;%0A%09%7D

Make line ending expectations in TotalProgressBarTests OS-independent