aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-02-01 00:30:52 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2023-02-01 00:33:20 +0100
commitda21265a141b68ea3069afd79107f7d374027bc0 (patch)
tree5dbbe3c3e63c42ece49858c38c33b2804b3a48d3 /org.eclipse.jgit.test/tst/org/eclipse/jgit/lib
parent41b33a16b87dbc7246f81089ef58f4bb530e4b1d (diff)
parent21e902dd7fa4ff53dc35fd7c48f8b5edc52f8eea (diff)
downloadjgit-da21265a141b68ea3069afd79107f7d374027bc0.tar.gz
jgit-da21265a141b68ea3069afd79107f7d374027bc0.zip
Merge branch 'stable-5.13' into stable-6.0
* stable-5.13: Shortcut during git fetch for avoiding looping through all local refs FetchCommand: fix fetchSubmodules to work on a Ref to a blob Silence API warnings introduced by I466dcde6 Allow the exclusions of refs prefixes from bitmap PackWriterBitmapPreparer: do not include annotated tags in bitmap BatchingProgressMonitor: avoid int overflow when computing percentage Speedup GC listing objects referenced from reflogs FileSnapshotTest: Add more MISSING_FILE coverage Change-Id: I58ad4c210a5e7e5a1ba6b22315b04211c8909950
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TextProgressMonitorTest.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TextProgressMonitorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TextProgressMonitorTest.java
new file mode 100644
index 0000000000..55ca2cdea3
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TextProgressMonitorTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2023, SAP SE or an SAP affiliate company and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.lib;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TextProgressMonitorTest {
+
+ private TextProgressMonitor m;
+
+ private ByteArrayOutputStream buf;
+
+ @Before
+ public void setup() {
+ buf = new ByteArrayOutputStream();
+ m = new TextProgressMonitor(
+ new OutputStreamWriter(buf, StandardCharsets.UTF_8));
+ }
+
+ @Test
+ public void testSimple() throws Exception {
+ m.beginTask("task", 10);
+ for (int i = 0; i < 10; i++) {
+ m.update(1);
+ }
+ m.endTask();
+ Assert.assertArrayEquals(
+ new String[] { "", "task: 10% ( 1/10)",
+ "task: 20% ( 2/10)",
+ "task: 30% ( 3/10)",
+ "task: 40% ( 4/10)",
+ "task: 50% ( 5/10)",
+ "task: 60% ( 6/10)",
+ "task: 70% ( 7/10)",
+ "task: 80% ( 8/10)",
+ "task: 90% ( 9/10)",
+ "task: 100% (10/10)",
+ "task: 100% (10/10)\n" },
+ bufLines());
+ }
+
+ @Test
+ public void testLargeNumbers() throws Exception {
+ m.beginTask("task", 1_000_000_000);
+ for (int i = 0; i < 10; i++) {
+ m.update(100_000_000);
+ }
+ m.endTask();
+ Assert.assertArrayEquals(
+ new String[] { "",
+ "task: 10% ( 100000000/1000000000)",
+ "task: 20% ( 200000000/1000000000)",
+ "task: 30% ( 300000000/1000000000)",
+ "task: 40% ( 400000000/1000000000)",
+ "task: 50% ( 500000000/1000000000)",
+ "task: 60% ( 600000000/1000000000)",
+ "task: 70% ( 700000000/1000000000)",
+ "task: 80% ( 800000000/1000000000)",
+ "task: 90% ( 900000000/1000000000)",
+ "task: 100% (1000000000/1000000000)",
+ "task: 100% (1000000000/1000000000)\n" },
+ bufLines());
+ }
+
+ String[] bufLines() throws UnsupportedEncodingException {
+ String s = new String(buf.toString(StandardCharsets.UTF_8.name()));
+ return s.split("\r");
+ }
+}