Skip to content

Commit

Permalink
Test coverage for StaplerClosureScript._ (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Mar 21, 2022
1 parent 5609942 commit 97ab5d8
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kohsuke.stapler.jelly.groovy;

import java.io.ByteArrayOutputStream;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
Expand All @@ -10,6 +11,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -37,6 +39,30 @@ public void testFoo() throws IOException, JellyTagException {
Files.delete(tmp);
}
}

public void testGettext() throws Exception {
Path tmp = Files.createTempFile("xxx", ".groovy");

try {
MetaClassLoader mcl = webApp.getMetaClass(Foo.class).classLoader;
GroovyClassLoaderTearOff t = mcl.getTearOff(GroovyClassLoaderTearOff.class);

Files.write(tmp, "output.write(_('localizable'))".getBytes(StandardCharsets.UTF_8));
Files.write(tmp.resolveSibling(tmp.getFileName().toString().replaceFirst("[.]groovy$", ".properties")), "localizable=Localizable".getBytes(StandardCharsets.ISO_8859_1));

JellyContext context = new JellyContext();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutput w = XMLOutput.createXMLOutput(baos);
t.parse(tmp.toUri().toURL()).run(context, w);
w.close();
assertEquals("Localizable", baos.toString());
} catch (Exception x) {
x.printStackTrace();
throw x;
} finally {
Files.delete(tmp);
}
}

public static class Foo {}
}

0 comments on commit 97ab5d8

Please sign in to comment.