Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge separated ApacheNoticeResourceTransformerTest #1063

Merged
merged 4 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@

package com.github.jengelman.gradle.plugins.shadow.transformers

import com.github.jengelman.gradle.plugins.shadow.ShadowStats
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

import static org.junit.jupiter.api.Assertions.assertFalse
import static org.junit.jupiter.api.Assertions.assertTrue
import static org.junit.jupiter.api.Assertions.fail

/**
* Test for {@link ApacheNoticeResourceTransformer}.
* Tests {@link ApacheLicenseResourceTransformer} parameters.
*
* @author Benjamin Bentmann
* @version $Id: ApacheNoticeResourceTransformerTest.java 673906 2008-07-04 05:03:20Z brett $
*
* Modified from org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformerTest.java
* Modified from org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformerParameterTests.java
*/
class ApacheNoticeResourceTransformerTest extends TransformerTestSupport<ApacheNoticeResourceTransformer> {

private static final String NOTICE_RESOURCE = "META-INF/NOTICE"
private static ShadowStats stats

static {
/*
* NOTE: The Turkish locale has an usual case transformation for the letters "I" and "i", making it a prime
Expand All @@ -46,14 +49,62 @@ class ApacheNoticeResourceTransformerTest extends TransformerTestSupport<ApacheN
@BeforeEach
void setUp() {
transformer = new ApacheNoticeResourceTransformer(objectFactory)
stats = new ShadowStats()
}

@Test
void testCanTransformResource() {
assertTrue(transformer.canTransformResource(getFileElement("META-INF/NOTICE")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/NOTICE.TXT")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/Notice.txt")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/NOTICE.md")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/Notice.md")))
assertFalse(transformer.canTransformResource(getFileElement("META-INF/MANIFEST.MF")))
}

@Test
void testNoParametersShouldNotThrowNullPointerWhenNoInput() {
processAndFailOnNullPointer("")
}

@Test
void testNoParametersShouldNotThrowNullPointerWhenNoLinesOfInput() {
processAndFailOnNullPointer("Some notice text")
}

@Test
void testNoParametersShouldNotThrowNullPointerWhenOneLineOfInput() {
processAndFailOnNullPointer("Some notice text\n")
}

@Test
void testNoParametersShouldNotThrowNullPointerWhenTwoLinesOfInput() {
processAndFailOnNullPointer("Some notice text\nSome notice text\n")
}

@Test
void testNoParametersShouldNotThrowNullPointerWhenLineStartsWithSlashSlash() {
processAndFailOnNullPointer("Some notice text\n//Some notice text\n")
}

@Test
void testNoParametersShouldNotThrowNullPointerWhenLineIsSlashSlash() {
processAndFailOnNullPointer("//\n")
}

@Test
void testNoParametersShouldNotThrowNullPointerWhenLineIsEmpty() {
processAndFailOnNullPointer("\n")
}

private static void processAndFailOnNullPointer(final String noticeText) {
try {
final ByteArrayInputStream noticeInputStream = new ByteArrayInputStream(noticeText.getBytes())
final List<Relocator> emptyList = Collections.emptyList()
transformer.transform(TransformerContext.builder().path(NOTICE_RESOURCE).inputStream(noticeInputStream).relocators(emptyList).stats(stats).build())
}
catch (NullPointerException ignored) {
fail("Null pointer should not be thrown when no parameters are set.")
}
}
}