### Question:
ExploreServiceUtils { public static File patchHiveClasses(File sourceJar, File targetJar) throws IOException { try (JarFile input = new JarFile(sourceJar)) { boolean needPatch = false; for (String classFile : HIVE_CLASS_FILES_TO_PATCH.keySet()) { needPatch = needPatch || (input.getEntry(classFile) != null); } if (!needPatch) { return sourceJar; } try (JarOutputStream output = new JarOutputStream(new FileOutputStream(targetJar))) { Enumeration<JarEntry> sourceEntries = input.entries(); while (sourceEntries.hasMoreElements()) { JarEntry entry = sourceEntries.nextElement(); output.putNextEntry(new JarEntry(entry.getName())); try (InputStream entryInputStream = input.getInputStream(entry)) { Set<String> patchMethods = HIVE_CLASS_FILES_TO_PATCH.get(entry.getName()); if (patchMethods == null) { ByteStreams.copy(entryInputStream, output); continue; } output.write(Classes.rewriteMethodToNoop(entry.getName(), entryInputStream, patchMethods)); } } } return targetJar; } }  static Class<? extends ExploreService> getHiveService(CConfiguration cConf); static HiveSupport checkHiveSupport(CConfiguration cConf); static String getHiveVersion(); static HiveSupport checkHiveSupport(CConfiguration cConf, @Nullable ClassLoader hiveClassLoader); static File patchHiveClasses(File sourceJar, File targetJar); static boolean isSparkEngine(HiveConf hiveConf, @Nullable Map<String, String> sessionConf); static boolean isTezEngine(HiveConf hiveConf, @Nullable Map<String, String> sessionConf);  }### Answer:
@Test public void testRewriteHiveAuthFactory() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); URL hiveAuthURL = classLoader.getResource(HiveAuthFactory.class.getName().replace('.', '/') + ".class"); String hiveJarFilePath = hiveAuthURL.getPath(); File hiveJarFile = new File(URI.create(hiveJarFilePath.substring(0, hiveJarFilePath.indexOf("!/")))); File targetJar = ExploreServiceUtils.patchHiveClasses(hiveJarFile, new File(tmpFolder.newFolder(), "hive.jar")); try ( TestHiveAuthFactoryClassLoader cl = new TestHiveAuthFactoryClassLoader(targetJar, classLoader) ) { Class<?> hiveAuthFactoryClass = cl.loadClass(HiveAuthFactory.class.getName()); Method loginFromKeytab = hiveAuthFactoryClass.getMethod("loginFromKeytab", HiveConf.class); loginFromKeytab.invoke(null, new Object[] { null }); } String functionClassPath = classLoader.getResource(Function.class.getName().replace('.', '/') + ".class").getPath(); File guavaJarFile = new File(URI.create(functionClassPath.substring(0, functionClassPath.indexOf("!/")))); targetJar = ExploreServiceUtils.patchHiveClasses(guavaJarFile, new File(tmpFolder.newFolder(), "guava.jar")); Assert.assertSame(guavaJarFile, targetJar); }