Home / Class/ ZipFileTarArchiveTests Class — spring-boot Architecture

ZipFileTarArchiveTests Class — spring-boot Architecture

Architecture documentation for the ZipFileTarArchiveTests class in ZipFileTarArchiveTests.java from the spring-boot codebase.

Entity Profile

Source Code

buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchiveTests.java lines 41–100

class ZipFileTarArchiveTests {

	@TempDir
	@SuppressWarnings("NullAway.Init")
	File tempDir;

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void createWhenZipIsNullThrowsException() {
		assertThatIllegalArgumentException().isThrownBy(() -> new ZipFileTarArchive(null, Owner.ROOT))
			.withMessage("'zip' must not be null");
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void createWhenOwnerIsNullThrowsException() throws Exception {
		File file = new File(this.tempDir, "test.zip");
		writeTestZip(file);
		assertThatIllegalArgumentException().isThrownBy(() -> new ZipFileTarArchive(file, null))
			.withMessage("'owner' must not be null");
	}

	@Test
	void writeToAdaptsContent() throws Exception {
		Owner owner = Owner.of(123, 456);
		File file = new File(this.tempDir, "test.zip");
		writeTestZip(file);
		TarArchive tarArchive = TarArchive.fromZip(file, owner);
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		tarArchive.writeTo(outputStream);
		try (TarArchiveInputStream tarStream = new TarArchiveInputStream(
				new ByteArrayInputStream(outputStream.toByteArray()))) {
			TarArchiveEntry dirEntry = tarStream.getNextEntry();
			assertThat(dirEntry.getName()).isEqualTo("spring/");
			assertThat(dirEntry.getLongUserId()).isEqualTo(123);
			assertThat(dirEntry.getLongGroupId()).isEqualTo(456);
			TarArchiveEntry fileEntry = tarStream.getNextEntry();
			assertThat(fileEntry.getName()).isEqualTo("spring/boot");
			assertThat(fileEntry.getLongUserId()).isEqualTo(123);
			assertThat(fileEntry.getLongGroupId()).isEqualTo(456);
			assertThat(fileEntry.getSize()).isEqualTo(4);
			assertThat(fileEntry.getMode()).isEqualTo(0755);
			assertThat(tarStream).hasContent("test");
		}
	}

	private void writeTestZip(File file) throws IOException {
		try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(file)) {
			ZipArchiveEntry dirEntry = new ZipArchiveEntry("spring/");
			zip.putArchiveEntry(dirEntry);
			zip.closeArchiveEntry();
			ZipArchiveEntry fileEntry = new ZipArchiveEntry("spring/boot");
			fileEntry.setUnixMode(0755);
			zip.putArchiveEntry(fileEntry);
			zip.write("test".getBytes(StandardCharsets.UTF_8));
			zip.closeArchiveEntry();
		}
	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free