Skip to content
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
4 changes: 4 additions & 0 deletions src/test/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*.{groovy,java}]
indent_size = 2
Original file line number Diff line number Diff line change
@@ -1,53 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License") you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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

import org.junit.jupiter.api.Test

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


/**
* Modified from org.apache.maven.plugins.shade.relocation.SimpleRelocatorParameterTest.java
*
* Modifications
* @author John Engelman
*/
class SimpleRelocatorParameterTest {

@Test
void testThatNullPatternInConstructorShouldNotThrowNullPointerException() {
constructThenFailOnNullPointerException(null, "")
}
@Test
void testThatNullPatternInConstructorShouldNotThrowNullPointerException() {
constructThenFailOnNullPointerException(null, "")
}

@Test
void testThatNullShadedPatternInConstructorShouldNotThrowNullPointerException() {
constructThenFailOnNullPointerException("", null)
}
@Test
void testThatNullShadedPatternInConstructorShouldNotThrowNullPointerException() {
constructThenFailOnNullPointerException("", null)
}

private static void constructThenFailOnNullPointerException(String pattern, String shadedPattern) {
try {
new SimpleRelocator(pattern, shadedPattern)
}
catch (NullPointerException ignored) {
fail("Constructor should not throw null pointer exceptions")
}
private static void constructThenFailOnNullPointerException(String pattern, String shadedPattern) {
try {
new SimpleRelocator(pattern, shadedPattern)
}
catch (NullPointerException ignored) {
fail("Constructor should not throw null pointer exceptions")
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License") you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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

import org.junit.jupiter.api.BeforeEach
Expand All @@ -26,32 +7,26 @@ import static org.junit.jupiter.api.Assertions.assertFalse
import static org.junit.jupiter.api.Assertions.assertTrue

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

static {
setupTurkishLocale()
}

@BeforeEach
void setUp() {
transformer = new ApacheLicenseResourceTransformer()
}

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

static {
setupTurkishLocale()
}

@BeforeEach
void setUp() {
transformer = new ApacheLicenseResourceTransformer()
}

@Test
void testCanTransformResource() {
assertTrue(transformer.canTransformResource(getFileElement("META-INF/LICENSE")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/LICENSE.TXT")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/License.txt")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/LICENSE.md")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/License.md")))
assertFalse(transformer.canTransformResource(getFileElement("META-INF/MANIFEST.MF")))
}
}
Original file line number Diff line number Diff line change
@@ -1,106 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License") you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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
import static org.junit.jupiter.api.Assertions.*

/**
* Tests {@link ApacheLicenseResourceTransformer} parameters.
*
* 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 {
setupTurkishLocale()
}

@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")
private static final String NOTICE_RESOURCE = "META-INF/NOTICE"
private static ShadowStats stats

static {
setupTurkishLocale()
}

@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())
}

@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.")
}
catch (NullPointerException ignored) {
fail("Null pointer should not be thrown when no parameters are set.")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License") you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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

import org.junit.jupiter.api.BeforeEach
Expand All @@ -26,29 +7,26 @@ import static org.junit.jupiter.api.Assertions.assertFalse
import static org.junit.jupiter.api.Assertions.assertTrue

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

static {
setupTurkishLocale()
}
static {
setupTurkishLocale()
}

@BeforeEach
void setUp() {
transformer = new AppendingTransformer(objectFactory)
}
@BeforeEach
void setUp() {
transformer = new AppendingTransformer(objectFactory)
}

@Test
void testCanTransformResource() {
transformer.resource.set("abcdefghijklmnopqrstuvwxyz")
@Test
void testCanTransformResource() {
transformer.resource.set("abcdefghijklmnopqrstuvwxyz")

assertTrue(transformer.canTransformResource(getFileElement("abcdefghijklmnopqrstuvwxyz")))
assertTrue(transformer.canTransformResource(getFileElement("ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
assertFalse(transformer.canTransformResource(getFileElement("META-INF/MANIFEST.MF")))
}
assertTrue(transformer.canTransformResource(getFileElement("abcdefghijklmnopqrstuvwxyz")))
assertTrue(transformer.canTransformResource(getFileElement("ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
assertFalse(transformer.canTransformResource(getFileElement("META-INF/MANIFEST.MF")))
}

}
Loading