NotificationToEmailConverterCommon { public String readContentFromFile(ClassLoader classLoader, String fileName) { StringBuilder contents = new StringBuilder(); URL resource = classLoader.getResource(fileName); if (resource != null) { try (BufferedReader br = new BufferedReader(new InputStreamReader(resource.openStream()))) { String line; while ((line = br.readLine()) != null) { contents.append(line); contents.append(System.getProperty("line.separator")); } } catch (IOException ex) { LOGGER.error("Could not read file: {}. Error message: {}", fileName, ex.getMessage()); } } return contents.toString(); } NotificationToEmailConverterCommon(); String readContentFromFile(ClassLoader classLoader, String fileName); String generateBodyFromTemplate(Map<String, String> metaDetails,
                                            String bodyTemplate,
                                            String bodyTemplateDetails,
                                            String tableValuesKey,
                                            int tableEntryNumColumns); String getTableEntryTemplate(int numOfColumns); String addCssStyleToBody(String body); String getSubject(String propertyName); Set<String> getFullyQualifiedEmailAddresses(Set<String> recipients); String getWorkflowUrl(); String getAthenzUIUrl();  }
@Test public void testReadContentFromFile() { NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(); assertTrue(notificationToEmailConverterCommon.readContentFromFile(getClass().getClassLoader(), "resources/non-existent").isEmpty()); }
@Test public void testReadContentFromFileNull() throws Exception { NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(); BufferedReader reader = mock(BufferedReader.class); Mockito.when(reader.readLine()).thenReturn(null); assertTrue(notificationToEmailConverterCommon.readContentFromFile(getClass().getClassLoader(), "resources/dummy").isEmpty()); }
@Test public void testReadContentFromFileException() throws Exception { NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(); BufferedReader reader = mock(BufferedReader.class); Mockito.when(reader.readLine()).thenThrow(new IOException()); assertTrue(notificationToEmailConverterCommon.readContentFromFile(getClass().getClassLoader(), "resources/dummy").isEmpty()); }