@@ -11,6 +11,8 @@ import java.util.zip.ZipFile
11
11
12
12
import static java.util.Collections.singletonList
13
13
import static org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE
14
+ import static org.junit.Assert.assertFalse
15
+ import static org.junit.Assert.assertTrue
14
16
15
17
/**
16
18
* @author Paul Nelson Baker
@@ -51,31 +53,34 @@ class Log4j2PluginsCacheFileTransformerTest {
51
53
void testRelocate (String source , String pattern , String target ) throws IOException {
52
54
List<Relocator > relocators = singletonList((Relocator ) new SimpleRelocator (source, pattern, null , null ))
53
55
transformer. transform(new TransformerContext (PLUGIN_CACHE_FILE , getResourceStream(PLUGIN_CACHE_FILE ), relocators))
54
- assertTrue (transformer . hasTransformedResource(), " Transformer didn't transform resources" )
56
+ assertTrue (" Transformer didn't transform resources" , transformer . hasTransformedResource() )
55
57
// Write out to a fake jar file
56
- File . createTempFile(" testable-zip-file-" , " .jar" ). withCloseable { testableZipFile ->
57
- new FileOutputStream (testableZipFile). withCloseable { fileOutputStream ->
58
- new BufferedOutputStream (fileOutputStream). withCloseable { bufferedOutputStream ->
59
- new ZipOutputStream (bufferedOutputStream). withCloseable { zipOutputStream ->
60
- transformer. modifyOutputStream(zipOutputStream)
61
- }
62
- }
63
- }
64
- }
58
+ def testableZipFile = File . createTempFile(" testable-zip-file-" , " .jar" )
59
+ def fileOutputStream = new FileOutputStream (testableZipFile)
60
+ def bufferedOutputStream = new BufferedOutputStream (fileOutputStream)
61
+ def zipOutputStream = new ZipOutputStream (bufferedOutputStream)
62
+ transformer. modifyOutputStream(zipOutputStream)
63
+ zipOutputStream. close()
64
+ bufferedOutputStream. close()
65
+ fileOutputStream. close()
65
66
// Pull the data back out and make sure it was transformed
66
67
ZipFile zipFile = new ZipFile (testableZipFile)
67
68
ZipEntry zipFileEntry = zipFile. getEntry(PLUGIN_CACHE_FILE )
68
69
InputStream inputStream = zipFile. getInputStream(zipFileEntry)
69
- new Scanner (inputStream). withReader { scanner ->
70
+ new Scanner (inputStream). withCloseable { scanner ->
70
71
boolean hasAtLeastOneTransform = false
71
72
while (scanner. hasNextLine()) {
72
73
String nextLine = scanner. nextLine()
73
74
if (nextLine. contains(source)) {
74
75
hasAtLeastOneTransform = true
75
- assertTrue (nextLine . contains(target), " Target wasn't included in transform" )
76
+ assertTrue (" Target wasn't included in transform" , nextLine . contains(target) )
76
77
}
77
78
}
78
- assertTrue (hasAtLeastOneTransform, " There were no transformations inside the file" )
79
+ assertTrue (" There were no transformations inside the file" , hasAtLeastOneTransform )
79
80
}
80
81
}
82
+
83
+ InputStream getResourceStream (String resource ) {
84
+ return this . class. getClassLoader(). getResourceAsStream(resource);
85
+ }
81
86
}
0 commit comments