### Question:
IndexingUtils { public static byte[] getByteContent(Resource resource, String sourceURL) throws RegistryException { try { InputStream is = null; if (sourceURL != null) { is = new URL(sourceURL).openStream(); } else { Object content = resource.getContent(); if( null == content) { return new byte[0]; } is = resource.getContentStream(); if (is == null) { if (content instanceof byte[]) { return (byte[]) content; } else if (content instanceof String) { return RegistryUtils.encodeString((String) content); } else { throw new RegistryException("Unknown type found as content " + content); } } } return readBytesFromInputSteam(is); } catch (IOException e) { throw new RegistryException("Error at indexing", e); } }  static boolean isAuthorized(UserRegistry registry, String resourcePath, String action); static byte[] readBytesFromInputSteam(InputStream in); static byte[] getByteContent(Resource resource, String sourceURL); static String getLoggedInUserName();  }### Answer:
@Test public void testGetByteContent() throws Exception { ResourceImpl resource = new ResourceImpl(); String contentString = "Testing Content"; resource.setContent(contentString); byte[] byteContent = IndexingUtils.getByteContent(resource, null); assertEquals(contentString, RegistryUtils.decodeBytes(byteContent)); resource.setContent(null); byte[] emptyContent = IndexingUtils.getByteContent(resource, null); assertArrayEquals(new byte[0], emptyContent); }
@Test public void testGetByteContentWithInvalidContent() throws Exception { ResourceImpl resource = new ResourceImpl(); resource.setContent(new Object()); try { IndexingUtils.getByteContent(resource, null); fail("Resource validation is missing"); } catch (RegistryException e) { assertEquals("Cannot return input stream for content of type: java.lang.Object", e.getMessage()); } }
@Test public void testGetByteContentWithoutStream() throws Exception { ResourceImpl resource = mock(ResourceImpl.class); String contentString = "Testing Content"; when(resource.getContent()).thenReturn(contentString); when(resource.getContentStream()).thenReturn(null); byte[] byteContent = IndexingUtils.getByteContent(resource, null); assertEquals(contentString, RegistryUtils.decodeBytes(byteContent)); }