PolicyUpdater { static void verifyTmpDirSetup(PolicyUpdaterConfiguration configuration) throws IOException { String policyTmpDir = configuration.getPolicyFileTmpDir(); Path tmpDir = Paths.get(policyTmpDir); if (java.nio.file.Files.exists(tmpDir)) { return; } LOG.warn("The temp dir doesnt exist so will create it: " + tmpDir); java.nio.file.Files.createDirectory(tmpDir); String user = configuration.getZpuDirOwner(); if (user == null) { LOG.warn("Cannot chown of the temp dir: " + tmpDir + " : no configured user"); return; } try { java.nio.file.attribute.UserPrincipalLookupService lookupSvc = java.nio.file.FileSystems.getDefault().getUserPrincipalLookupService(); java.nio.file.attribute.UserPrincipal uprinc = lookupSvc.lookupPrincipalByName(user); Files.setOwner(tmpDir, uprinc); } catch (Exception exc) { LOG.warn("Failed to chown of the temp dir: " + tmpDir + ", user: " + user + ", exc: " + exc.getMessage()); } }  static void main(String[] args); static void postDomainMetrics(ZTSClient zts); static final String ZPE_METRIC_FILE_PATH; static final String ZPE_PROP_METRIC_FILE_PATH; }
@Test public void TestverifyTmpDirSetupUserNull() throws Exception { PolicyUpdaterConfiguration config = Mockito.mock(PolicyUpdaterConfiguration.class); Mockito.when(config.getPolicyFileTmpDir()).thenReturn(pupConfig.getRootDir() + TEST_POLICY_TEMP_DIR + "/tmpnon"); Mockito.when(config.getZpuDirOwner()).thenReturn(null); boolean expectedCaught = true; try { PolicyUpdater.verifyTmpDirSetup(config); } catch (Exception e) { } Assert.assertTrue(expectedCaught); }