aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib')
-rw-r--r--org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectIdTest.java564
-rw-r--r--org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java303
-rw-r--r--org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LfsPointerFilterTest.java181
-rw-r--r--org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java398
-rw-r--r--org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/MutableLongObjectIdTest.java59
5 files changed, 1505 insertions, 0 deletions
diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectIdTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectIdTest.java
new file mode 100644
index 0000000000..81c7f14e81
--- /dev/null
+++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectIdTest.java
@@ -0,0 +1,564 @@
+/*
+ * Copyright (C) 2015, Matthias Sohn <matthias.sohn@sap.com> 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.lfs.lib;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils;
+import org.junit.Test;
+
+/*
+ * Ported to SHA-256 from org.eclipse.jgit.lib.AbbreviatedObjectIdTest
+ */
+public class AbbreviatedLongObjectIdTest {
+ @Test
+ public void testEmpty_FromByteArray() {
+ final AbbreviatedLongObjectId i;
+ i = AbbreviatedLongObjectId.fromString(new byte[] {}, 0, 0);
+ assertNotNull(i);
+ assertEquals(0, i.length());
+ assertFalse(i.isComplete());
+ assertEquals("", i.name());
+ }
+
+ @Test
+ public void testEmpty_FromString() {
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId
+ .fromString("");
+ assertNotNull(i);
+ assertEquals(0, i.length());
+ assertFalse(i.isComplete());
+ assertEquals("", i.name());
+ }
+
+ @Test
+ public void testFull_FromByteArray() {
+ final String s = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final byte[] b = org.eclipse.jgit.lib.Constants.encodeASCII(s);
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(b,
+ 0, b.length);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertTrue(i.isComplete());
+ assertEquals(s, i.name());
+
+ final LongObjectId f = i.toLongObjectId();
+ assertNotNull(f);
+ assertEquals(LongObjectId.fromString(s), f);
+ assertEquals(f.hashCode(), i.hashCode());
+ }
+
+ @Test
+ public void testFull_FromString() {
+ final String s = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertTrue(i.isComplete());
+ assertEquals(s, i.name());
+
+ final LongObjectId f = i.toLongObjectId();
+ assertNotNull(f);
+ assertEquals(LongObjectId.fromString(s), f);
+ assertEquals(f.hashCode(), i.hashCode());
+ }
+
+ @Test
+ public void test1_FromString() {
+ final String s = "2";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test2_FromString() {
+ final String s = "27";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test3_FromString() {
+ final String s = "27e";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test4_FromString() {
+ final String s = "27e1";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test5_FromString() {
+ final String s = "27e15";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test6_FromString() {
+ final String s = "27e15b";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test7_FromString() {
+ final String s = "27e15b7";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test8_FromString() {
+ final String s = "27e15b72";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test9_FromString() {
+ final String s = "27e15b729";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test15_FromString() {
+ final String s = "27e15b72937fc8f";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test16_FromString() {
+ final String s = "27e15b72937fc8f5";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test17_FromString() {
+ final String s = "27e15b72937fc8f55";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void test33_FromString() {
+ final String s = "27e15b72937fc8f558da24ac3d50ec203";
+ final AbbreviatedLongObjectId i = AbbreviatedLongObjectId.fromString(s);
+ assertNotNull(i);
+ assertEquals(s.length(), i.length());
+ assertFalse(i.isComplete());
+ assertEquals(s, i.name());
+ assertNull(i.toLongObjectId());
+ }
+
+ @Test
+ public void testEquals_Short() {
+ final String s = "27e15b72";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId.fromString(s);
+ final AbbreviatedLongObjectId b = AbbreviatedLongObjectId.fromString(s);
+ assertNotSame(a, b);
+ assertTrue(a.hashCode() == b.hashCode());
+ assertEquals(b, a);
+ assertEquals(a, b);
+ }
+
+ @Test
+ public void testEquals_Full() {
+ final String s = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId.fromString(s);
+ final AbbreviatedLongObjectId b = AbbreviatedLongObjectId.fromString(s);
+ assertNotSame(a, b);
+ assertTrue(a.hashCode() == b.hashCode());
+ assertEquals(b, a);
+ assertEquals(a, b);
+ }
+
+ @Test
+ public void testNotEquals_SameLength() {
+ final String sa = "27e15b72";
+ final String sb = "27e15b7f";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId
+ .fromString(sa);
+ final AbbreviatedLongObjectId b = AbbreviatedLongObjectId
+ .fromString(sb);
+ assertFalse(a.equals(b));
+ assertFalse(b.equals(a));
+ }
+
+ @Test
+ public void testNotEquals_DiffLength() {
+ final String sa = "27e15b72abcd";
+ final String sb = "27e15b72";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId
+ .fromString(sa);
+ final AbbreviatedLongObjectId b = AbbreviatedLongObjectId
+ .fromString(sb);
+ assertFalse(a.equals(b));
+ assertFalse(b.equals(a));
+ }
+
+ @Test
+ public void testPrefixCompare_Full() {
+ final String s1 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId
+ .fromString(s1);
+ final LongObjectId i1 = LongObjectId.fromString(s1);
+ assertEquals(0, a.prefixCompare(i1));
+ assertTrue(i1.startsWith(a));
+
+ final String s2 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b11";
+ final LongObjectId i2 = LongObjectId.fromString(s2);
+ assertTrue(a.prefixCompare(i2) < 0);
+ assertFalse(i2.startsWith(a));
+
+ final String s3 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b0f";
+ final LongObjectId i3 = LongObjectId.fromString(s3);
+ assertTrue(a.prefixCompare(i3) > 0);
+ assertFalse(i3.startsWith(a));
+ }
+
+ @Test
+ public void testPrefixCompare_1() {
+ final String sa = "2";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId
+ .fromString(sa);
+
+ final String s1 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i1 = LongObjectId.fromString(s1);
+ assertEquals(0, a.prefixCompare(i1));
+ assertTrue(i1.startsWith(a));
+
+ final String s2 = "37e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i2 = LongObjectId.fromString(s2);
+ assertTrue(a.prefixCompare(i2) < 0);
+ assertFalse(i2.startsWith(a));
+
+ final String s3 = "17e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i3 = LongObjectId.fromString(s3);
+ assertTrue(a.prefixCompare(i3) > 0);
+ assertFalse(i3.startsWith(a));
+ }
+
+ @Test
+ public void testPrefixCompare_15() {
+ final String sa = "27e15b72937fc8f";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId
+ .fromString(sa);
+
+ final String s1 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i1 = LongObjectId.fromString(s1);
+ assertEquals(0, a.prefixCompare(i1));
+ assertTrue(i1.startsWith(a));
+
+ final String s2 = "27e15b72937fc90558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i2 = LongObjectId.fromString(s2);
+ assertTrue(a.prefixCompare(i2) < 0);
+ assertFalse(i2.startsWith(a));
+
+ final String s3 = "27e15b72937fc8e558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i3 = LongObjectId.fromString(s3);
+ assertTrue(a.prefixCompare(i3) > 0);
+ assertFalse(i3.startsWith(a));
+ }
+
+ @Test
+ public void testPrefixCompare_16() {
+ final String sa = "27e15b72937fc8f5";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId
+ .fromString(sa);
+
+ final String s1 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i1 = LongObjectId.fromString(s1);
+ assertEquals(0, a.prefixCompare(i1));
+ assertTrue(i1.startsWith(a));
+
+ final String s2 = "27e15b72937fc8f658da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i2 = LongObjectId.fromString(s2);
+ assertTrue(a.prefixCompare(i2) < 0);
+ assertFalse(i2.startsWith(a));
+
+ final String s3 = "27e15b72937fc8f458da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i3 = LongObjectId.fromString(s3);
+ assertTrue(a.prefixCompare(i3) > 0);
+ assertFalse(i3.startsWith(a));
+ }
+
+ @Test
+ public void testPrefixCompare_17() {
+ final String sa = "27e15b72937fc8f55";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId
+ .fromString(sa);
+
+ final String s1 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i1 = LongObjectId.fromString(s1);
+ assertEquals(0, a.prefixCompare(i1));
+ assertTrue(i1.startsWith(a));
+
+ final String s2 = "27e15b72937fc8f568da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i2 = LongObjectId.fromString(s2);
+ assertTrue(a.prefixCompare(i2) < 0);
+ assertFalse(i2.startsWith(a));
+
+ final String s3 = "27e15b72937fc8f548da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i3 = LongObjectId.fromString(s3);
+ assertTrue(a.prefixCompare(i3) > 0);
+ assertFalse(i3.startsWith(a));
+ }
+
+ @Test
+ public void testPrefixCompare_33() {
+ final String sa = "27e15b72937fc8f558da24ac3d50ec203";
+ final AbbreviatedLongObjectId a = AbbreviatedLongObjectId
+ .fromString(sa);
+
+ final String s1 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i1 = LongObjectId.fromString(s1);
+ assertEquals(0, a.prefixCompare(i1));
+ assertTrue(i1.startsWith(a));
+
+ final String s2 = "27e15b72937fc8f558da24ac3d50ec20402a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i2 = LongObjectId.fromString(s2);
+ assertTrue(a.prefixCompare(i2) < 0);
+ assertFalse(i2.startsWith(a));
+
+ final String s3 = "27e15b72937fc8f558da24ac3d50ec20202a4cf21e33b87ae8e4ce90e89c4b10";
+ final LongObjectId i3 = LongObjectId.fromString(s3);
+ assertTrue(a.prefixCompare(i3) > 0);
+ assertFalse(i3.startsWith(a));
+ }
+
+ @Test
+ public void testIsId() {
+ // These are all too short.
+ assertFalse(AbbreviatedLongObjectId.isId(""));
+ assertFalse(AbbreviatedLongObjectId.isId("a"));
+
+ // These are too long.
+ assertFalse(AbbreviatedLongObjectId.isId(LongObjectId
+ .fromString(
+ "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10")
+ .name() + "0"));
+ assertFalse(AbbreviatedLongObjectId.isId(LongObjectId
+ .fromString(
+ "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10")
+ .name() + "c0ffee"));
+
+ // These contain non-hex characters.
+ assertFalse(AbbreviatedLongObjectId.isId("01notahexstring"));
+
+ // These should all work.
+ assertTrue(AbbreviatedLongObjectId.isId("ab"));
+ assertTrue(AbbreviatedLongObjectId.isId("abc"));
+ assertTrue(AbbreviatedLongObjectId.isId("abcd"));
+ assertTrue(AbbreviatedLongObjectId.isId("abcd0"));
+ assertTrue(AbbreviatedLongObjectId.isId("abcd09"));
+ assertTrue(AbbreviatedLongObjectId.isId(LongObjectId
+ .fromString(
+ "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10")
+ .name()));
+ }
+
+ @Test
+ public void testAbbreviate() {
+ AnyLongObjectId id = LongObjectIdTestUtils.hash("test");
+ assertEquals(
+ "abbreviated id should match the id it was abbreviated from", 0,
+ id.abbreviate(10).prefixCompare(id));
+ }
+
+ @Test
+ public void testFromStringByteWrongLength() {
+ byte[] buf = new byte[65];
+ try {
+ AbbreviatedLongObjectId.fromString(buf, 0, 65);
+ fail("expected IllegalArgumentException for too long AbbreviatedLongObjectId");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testFromStringWrongLength() {
+ AnyLongObjectId id = LongObjectIdTestUtils.hash("test");
+ try {
+ AbbreviatedLongObjectId.fromString(id.name() + "c0ffee");
+ fail("expected IllegalArgumentException for too long AbbreviatedLongObjectId");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testFromLongObjectId() {
+ AnyLongObjectId id = LongObjectIdTestUtils.hash("test");
+ assertEquals(0,
+ AbbreviatedLongObjectId.fromLongObjectId(id).prefixCompare(id));
+ }
+
+ @Test
+ public void testPrefixCompareByte() {
+ AnyLongObjectId id = LongObjectId.fromString(
+ "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
+ byte[] buf = new byte[32];
+ id.copyRawTo(buf, 0);
+
+ AbbreviatedLongObjectId a = id.abbreviate(62);
+ assertEquals(0, a.prefixCompare(buf, 0));
+
+ a = LongObjectId
+ .fromString(
+ "0023456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
+ .abbreviate(16);
+ assertEquals(-1, a.prefixCompare(buf, 0));
+ a = LongObjectId
+ .fromString(
+ "0123456789abcdef0023456789abcdef0123456789abcdef0123456789abcdef")
+ .abbreviate(32);
+ assertEquals(-1, a.prefixCompare(buf, 0));
+ a = LongObjectId
+ .fromString(
+ "0123456789abcdef0123456789abcdef0023456789abcdef0123456789abcdef")
+ .abbreviate(48);
+ assertEquals(-1, a.prefixCompare(buf, 0));
+ a = LongObjectId
+ .fromString(
+ "0123456789abcdef0123456789abcdef0123456789abcdef0023456789abcdef")
+ .abbreviate(64);
+ assertEquals(-1, a.prefixCompare(buf, 0));
+
+ a = LongObjectId
+ .fromString(
+ "1123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
+ .abbreviate(16);
+ assertEquals(1, a.prefixCompare(buf, 0));
+ a = LongObjectId
+ .fromString(
+ "0123456789abcdef1123456789abcdef0123456789abcdef0123456789abcdef")
+ .abbreviate(32);
+ assertEquals(1, a.prefixCompare(buf, 0));
+ a = LongObjectId
+ .fromString(
+ "0123456789abcdef0123456789abcdef1123456789abcdef0123456789abcdef")
+ .abbreviate(48);
+ assertEquals(1, a.prefixCompare(buf, 0));
+ a = LongObjectId
+ .fromString(
+ "0123456789abcdef0123456789abcdef0123456789abcdef1123456789abcdef")
+ .abbreviate(64);
+ assertEquals(1, a.prefixCompare(buf, 0));
+ }
+
+ @Test
+ public void testPrefixCompareLong() {
+ AnyLongObjectId id = new LongObjectId(1L, 2L, 3L, 4L);
+ long[] buf = new long[4];
+ id.copyRawTo(buf, 0);
+
+ AbbreviatedLongObjectId a = id.abbreviate(62);
+ assertEquals(0, a.prefixCompare(buf, 0));
+
+ a = new LongObjectId(0L, 2L, 3L, 4L).abbreviate(16);
+ assertEquals(-1, a.prefixCompare(buf, 0));
+ a = new LongObjectId(1L, 1L, 3L, 4L).abbreviate(32);
+ assertEquals(-1, a.prefixCompare(buf, 0));
+ a = new LongObjectId(1L, 2L, 2L, 4L).abbreviate(48);
+ assertEquals(-1, a.prefixCompare(buf, 0));
+ a = new LongObjectId(1L, 2L, 3L, 3L).abbreviate(64);
+ assertEquals(-1, a.prefixCompare(buf, 0));
+
+ a = new LongObjectId(2L, 2L, 3L, 4L).abbreviate(16);
+ assertEquals(1, a.prefixCompare(buf, 0));
+ a = new LongObjectId(1L, 3L, 3L, 4L).abbreviate(32);
+ assertEquals(1, a.prefixCompare(buf, 0));
+ a = new LongObjectId(1L, 2L, 4L, 4L).abbreviate(48);
+ assertEquals(1, a.prefixCompare(buf, 0));
+ a = new LongObjectId(1L, 2L, 3L, 5L).abbreviate(64);
+ assertEquals(1, a.prefixCompare(buf, 0));
+ }
+
+ @Test
+ public void testGetFirstByte() {
+ AnyLongObjectId id = LongObjectId.fromString(
+ "f423456789abcdef0123456789abcdef0123456789abcdef1123456789abcdef");
+ AbbreviatedLongObjectId a = id.abbreviate(10);
+ assertEquals(0xf4, a.getFirstByte());
+ assertEquals(id.getFirstByte(), a.getFirstByte());
+ }
+
+ @SuppressWarnings("unlikely-arg-type")
+ @Test
+ public void testNotEquals() {
+ AbbreviatedLongObjectId a = new LongObjectId(1L, 2L, 3L, 4L)
+ .abbreviate(10);
+ assertFalse(a.equals("different"));
+ }
+}
diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
new file mode 100644
index 0000000000..da78b28d90
--- /dev/null
+++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
@@ -0,0 +1,303 @@
+/*
+ * Copyright (C) 2016, Christian Halstrick <christian.halstrick@sap.com> 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.lfs.lib;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.eclipse.jgit.lfs.LfsPointer;
+import org.junit.Test;
+
+/*
+ * Test LfsPointer file abstraction
+ */
+public class LFSPointerTest {
+
+ private static final String TEST_SHA256 = "27e15b72937fc8f558da24ac3d50ec20302a4cf21e33b87ae8e4ce90e89c4b10";
+
+ @Test
+ public void testEncoding() throws IOException {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer ptr = new LfsPointer(id, 4);
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ ptr.encode(baos);
+ assertEquals(
+ "version https://git-lfs.github.com/spec/v1\noid sha256:"
+ + TEST_SHA256 + "\nsize 4\n",
+ baos.toString(UTF_8.name()));
+ }
+ }
+
+ @Test
+ public void testReadValidLfsPointer() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n";
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertEquals(lfs, LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadValidLfsPointerUnordered() throws Exception {
+ // This is actually not allowed per the spec, but JGit accepts it
+ // anyway.
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "size 4\n"
+ + "oid sha256:" + TEST_SHA256 + '\n';
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertEquals(lfs, LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadValidLfsPointerVersionNotFirst() throws Exception {
+ // This is actually not allowed per the spec, but JGit accepts it
+ // anyway.
+ String ptr = "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n"
+ + "version https://git-lfs.github.com/spec/v1\n";
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertEquals(lfs, LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInvalidLfsPointer() throws Exception {
+ String cSource = "size_t someFunction(void *ptr); // Fake C source\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ cSource.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInvalidLfsPointer2() throws Exception {
+ String cSource = "size_t\nsomeFunction(void *ptr);\n// Fake C source\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ cSource.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerVersionWrong() throws Exception {
+ String ptr = "version https://git-lfs.example.org/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerVersionTwice() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "version https://git-lfs.github.com/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerVersionTwice2() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "version https://git-lfs.github.com/spec/v1\n"
+ + "size 4\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerOidTwice() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "oid sha256:" + TEST_SHA256 + '\n'
+ + "size 4\n";
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testReadInValidLfsPointerSizeTwice() throws Exception {
+ String ptr = "version https://git-lfs.github.com/spec/v1\n"
+ + "size 4\n"
+ + "size 4\n"
+ + "oid sha256:" + TEST_SHA256 + '\n';
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ ptr.getBytes(UTF_8))) {
+ assertNull("Is not a LFS pointer", LfsPointer.parseLfsPointer(in));
+ }
+ }
+
+ @Test
+ public void testRoundtrip() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer ptr = new LfsPointer(id, 4);
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ ptr.encode(baos);
+ try (ByteArrayInputStream in = new ByteArrayInputStream(
+ baos.toByteArray())) {
+ assertEquals(ptr, LfsPointer.parseLfsPointer(in));
+ }
+ }
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertTrue(lfs.equals(lfs2));
+ assertTrue(lfs2.equals(lfs));
+ }
+
+ @Test
+ public void testEqualsNull() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertFalse(lfs.equals(null));
+ }
+
+ @Test
+ public void testEqualsSame() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertTrue(lfs.equals(lfs));
+ }
+
+ @Test
+ public void testEqualsOther() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertFalse(lfs.equals(new Object()));
+ }
+
+ @Test
+ public void testNotEqualsOid() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId
+ .fromString(TEST_SHA256.replace('7', '5'));
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertFalse(lfs.equals(lfs2));
+ assertFalse(lfs2.equals(lfs));
+ }
+
+ @Test
+ public void testNotEqualsSize() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 5);
+ assertFalse(lfs.equals(lfs2));
+ assertFalse(lfs2.equals(lfs));
+ }
+
+ @Test
+ public void testCompareToEquals() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertEquals(0, lfs.compareTo(lfs2));
+ assertEquals(0, lfs2.compareTo(lfs));
+ }
+
+ @Test
+ @SuppressWarnings("SelfComparison")
+ public void testCompareToSame() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertEquals(0, lfs.compareTo(lfs));
+ }
+
+ @Test
+ public void testCompareToNotEqualsOid() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId
+ .fromString(TEST_SHA256.replace('7', '5'));
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertNotEquals(0, lfs.compareTo(lfs2));
+ assertNotEquals(0, lfs2.compareTo(lfs));
+ }
+
+ @Test
+ public void testCompareToNotEqualsSize() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 5);
+ assertNotEquals(0, lfs.compareTo(lfs2));
+ assertNotEquals(0, lfs2.compareTo(lfs));
+ }
+
+ @Test
+ public void testCompareToNull() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertThrows(NullPointerException.class, () -> lfs.compareTo(null));
+ }
+
+ @Test
+ public void testHashcodeEquals() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 4);
+ assertEquals(lfs.hashCode(), lfs2.hashCode());
+ }
+
+ @Test
+ public void testHashcodeSame() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ assertEquals(lfs.hashCode(), lfs.hashCode());
+ }
+
+ @Test
+ public void testHashcodeNotEquals() throws Exception {
+ AnyLongObjectId id = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs = new LfsPointer(id, 4);
+ AnyLongObjectId id2 = LongObjectId.fromString(TEST_SHA256);
+ LfsPointer lfs2 = new LfsPointer(id2, 5);
+ assertNotEquals(lfs.hashCode(), lfs2.hashCode());
+ }
+}
diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LfsPointerFilterTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LfsPointerFilterTest.java
new file mode 100644
index 0000000000..081a4a50a4
--- /dev/null
+++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LfsPointerFilterTest.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2015, Dariusz Luksza <dariusz@luksza.org> 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.lfs.lib;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
+import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
+import org.eclipse.jgit.junit.TestRepository;
+import org.eclipse.jgit.revwalk.ObjectWalk;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevTree;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.junit.Test;
+
+public class LfsPointerFilterTest {
+
+ private static final int SIZE = 12345;
+
+ private static final String OID = "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393";
+
+ private static final String[] NOT_VALID_LFS_FILES = { "", // empty file
+ // simulate java file
+ "package org.eclipse.jgit;",
+ // invalid LFS pointer, no oid and version
+ "version https://hawser.github.com/spec/v1\n",
+ // invalid LFS pointer, no version
+ "version https://hawser.github.com/spec/v1\n"
+ + "oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\n",
+ // invalid LFS pointer, no id
+ "version https://hawser.github.com/spec/v1\n" + "size 12345\n",
+ // invalid LFS pointer, wrong order of oid and size
+ "version https://hawser.github.com/spec/v1\n" + "size 12345\n"
+ + "oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\n" };
+
+ private static final String[] LFS_VERSION_DOMAINS = {
+ "hawser", "git-lfs"
+ };
+
+ private static final String[] VALID_LFS_FILES = {
+ // valid LFS pointer
+ "version https://%s.github.com/spec/v1\n"
+ + "oid sha256:" + OID + "\n"
+ + "size " + SIZE + "\n",
+ // valid LFS pointer with "custom" key
+ "version https://%s.github.com/spec/v1\n"
+ + "custom key with value\n"
+ + "oid sha256:" + OID + "\n"
+ + "size " + SIZE + "\n",
+ // valid LFS pointer with key with "."
+ "version https://%s.github.com/spec/v1\n"
+ + "oid sha256:" + OID + "\n"
+ + "r.key key with .\n"
+ + "size " + SIZE + "\n",
+ // valid LFS pointer with key with "-"
+ "version https://%s.github.com/spec/v1\n"
+ + "oid sha256:" + OID + "\n"
+ + "size " + SIZE + "\n"
+ + "valid-name another valid key\n" };
+
+ @Test
+ public void testRegularFilesInRepositoryRoot() throws Exception {
+ for (String file : NOT_VALID_LFS_FILES) {
+ assertLfs("file.bin", file).withRecursive(false).shouldBe(false);
+ }
+ }
+
+ @Test
+ public void testNestedRegularFiles() throws Exception {
+ for (String file : NOT_VALID_LFS_FILES) {
+ assertLfs("a/file.bin", file).withRecursive(true).shouldBe(false);
+ }
+ }
+
+ @Test
+ public void testValidPointersInRepositoryRoot() throws Exception {
+ for (String domain : LFS_VERSION_DOMAINS) {
+ for (String file : VALID_LFS_FILES) {
+ assertLfs("file.bin", String.format(file, domain))
+ .withRecursive(true).shouldBe(true)
+ .check();
+ }
+ }
+ }
+
+ @Test
+ public void testValidNestedPointers() throws Exception {
+ for (String domain : LFS_VERSION_DOMAINS) {
+ for (String file : VALID_LFS_FILES) {
+ assertLfs("a/file.bin", String.format(file, domain))
+ .withRecursive(true).shouldBe(true).check();
+ }
+ }
+ }
+
+ @Test
+ public void testValidNestedPointersWithoutRecurrence() throws Exception {
+ for (String domain : LFS_VERSION_DOMAINS) {
+ for (String file : VALID_LFS_FILES) {
+ assertLfs("file.bin", String.format(file, domain))
+ .withRecursive(false).shouldBe(true).check();
+ assertLfs("a/file.bin", String.format(file, domain))
+ .withRecursive(false).shouldBe(false).check();
+ }
+ }
+ }
+
+ private static LfsTreeWalk assertLfs(String path, String content) {
+ return new LfsTreeWalk(path, content);
+ }
+
+ private static class LfsTreeWalk {
+ private final String path;
+
+ private final String content;
+
+ private boolean state;
+
+ private boolean recursive;
+
+ private TestRepository<InMemoryRepository> tr;
+
+ LfsTreeWalk(String path, String content) {
+ this.path = path;
+ this.content = content;
+ }
+
+ LfsTreeWalk withRecursive(boolean shouldBeRecursive) {
+ this.recursive = shouldBeRecursive;
+ return this;
+ }
+
+ LfsTreeWalk shouldBe(boolean shouldBeValid) {
+ this.state = shouldBeValid;
+ return this;
+ }
+
+ void check() throws Exception {
+ tr = new TestRepository<>(new InMemoryRepository(
+ new DfsRepositoryDescription("test")));
+ RevCommit commit = tr.branch("master").commit().add(path, content)
+ .message("initial commit").create();
+ RevTree tree = parseCommit(commit);
+ LfsPointerFilter filter = new LfsPointerFilter();
+ try (TreeWalk treeWalk = new TreeWalk(tr.getRepository())) {
+ treeWalk.addTree(tree);
+ treeWalk.setRecursive(recursive);
+ treeWalk.setFilter(filter);
+
+ if (state) {
+ assertTrue(treeWalk.next());
+ assertEquals(path, treeWalk.getPathString());
+ assertNotNull(filter.getPointer());
+ assertEquals(SIZE, filter.getPointer().getSize());
+ assertEquals(OID, filter.getPointer().getOid().name());
+ } else {
+ assertFalse(treeWalk.next());
+ assertNull(filter.getPointer());
+ }
+ }
+ }
+
+ private RevTree parseCommit(RevCommit commit) throws Exception {
+ try (ObjectWalk ow = new ObjectWalk(tr.getRepository())) {
+ return ow.parseCommit(commit).getTree();
+ }
+ }
+ }
+}
diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java
new file mode 100644
index 0000000000..a71d42367d
--- /dev/null
+++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java
@@ -0,0 +1,398 @@
+/*
+ * Copyright (C) 2015, Matthias Sohn <matthias.sohn@sap.com> 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.lfs.lib;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.nio.charset.StandardCharsets.US_ASCII;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Locale;
+
+import org.eclipse.jgit.junit.JGitTestUtil;
+import org.eclipse.jgit.lfs.errors.InvalidLongObjectIdException;
+import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils;
+import org.eclipse.jgit.util.FileUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/*
+ * Ported to SHA-256 from org.eclipse.jgit.lib.ObjectIdTest
+ */
+public class LongObjectIdTest {
+ private static Path tmp;
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ tmp = Files.createTempDirectory("jgit_test_");
+ }
+
+ @AfterClass
+ public static void tearDown() throws IOException {
+ FileUtils.delete(tmp.toFile(), FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
+
+ @Test
+ public void test001_toString() {
+ final String x = "8367b0edc81df80e6b42eb1b71f783111224e058cb3da37894d065d2deb7ab0a";
+ final LongObjectId oid = LongObjectId.fromString(x);
+ assertEquals(x, oid.name());
+ }
+
+ @Test
+ public void test002_toString() {
+ final String x = "140ce71d628cceb78e3709940ba52a651a0c4a9c1400f2e15e998a1a43887edf";
+ final LongObjectId oid = LongObjectId.fromString(x);
+ assertEquals(x, oid.name());
+ }
+
+ @Test
+ public void test003_equals() {
+ final String x = "8367b0edc81df80e6b42eb1b71f783111224e058cb3da37894d065d2deb7ab0a";
+ final LongObjectId a = LongObjectId.fromString(x);
+ final LongObjectId b = LongObjectId.fromString(x);
+ assertEquals(a.hashCode(), b.hashCode());
+ assertEquals("a and b should be equal", b, a);
+ }
+
+ @Test
+ public void test004_isId() {
+ assertTrue("valid id", LongObjectId.isId(
+ "8367b0edc81df80e6b42eb1b71f783111224e058cb3da37894d065d2deb7ab0a"));
+ }
+
+ @Test
+ public void test005_notIsId() {
+ assertFalse("bob is not an id", LongObjectId.isId("bob"));
+ }
+
+ @Test
+ public void test006_notIsId() {
+ assertFalse("63 digits is not an id", LongObjectId.isId(
+ "8367b0edc81df80e6b42eb1b71f783111224e058cb3da37894d065d2deb7ab0"));
+ }
+
+ @Test
+ public void test007_isId() {
+ assertTrue("uppercase is accepted", LongObjectId.isId(
+ "8367b0edc81df80e6b42eb1b71f783111224e058cb3da37894d065d2dEb7ab0A"));
+ }
+
+ @Test
+ public void test008_notIsId() {
+ assertFalse("g is not a valid hex digit", LongObjectId.isId(
+ "g367b0edc81df80e6b42eb1b71f783111224e058cb3da37894d065d2deb7ab0a"));
+ }
+
+ @Test
+ public void test009_toString() {
+ final String x = "140ce71d628cceb78e3709940ba52a651a0c4a9c1400f2e15e998a1a43887edf";
+ final LongObjectId oid = LongObjectId.fromString(x);
+ assertEquals(x, LongObjectId.toString(oid));
+ }
+
+ @Test
+ public void test010_toString() {
+ final String x = "0000000000000000000000000000000000000000000000000000000000000000";
+ assertEquals(x, LongObjectId.toString(null));
+ }
+
+ @Test
+ public void test011_toString() {
+ final String x = "0123456789ABCDEFabcdef01234567890123456789ABCDEFabcdef0123456789";
+ final LongObjectId oid = LongObjectId.fromString(x);
+ assertEquals(x.toLowerCase(Locale.ROOT), oid.name());
+ }
+
+ @Test
+ public void testGetByte() {
+ byte[] raw = new byte[32];
+ for (int i = 0; i < 32; i++)
+ raw[i] = (byte) (0xa0 + i);
+ LongObjectId id = LongObjectId.fromRaw(raw);
+
+ assertEquals(raw[0] & 0xff, id.getFirstByte());
+ assertEquals(raw[0] & 0xff, id.getByte(0));
+ assertEquals(raw[1] & 0xff, id.getByte(1));
+ assertEquals(raw[1] & 0xff, id.getSecondByte());
+
+ for (int i = 2; i < 32; i++) {
+ assertEquals("index " + i, raw[i] & 0xff, id.getByte(i));
+ }
+ try {
+ id.getByte(32);
+ fail("LongObjectId has 32 byte only");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testSetByte() {
+ byte[] exp = new byte[32];
+ for (int i = 0; i < 32; i++) {
+ exp[i] = (byte) (0xa0 + i);
+ }
+
+ MutableLongObjectId id = new MutableLongObjectId();
+ id.fromRaw(exp);
+ assertEquals(LongObjectId.fromRaw(exp).name(), id.name());
+
+ id.setByte(0, 0x10);
+ assertEquals(0x10, id.getByte(0));
+ exp[0] = 0x10;
+ assertEquals(LongObjectId.fromRaw(exp).name(), id.name());
+
+ for (int p = 1; p < 32; p++) {
+ id.setByte(p, 0x10 + p);
+ assertEquals(0x10 + p, id.getByte(p));
+ exp[p] = (byte) (0x10 + p);
+ assertEquals(LongObjectId.fromRaw(exp).name(), id.name());
+ }
+
+ for (int p = 0; p < 32; p++) {
+ id.setByte(p, 0x80 + p);
+ assertEquals(0x80 + p, id.getByte(p));
+ exp[p] = (byte) (0x80 + p);
+ assertEquals(LongObjectId.fromRaw(exp).name(), id.name());
+ }
+ }
+
+ @Test
+ public void testZeroId() {
+ AnyLongObjectId zero = new LongObjectId(0L, 0L, 0L, 0L);
+ assertEquals(zero, LongObjectId.zeroId());
+ assertEquals(
+ "0000000000000000000000000000000000000000000000000000000000000000",
+ LongObjectId.zeroId().name());
+ }
+
+ @Test
+ public void testEquals() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ assertTrue("id should equal itself", id1.equals(id1));
+ AnyLongObjectId id2 = new LongObjectId(id1);
+ assertEquals("objects should be equals", id1, id2);
+
+ id2 = LongObjectIdTestUtils.hash("other");
+ assertNotEquals("objects should be not equal", id1, id2);
+ }
+
+ @Test
+ public void testCopyRawBytes() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ AnyLongObjectId id2 = new LongObjectId(id1);
+
+ byte[] buf = new byte[64];
+ id1.copyRawTo(buf, 0);
+ id2.copyRawTo(buf, 32);
+ assertTrue("objects should be equals",
+ LongObjectId.equals(buf, 0, buf, 32));
+ }
+
+ @Test
+ public void testCopyRawLongs() {
+ long[] a = new long[4];
+ a[0] = 1L;
+ a[1] = 2L;
+ a[2] = 3L;
+ a[3] = 4L;
+ AnyLongObjectId id1 = new LongObjectId(a[0], a[1], a[2], a[3]);
+ AnyLongObjectId id2 = LongObjectId.fromRaw(a);
+ assertEquals("objects should be equals", id1, id2);
+ }
+
+ @Test
+ public void testCopyFromStringInvalid() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ try {
+ LongObjectId.fromString(id1.name() + "01234");
+ fail("expected InvalidLongObjectIdException");
+ } catch (InvalidLongObjectIdException e) {
+ assertEquals("Invalid id: " + id1.name() + "01234",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testCopyFromStringByte() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ byte[] buf = new byte[64];
+ Charset cs = US_ASCII;
+ cs.encode(id1.name()).get(buf);
+ AnyLongObjectId id2 = LongObjectId.fromString(buf, 0);
+ assertEquals("objects should be equals", id1, id2);
+ }
+
+ @Test
+ public void testHashFile() throws IOException {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ Path f = tmp.resolve("test");
+ JGitTestUtil.write(f.toFile(), "test");
+ AnyLongObjectId id2 = LongObjectIdTestUtils.hash(f);
+ assertEquals("objects should be equals", id1, id2);
+ }
+
+ @Test
+ public void testCompareTo() {
+ AnyLongObjectId id1 = LongObjectId.fromString(
+ "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
+ assertEquals(0, id1.compareTo(LongObjectId.fromString(
+ "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")));
+ AnyLongObjectId self = id1;
+ assertEquals(0, id1.compareTo(self));
+
+ assertEquals(-1, id1.compareTo(LongObjectId.fromString(
+ "1123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")));
+ assertEquals(-1, id1.compareTo(LongObjectId.fromString(
+ "0123456789abcdef1123456789abcdef0123456789abcdef0123456789abcdef")));
+ assertEquals(-1, id1.compareTo(LongObjectId.fromString(
+ "0123456789abcdef0123456789abcdef1123456789abcdef0123456789abcdef")));
+ assertEquals(-1, id1.compareTo(LongObjectId.fromString(
+ "0123456789abcdef0123456789abcdef0123456789abcdef1123456789abcdef")));
+
+ assertEquals(1, id1.compareTo(LongObjectId.fromString(
+ "0023456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")));
+ assertEquals(1, id1.compareTo(LongObjectId.fromString(
+ "0123456789abcdef0023456789abcdef0123456789abcdef0123456789abcdef")));
+ assertEquals(1, id1.compareTo(LongObjectId.fromString(
+ "0123456789abcdef0123456789abcdef0023456789abcdef0123456789abcdef")));
+ assertEquals(1, id1.compareTo(LongObjectId.fromString(
+ "0123456789abcdef0123456789abcdef0123456789abcdef0023456789abcdef")));
+ }
+
+ @Test
+ public void testCompareToByte() {
+ AnyLongObjectId id1 = LongObjectId.fromString(
+ "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
+ byte[] buf = new byte[32];
+ id1.copyRawTo(buf, 0);
+ assertEquals(0, id1.compareTo(buf, 0));
+
+ LongObjectId
+ .fromString(
+ "1123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
+ .copyRawTo(buf, 0);
+ assertEquals(-1, id1.compareTo(buf, 0));
+
+ LongObjectId
+ .fromString(
+ "0023456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
+ .copyRawTo(buf, 0);
+ assertEquals(1, id1.compareTo(buf, 0));
+ }
+
+ @Test
+ public void testCompareToLong() {
+ AnyLongObjectId id1 = new LongObjectId(1L, 2L, 3L, 4L);
+ long[] buf = new long[4];
+ id1.copyRawTo(buf, 0);
+ assertEquals(0, id1.compareTo(buf, 0));
+
+ new LongObjectId(2L, 2L, 3L, 4L).copyRawTo(buf, 0);
+ assertEquals(-1, id1.compareTo(buf, 0));
+
+ new LongObjectId(0L, 2L, 3L, 4L).copyRawTo(buf, 0);
+ assertEquals(1, id1.compareTo(buf, 0));
+ }
+
+ @Test
+ public void testCopyToByte() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ byte[] buf = new byte[64];
+ id1.copyTo(buf, 0);
+ assertEquals(id1, LongObjectId.fromString(buf, 0));
+ }
+
+ @Test
+ public void testCopyRawToByteBuffer() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ ByteBuffer buf = ByteBuffer.allocate(32);
+ id1.copyRawTo(buf);
+ assertEquals(id1, LongObjectId.fromRaw(buf.array(), 0));
+ }
+
+ @Test
+ public void testCopyToByteBuffer() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ ByteBuffer buf = ByteBuffer.allocate(64);
+ id1.copyTo(buf);
+ assertEquals(id1, LongObjectId.fromString(buf.array(), 0));
+ }
+
+ @Test
+ public void testCopyRawToOutputStream() throws IOException {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ ByteArrayOutputStream os = new ByteArrayOutputStream(32);
+ id1.copyRawTo(os);
+ assertEquals(id1, LongObjectId.fromRaw(os.toByteArray(), 0));
+ }
+
+ @Test
+ public void testCopyToOutputStream() throws IOException {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ ByteArrayOutputStream os = new ByteArrayOutputStream(64);
+ id1.copyTo(os);
+ assertEquals(id1, LongObjectId.fromString(os.toByteArray(), 0));
+ }
+
+ @Test
+ public void testCopyToWriter() throws IOException {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ ByteArrayOutputStream os = new ByteArrayOutputStream(64);
+ try (OutputStreamWriter w = new OutputStreamWriter(os,
+ UTF_8)) {
+ id1.copyTo(w);
+ }
+ assertEquals(id1, LongObjectId.fromString(os.toByteArray(), 0));
+ }
+
+ @Test
+ public void testCopyToWriterWithBuf() throws IOException {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ ByteArrayOutputStream os = new ByteArrayOutputStream(64);
+ try (OutputStreamWriter w = new OutputStreamWriter(os,
+ UTF_8)) {
+ char[] buf = new char[64];
+ id1.copyTo(buf, w);
+ }
+ assertEquals(id1, LongObjectId.fromString(os.toByteArray(), 0));
+ }
+
+ @Test
+ public void testCopyToStringBuilder() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ StringBuilder sb = new StringBuilder();
+ char[] buf = new char[64];
+ id1.copyTo(buf, sb);
+ assertEquals(id1, LongObjectId.fromString(sb.toString()));
+ }
+
+ @Test
+ public void testCopy() {
+ AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test");
+ assertEquals(id1.copy(), id1);
+ MutableLongObjectId id2 = new MutableLongObjectId();
+ id2.fromObjectId(id1);
+ assertEquals(id1, id2.copy());
+ }
+}
diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/MutableLongObjectIdTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/MutableLongObjectIdTest.java
new file mode 100644
index 0000000000..8c19cd714f
--- /dev/null
+++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/MutableLongObjectIdTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2015, Matthias Sohn <matthias.sohn@sap.com> 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.lfs.lib;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/*
+ * Ported to SHA-256 from org.eclipse.jgit.lib.MutableObjectIdTest
+ */
+public class MutableLongObjectIdTest {
+
+ @Test
+ public void testFromRawLong() {
+ MutableLongObjectId m = new MutableLongObjectId();
+ m.fromRaw(new long[] { 1L, 2L, 3L, 4L });
+ assertEquals(new LongObjectId(1L, 2L, 3L, 4L), m);
+ }
+
+ @Test
+ public void testFromString() {
+ AnyLongObjectId id = new LongObjectId(1L, 2L, 3L, 4L);
+ MutableLongObjectId m = new MutableLongObjectId();
+ m.fromString(id.name());
+ assertEquals(id, m);
+ }
+
+ @Test
+ public void testFromStringByte() {
+ AnyLongObjectId id = new LongObjectId(1L, 2L, 3L, 4L);
+ MutableLongObjectId m = new MutableLongObjectId();
+ byte[] buf = new byte[64];
+ id.copyTo(buf, 0);
+ m.fromString(buf, 0);
+ assertEquals(id, m);
+ }
+
+ @Test
+ public void testCopy() {
+ MutableLongObjectId m = new MutableLongObjectId();
+ m.fromRaw(new long[] { 1L, 2L, 3L, 4L });
+ assertEquals(m, new MutableLongObjectId(m));
+ }
+
+ @Test
+ public void testToObjectId() {
+ MutableLongObjectId m = new MutableLongObjectId();
+ m.fromRaw(new long[] { 1L, 2L, 3L, 4L });
+ assertEquals(m, m.toObjectId());
+ }
+}
ption> Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/tests/ThemingDefaultsTest.php
blob: b8b6c6869cd513e029947b185ad14797817b68b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
<?php
/**
 * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Theming\Tests;

use OCA\Theming\ImageManager;
use OCA\Theming\Service\BackgroundService;
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
use OCP\App\IAppManager;
use OCP\Files\NotFoundException;
use OCP\IAppConfig;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class ThemingDefaultsTest extends TestCase {
	private IAppConfig&MockObject $appConfig;
	private IConfig&MockObject $config;
	private \OC_Defaults $defaults;

	/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
	private $l10n;
	/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
	private $userSession;
	/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
	private $urlGenerator;
	/** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
	private $cacheFactory;
	/** @var ThemingDefaults */
	private $template;
	/** @var Util|\PHPUnit\Framework\MockObject\MockObject */
	private $util;
	/** @var ICache|\PHPUnit\Framework\MockObject\MockObject */
	private $cache;
	/** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
	private $appManager;
	/** @var ImageManager|\PHPUnit\Framework\MockObject\MockObject */
	private $imageManager;
	/** @var INavigationManager|\PHPUnit\Framework\MockObject\MockObject */
	private $navigationManager;
	/** @var BackgroundService|\PHPUnit\Framework\MockObject\MockObject */
	private $backgroundService;

	protected function setUp(): void {
		parent::setUp();
		$this->appConfig = $this->createMock(IAppConfig::class);
		$this->config = $this->createMock(IConfig::class);
		$this->l10n = $this->createMock(IL10N::class);
		$this->userSession = $this->createMock(IUserSession::class);
		$this->urlGenerator = $this->createMock(IURLGenerator::class);
		$this->cacheFactory = $this->createMock(ICacheFactory::class);
		$this->cache = $this->createMock(ICache::class);
		$this->util = $this->createMock(Util::class);
		$this->imageManager = $this->createMock(ImageManager::class);
		$this->appManager = $this->createMock(IAppManager::class);
		$this->navigationManager = $this->createMock(INavigationManager::class);
		$this->backgroundService = $this->createMock(BackgroundService::class);
		$this->defaults = new \OC_Defaults();
		$this->urlGenerator
			->expects($this->any())
			->method('getBaseUrl')
			->willReturn('');
		$this->template = new ThemingDefaults(
			$this->config,
			$this->appConfig,
			$this->l10n,
			$this->userSession,
			$this->urlGenerator,
			$this->cacheFactory,
			$this->util,
			$this->imageManager,
			$this->appManager,
			$this->navigationManager,
			$this->backgroundService,
		);
	}

	public function testGetNameWithDefault(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'name', 'Nextcloud')
			->willReturn('Nextcloud');

		$this->assertEquals('Nextcloud', $this->template->getName());
	}

	public function testGetNameWithCustom(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'name', 'Nextcloud')
			->willReturn('MyCustomCloud');

		$this->assertEquals('MyCustomCloud', $this->template->getName());
	}

	public function testGetHTMLNameWithDefault(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'name', 'Nextcloud')
			->willReturn('Nextcloud');

		$this->assertEquals('Nextcloud', $this->template->getHTMLName());
	}

	public function testGetHTMLNameWithCustom(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'name', 'Nextcloud')
			->willReturn('MyCustomCloud');

		$this->assertEquals('MyCustomCloud', $this->template->getHTMLName());
	}

	public function testGetTitleWithDefault(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'name', 'Nextcloud')
			->willReturn('Nextcloud');

		$this->assertEquals('Nextcloud', $this->template->getTitle());
	}

	public function testGetTitleWithCustom(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'name', 'Nextcloud')
			->willReturn('MyCustomCloud');

		$this->assertEquals('MyCustomCloud', $this->template->getTitle());
	}


	public function testGetEntityWithDefault(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'name', 'Nextcloud')
			->willReturn('Nextcloud');

		$this->assertEquals('Nextcloud', $this->template->getEntity());
	}

	public function testGetEntityWithCustom(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'name', 'Nextcloud')
			->willReturn('MyCustomCloud');

		$this->assertEquals('MyCustomCloud', $this->template->getEntity());
	}

	public function testGetBaseUrlWithDefault(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'url', $this->defaults->getBaseUrl())
			->willReturn($this->defaults->getBaseUrl());

		$this->assertEquals($this->defaults->getBaseUrl(), $this->template->getBaseUrl());
	}

	public function testGetBaseUrlWithCustom(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'url', $this->defaults->getBaseUrl())
			->willReturn('https://example.com/');

		$this->assertEquals('https://example.com/', $this->template->getBaseUrl());
	}

	public function legalUrlProvider() {
		return [
			[ '' ],
			[ 'https://example.com/legal.html']
		];
	}

	/**
	 * @param $imprintUrl
	 * @dataProvider legalUrlProvider
	 */
	public function testGetImprintURL($imprintUrl): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'imprintUrl', '')
			->willReturn($imprintUrl);

		$this->assertEquals($imprintUrl, $this->template->getImprintUrl());
	}

	/**
	 * @param $privacyUrl
	 * @dataProvider legalUrlProvider
	 */
	public function testGetPrivacyURL($privacyUrl): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'privacyUrl', '')
			->willReturn($privacyUrl);

		$this->assertEquals($privacyUrl, $this->template->getPrivacyUrl());
	}

	public function testGetSloganWithDefault(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'slogan', $this->defaults->getSlogan())
			->willReturn($this->defaults->getSlogan());

		$this->assertEquals($this->defaults->getSlogan(), $this->template->getSlogan());
	}

	public function testGetSloganWithCustom(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'slogan', $this->defaults->getSlogan())
			->willReturn('My custom Slogan');

		$this->assertEquals('My custom Slogan', $this->template->getSlogan());
	}

	public function testGetShortFooter(): void {
		$this->config
			->expects($this->exactly(5))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
				['theming', 'name', 'Nextcloud', 'Name'],
				['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
				['theming', 'imprintUrl', '', ''],
				['theming', 'privacyUrl', '', ''],
			]);

		$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan', $this->template->getShortFooter());
	}

	public function testGetShortFooterEmptyUrl(): void {
		$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
		$this->config
			->expects($this->exactly(5))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'url', $this->defaults->getBaseUrl(), ''],
				['theming', 'name', 'Nextcloud', 'Name'],
				['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
				['theming', 'imprintUrl', '', ''],
				['theming', 'privacyUrl', '', ''],
			]);

		$this->assertEquals('<span class="entity-name">Name</span> – Slogan', $this->template->getShortFooter());
	}

	public function testGetShortFooterEmptySlogan(): void {
		$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
		$this->config
			->expects($this->exactly(5))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
				['theming', 'name', 'Nextcloud', 'Name'],
				['theming', 'slogan', $this->defaults->getSlogan(), ''],
				['theming', 'imprintUrl', '', ''],
				['theming', 'privacyUrl', '', ''],
			]);

		$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a>', $this->template->getShortFooter());
	}

	public function testGetShortFooterImprint(): void {
		$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
		$this->config
			->expects($this->exactly(5))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
				['theming', 'name', 'Nextcloud', 'Name'],
				['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
				['theming', 'imprintUrl', '', 'https://example.com/imprint'],
				['theming', 'privacyUrl', '', ''],
			]);

		$this->l10n
			->expects($this->any())
			->method('t')
			->willReturnArgument(0);

		$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan<br/><span class="footer__legal-links"><a href="https://example.com/imprint" class="legal" target="_blank" rel="noreferrer noopener">Legal notice</a></span>', $this->template->getShortFooter());
	}

	public function testGetShortFooterPrivacy(): void {
		$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
		$this->config
			->expects($this->exactly(5))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
				['theming', 'name', 'Nextcloud', 'Name'],
				['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
				['theming', 'imprintUrl', '', ''],
				['theming', 'privacyUrl', '', 'https://example.com/privacy'],
			]);

		$this->l10n
			->expects($this->any())
			->method('t')
			->willReturnArgument(0);

		$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan<br/><span class="footer__legal-links"><a href="https://example.com/privacy" class="legal" target="_blank" rel="noreferrer noopener">Privacy policy</a></span>', $this->template->getShortFooter());
	}

	public function testGetShortFooterAllLegalLinks(): void {
		$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
		$this->config
			->expects($this->exactly(5))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
				['theming', 'name', 'Nextcloud', 'Name'],
				['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
				['theming', 'imprintUrl', '', 'https://example.com/imprint'],
				['theming', 'privacyUrl', '', 'https://example.com/privacy'],
			]);

		$this->l10n
			->expects($this->any())
			->method('t')
			->willReturnArgument(0);

		$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan<br/><span class="footer__legal-links"><a href="https://example.com/imprint" class="legal" target="_blank" rel="noreferrer noopener">Legal notice</a> · <a href="https://example.com/privacy" class="legal" target="_blank" rel="noreferrer noopener">Privacy policy</a></span>', $this->template->getShortFooter());
	}

	public function invalidLegalUrlProvider() {
		return [
			['example.com/legal'],  # missing scheme
			['https:///legal'],     # missing host
		];
	}

	/**
	 * @param $invalidImprintUrl
	 * @dataProvider invalidLegalUrlProvider
	 */
	public function testGetShortFooterInvalidImprint($invalidImprintUrl): void {
		$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
		$this->config
			->expects($this->exactly(5))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
				['theming', 'name', 'Nextcloud', 'Name'],
				['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
				['theming', 'imprintUrl', '', $invalidImprintUrl],
				['theming', 'privacyUrl', '', ''],
			]);

		$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan', $this->template->getShortFooter());
	}

	/**
	 * @param $invalidPrivacyUrl
	 * @dataProvider invalidLegalUrlProvider
	 */
	public function testGetShortFooterInvalidPrivacy($invalidPrivacyUrl): void {
		$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
		$this->config
			->expects($this->exactly(5))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
				['theming', 'name', 'Nextcloud', 'Name'],
				['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
				['theming', 'imprintUrl', '', ''],
				['theming', 'privacyUrl', '', $invalidPrivacyUrl],
			]);

		$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan', $this->template->getShortFooter());
	}

	public function testGetColorPrimaryWithDefault(): void {
		$this->appConfig
			->expects(self::once())
			->method('getValueBool')
			->with('theming', 'disable-user-theming')
			->willReturn(false);
		$this->appConfig
			->expects(self::once())
			->method('getValueString')
			->with('theming', 'primary_color', '')
			->willReturn($this->defaults->getColorPrimary());

		$this->assertEquals($this->defaults->getColorPrimary(), $this->template->getColorPrimary());
	}

	public function testGetColorPrimaryWithCustom(): void {
		$this->appConfig
			->expects(self::once())
			->method('getValueBool')
			->with('theming', 'disable-user-theming')
			->willReturn(false);
		$this->appConfig
			->expects(self::once())
			->method('getValueString')
			->with('theming', 'primary_color', '')
			->willReturn('#fff');

		$this->assertEquals('#fff', $this->template->getColorPrimary());
	}

	public function dataGetColorPrimary() {
		return [
			'with fallback default' => [
				'disableTheming' => false,
				'primaryColor' => '',
				'userPrimaryColor' => '',
				'expected' => BackgroundService::DEFAULT_COLOR,
			],
			'with custom admin primary' => [
				'disableTheming' => false,
				'primaryColor' => '#aaa',
				'userPrimaryColor' => '',
				'expected' => '#aaa',
			],
			'with custom invalid admin primary' => [
				'disableTheming' => false,
				'primaryColor' => 'invalid',
				'userPrimaryColor' => '',
				'expected' => BackgroundService::DEFAULT_COLOR,
			],
			'with custom invalid user primary' => [
				'disableTheming' => false,
				'primaryColor' => '',
				'userPrimaryColor' => 'invalid-name',
				'expected' => BackgroundService::DEFAULT_COLOR,
			],
			'with custom user primary' => [
				'disableTheming' => false,
				'primaryColor' => '',
				'userPrimaryColor' => '#bbb',
				'expected' => '#bbb',
			],
			'with disabled user theming primary' => [
				'disableTheming' => true,
				'primaryColor' => '#aaa',
				'userPrimaryColor' => '#bbb',
				'expected' => '#aaa',
			],
		];
	}

	/**
	 * @dataProvider dataGetColorPrimary
	 */
	public function testGetColorPrimary(bool $disableTheming, string $primaryColor, string $userPrimaryColor, string $expected): void {
		$user = $this->createMock(IUser::class);
		$this->userSession->expects($this->any())
			->method('getUser')
			->willReturn($user);
		$user->expects($this->any())
			->method('getUID')
			->willReturn('user');
		$this->appConfig
			->expects(self::any())
			->method('getValueBool')
			->with('theming', 'disable-user-theming')
			->willReturn($disableTheming);
		$this->appConfig
			->expects(self::any())
			->method('getValueString')
			->with('theming', 'primary_color', '')
			->willReturn($primaryColor);
		$this->config
			->expects($this->any())
			->method('getUserValue')
			->with('user', 'theming', 'primary_color', '')
			->willReturn($userPrimaryColor);

		$this->assertEquals($expected, $this->template->getColorPrimary());
	}

	public function testSet(): void {
		$expectedCalls = [
			['theming', 'MySetting', 'MyValue'],
			['theming', 'cachebuster', 16],
		];
		$i = 0;
		$this->config
			->expects($this->exactly(2))
			->method('setAppValue')
			->willReturnCallback(function () use ($expectedCalls, &$i): void {
				$this->assertEquals($expectedCalls[$i], func_get_args());
				$i++;
			});
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'cachebuster', '0')
			->willReturn('15');
		$this->cacheFactory
			->expects($this->exactly(2))
			->method('createDistributed')
			->willReturnMap([
				['theming-', $this->cache],
				['imagePath', $this->cache],
			]);
		$this->cache
			->expects($this->any())
			->method('clear')
			->with('');
		$this->template->set('MySetting', 'MyValue');
	}

	public function testUndoName(): void {
		$this->config
			->expects($this->once())
			->method('deleteAppValue')
			->with('theming', 'name');
		$this->config
			->expects($this->exactly(2))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'cachebuster', '0', '15'],
				['theming', 'name', 'Nextcloud', 'Nextcloud'],
			]);
		$this->config
			->expects($this->once())
			->method('setAppValue')
			->with('theming', 'cachebuster', 16);

		$this->assertSame('Nextcloud', $this->template->undo('name'));
	}

	public function testUndoBaseUrl(): void {
		$this->config
			->expects($this->once())
			->method('deleteAppValue')
			->with('theming', 'url');
		$this->config
			->expects($this->exactly(2))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'cachebuster', '0', '15'],
				['theming', 'url', $this->defaults->getBaseUrl(), $this->defaults->getBaseUrl()],
			]);
		$this->config
			->expects($this->once())
			->method('setAppValue')
			->with('theming', 'cachebuster', 16);

		$this->assertSame($this->defaults->getBaseUrl(), $this->template->undo('url'));
	}

	public function testUndoSlogan(): void {
		$this->config
			->expects($this->once())
			->method('deleteAppValue')
			->with('theming', 'slogan');
		$this->config
			->expects($this->exactly(2))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'cachebuster', '0', '15'],
				['theming', 'slogan', $this->defaults->getSlogan(), $this->defaults->getSlogan()],
			]);
		$this->config
			->expects($this->once())
			->method('setAppValue')
			->with('theming', 'cachebuster', 16);

		$this->assertSame($this->defaults->getSlogan(), $this->template->undo('slogan'));
	}

	public function testUndoPrimaryColor(): void {
		$this->config
			->expects($this->once())
			->method('deleteAppValue')
			->with('theming', 'primary_color');
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'cachebuster', '0')
			->willReturn('15');
		$this->config
			->expects($this->once())
			->method('setAppValue')
			->with('theming', 'cachebuster', 16);

		$this->assertSame($this->defaults->getColorPrimary(), $this->template->undo('primary_color'));
	}

	public function testUndoDefaultAction(): void {
		$this->config
			->expects($this->once())
			->method('deleteAppValue')
			->with('theming', 'defaultitem');
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'cachebuster', '0')
			->willReturn('15');
		$this->config
			->expects($this->once())
			->method('setAppValue')
			->with('theming', 'cachebuster', 16);

		$this->assertSame('', $this->template->undo('defaultitem'));
	}

	public function testGetBackground(): void {
		$this->imageManager
			->expects($this->once())
			->method('getImageUrl')
			->with('background')
			->willReturn('custom-background?v=0');
		$this->assertEquals('custom-background?v=0', $this->template->getBackground());
	}

	private function getLogoHelper($withName, $useSvg) {
		$this->imageManager->expects($this->any())
			->method('getImage')
			->with('logo')
			->willThrowException(new NotFoundException());
		$this->config
			->expects($this->exactly(2))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'logoMime', '', ''],
				['theming', 'cachebuster', '0', '0'],
			]);
		$this->urlGenerator->expects($this->once())
			->method('imagePath')
			->with('core', $withName)
			->willReturn('core-logo');
		$this->assertEquals('core-logo?v=0', $this->template->getLogo($useSvg));
	}

	public function testGetLogoDefaultWithSvg(): void {
		$this->getLogoHelper('logo/logo.svg', true);
	}

	public function testGetLogoDefaultWithoutSvg(): void {
		$this->getLogoHelper('logo/logo.png', false);
	}

	public function testGetLogoCustom(): void {
		$this->config
			->expects($this->exactly(2))
			->method('getAppValue')
			->willReturnMap([
				['theming', 'logoMime', '', 'image/svg+xml'],
				['theming', 'cachebuster', '0', '0'],
			]);
		$this->urlGenerator->expects($this->once())
			->method('linkToRoute')
			->with('theming.Theming.getImage')
			->willReturn('custom-logo?v=0');
		$this->assertEquals('custom-logo' . '?v=0', $this->template->getLogo());
	}

	public function testGetScssVariablesCached(): void {
		$this->config->expects($this->any())->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('1');
		$this->cacheFactory->expects($this->once())
			->method('createDistributed')
			->with('theming-1-')
			->willReturn($this->cache);
		$this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(['foo' => 'bar']);
		$this->assertEquals(['foo' => 'bar'], $this->template->getScssVariables());
	}

	public function testGetScssVariables(): void {
		$this->config
			->expects($this->any())
			->method('getAppValue')
			->willReturnMap([
				['theming', 'cachebuster', '0', '0'],
				['theming', 'logoMime', '', 'jpeg'],
				['theming', 'backgroundMime', '', 'jpeg'],
				['theming', 'logoheaderMime', '', 'jpeg'],
				['theming', 'faviconMime', '', 'jpeg'],
			]);

		$this->appConfig
			->expects(self::atLeastOnce())
			->method('getValueString')
			->willReturnMap([
				['theming', 'primary_color', '', false, $this->defaults->getColorPrimary()],
				['theming', 'primary_color', $this->defaults->getColorPrimary(), false, $this->defaults->getColorPrimary()],
			]);

		$this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false);
		$this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa');
		$this->cacheFactory->expects($this->once())
			->method('createDistributed')
			->with('theming-0-')
			->willReturn($this->cache);
		$this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null);
		$this->imageManager->expects($this->exactly(4))
			->method('getImageUrl')
			->willReturnMap([
				['logo', 'custom-logo?v=0'],
				['logoheader', 'custom-logoheader?v=0'],
				['favicon', 'custom-favicon?v=0'],
				['background', 'custom-background?v=0'],
			]);

		$expected = [
			'theming-cachebuster' => '\'0\'',
			'theming-logo-mime' => '\'jpeg\'',
			'theming-background-mime' => '\'jpeg\'',
			'image-logo' => "url('custom-logo?v=0')",
			'image-login-background' => "url('custom-background?v=0')",
			'color-primary' => $this->defaults->getColorPrimary(),
			'color-primary-text' => '#ffffff',
			'image-login-plain' => 'false',
			'color-primary-element' => '#aaaaaa',
			'theming-logoheader-mime' => '\'jpeg\'',
			'theming-favicon-mime' => '\'jpeg\'',
			'image-logoheader' => "url('custom-logoheader?v=0')",
			'image-favicon' => "url('custom-favicon?v=0')",
			'has-legal-links' => 'false'
		];
		$this->assertEquals($expected, $this->template->getScssVariables());
	}

	public function testGetDefaultAndroidURL(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'AndroidClientUrl', 'https://play.google.com/store/apps/details?id=com.nextcloud.client')
			->willReturn('https://play.google.com/store/apps/details?id=com.nextcloud.client');

		$this->assertEquals('https://play.google.com/store/apps/details?id=com.nextcloud.client', $this->template->getAndroidClientUrl());
	}

	public function testGetCustomAndroidURL(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'AndroidClientUrl', 'https://play.google.com/store/apps/details?id=com.nextcloud.client')
			->willReturn('https://play.google.com/store/apps/details?id=com.mycloud.client');

		$this->assertEquals('https://play.google.com/store/apps/details?id=com.mycloud.client', $this->template->getAndroidClientUrl());
	}

	public function testGetDefaultiOSURL(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'iOSClientUrl', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8')
			->willReturn('https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8');

		$this->assertEquals('https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8', $this->template->getiOSClientUrl());
	}

	public function testGetCustomiOSURL(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'iOSClientUrl', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8')
			->willReturn('https://geo.itunes.apple.com/us/app/nextcloud/id1234567890?mt=8');

		$this->assertEquals('https://geo.itunes.apple.com/us/app/nextcloud/id1234567890?mt=8', $this->template->getiOSClientUrl());
	}

	public function testGetDefaultiTunesAppId(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'iTunesAppId', '1125420102')
			->willReturn('1125420102');

		$this->assertEquals('1125420102', $this->template->getiTunesAppId());
	}

	public function testGetCustomiTunesAppId(): void {
		$this->config
			->expects($this->once())
			->method('getAppValue')
			->with('theming', 'iTunesAppId', '1125420102')
			->willReturn('1234567890');

		$this->assertEquals('1234567890', $this->template->getiTunesAppId());
	}

	public function dataReplaceImagePath() {
		return [
			['core', 'test.png', false],
			['core', 'manifest.json'],
			['core', 'favicon.ico'],
			['core', 'favicon-touch.png']
		];
	}

	/** @dataProvider dataReplaceImagePath */
	public function testReplaceImagePath($app, $image, $result = 'themingRoute?v=1234abcd'): void {
		$this->cache->expects($this->any())
			->method('get')
			->with('shouldReplaceIcons')
			->willReturn(true);
		$this->config
			->expects($this->any())
			->method('getAppValue')
			->with('theming', 'cachebuster', '0')
			->willReturn('0');
		$this->urlGenerator
			->expects($this->any())
			->method('linkToRoute')
			->willReturn('themingRoute');
		if ($result) {
			$this->util
				->expects($this->once())
				->method('getCacheBuster')
				->willReturn('1234abcd');
		}
		$this->assertEquals($result, $this->template->replaceImagePath($app, $image));
	}
}