AgentPremain { @SuppressWarnings("return.type.incompatible") static File getGlowrootJarFile(CodeSource codeSource) throws Exception { if (codeSource == null) { if (System.getProperty("glowroot.test.dir") != null) { return null; } throw new IOException("Could not determine glowroot jar location"); } File codeSourceFile = new File(codeSource.getLocation().toURI()); if (codeSourceFile.getName().endsWith(".jar")) { return codeSourceFile; } if (System.getProperty("glowroot.test.dir") != null) { return null; } throw new IOException("Could not determine glowroot jar location"); } private  AgentPremain(); static void premain(@SuppressWarnings("unused") String agentArgs,
            Instrumentation instrumentation);  }
@Test public void testNullCodeSource() throws Exception { thrown.expect(IOException.class); AgentPremain.getGlowrootJarFile(null); }
@Test public void testNullCodeSourceWithDelegateJavaagent() throws Exception { System.setProperty("glowroot.test.dir", "."); try { assertThat(AgentPremain.getGlowrootJarFile(null)).isNull(); } finally { System.clearProperty("glowroot.test.dir"); } }
@Test public void testWithGlowrootJar() throws Exception { File glowrootJar = new File("x/glowroot.jar").getAbsoluteFile(); CodeSource codeSource = new CodeSource(glowrootJar.toURI().toURL(), new Certificate[0]); assertThat(AgentPremain.getGlowrootJarFile(codeSource)).isEqualTo(glowrootJar); }
@Test public void testWithNotGlowrootJar() throws Exception { thrown.expect(IOException.class); File glowrootJar = new File("x/classes"); CodeSource codeSource = new CodeSource(glowrootJar.toURI().toURL(), new Certificate[0]); AgentPremain.getGlowrootJarFile(codeSource); }
@Test public void testWithNotGlowrootJarButWithTestDir() throws Exception { System.setProperty("glowroot.test.dir", "."); try { File glowrootJar = new File("x/classes"); CodeSource codeSource = new CodeSource(glowrootJar.toURI().toURL(), new Certificate[0]); assertThat(AgentPremain.getGlowrootJarFile(codeSource)).isNull(); } finally { System.clearProperty("glowroot.test.dir"); } }