|
| 1 | +package com.jakewharton.diffuse |
| 2 | + |
| 3 | +import assertk.assertThat |
| 4 | +import assertk.assertions.contains |
| 5 | +import assertk.assertions.doesNotContain |
| 6 | +import com.jakewharton.diffuse.diff.JarDiff |
| 7 | +import com.jakewharton.diffuse.diff.JarManifestDiff.Companion.MANIFEST_PATH |
| 8 | +import com.jakewharton.diffuse.format.ApiMapping |
| 9 | +import com.jakewharton.diffuse.format.Jar |
| 10 | +import com.jakewharton.diffuse.format.Jar.Companion.toJar |
| 11 | +import com.jakewharton.diffuse.io.Input.Companion.asInput |
| 12 | +import java.io.ByteArrayOutputStream |
| 13 | +import java.util.jar.JarOutputStream |
| 14 | +import java.util.zip.ZipEntry |
| 15 | +import okio.ByteString.Companion.toByteString |
| 16 | +import org.junit.Test |
| 17 | + |
| 18 | +class JarDiffTextReportTest { |
| 19 | + @Test |
| 20 | + fun manifestChanged() { |
| 21 | + val oldJar = jar("old.jar", "Manifest-Version: 1.0\nCreated-By: old") |
| 22 | + val newJar = jar("new.jar", "Manifest-Version: 1.0\nCreated-By: new") |
| 23 | + |
| 24 | + val report = |
| 25 | + JarDiff(oldJar, ApiMapping.EMPTY, newJar, ApiMapping.EMPTY).toTextReport(false).toString() |
| 26 | + |
| 27 | + assertThat(report) |
| 28 | + .contains( |
| 29 | + """ |
| 30 | + |====================== |
| 31 | + |==== MANIFEST ==== |
| 32 | + |====================== |
| 33 | + | |
| 34 | + |@@ -1,2 +1,2 @@ |
| 35 | + | Manifest-Version: 1.0 |
| 36 | + |-Created-By: old |
| 37 | + |+Created-By: new |
| 38 | + """ |
| 39 | + .trimMargin() |
| 40 | + ) |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + fun manifestNotChanged() { |
| 45 | + val oldJar = jar("old.jar", "Manifest-Version: 1.0\nCreated-By: same") |
| 46 | + val newJar = jar("new.jar", "Manifest-Version: 1.0\nCreated-By: same") |
| 47 | + |
| 48 | + val report = |
| 49 | + JarDiff(oldJar, ApiMapping.EMPTY, newJar, ApiMapping.EMPTY).toTextReport(false).toString() |
| 50 | + |
| 51 | + assertThat(report).doesNotContain("==== MANIFEST ====") |
| 52 | + } |
| 53 | + |
| 54 | + private fun jar(name: String, manifestContent: String): Jar { |
| 55 | + val bytes = ByteArrayOutputStream() |
| 56 | + JarOutputStream(bytes).use { jar -> |
| 57 | + jar.putNextEntry(ZipEntry(MANIFEST_PATH)) |
| 58 | + jar.write(manifestContent.toByteArray()) |
| 59 | + jar.closeEntry() |
| 60 | + } |
| 61 | + return bytes.toByteArray().toByteString().asInput(name).toJar() |
| 62 | + } |
| 63 | +} |
0 commit comments