package com.google.android.libraries.motionphotoreader;

import com.adobe.internal.xmp.XMPException;
import com.adobe.internal.xmp.XMPMeta;
import com.google.common.primitives.Bytes;

import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.*;

public class XmpParserTest {
    private static final byte[] OPEN_ARR = "<x:xmpmeta".getBytes();  /* Start of XMP metadata tag */
    private static final byte[] CLOSE_ARR = "</x:xmpmeta>".getBytes();  /* End of XMP metadata tag */

    private static final int XMP_BYTE_ARR_LENGTH = 425;

    private String filename;

    @Before
    public void setUp() {
        this.filename = this.getClass().getClassLoader().getResource("test_photo.jpg").getFile();
    }

    @Test
    public void getXmpMetadata_isNotNull() throws IOException, XMPException {
        XMPMeta meta = XmpParser.getXmpMetadata(filename);
        assertNotNull(meta);
    }

    @Test
    public void getXmpByteArray_hasCorrectHeader() throws IOException {
        byte[] segArr = XmpParser.getXmpByteArray(filename);
        int index = Bytes.indexOf(segArr, OPEN_ARR);
        assertEquals(0, index);
    }

    @Test
    public void getXmpByteArray_hasCorrectFooter() throws IOException {
        byte[] segArr = XmpParser.getXmpByteArray(filename);
        int length = Bytes.indexOf(segArr, CLOSE_ARR) + CLOSE_ARR.length;
        assertEquals(XMP_BYTE_ARR_LENGTH, length);
    }
}
@@ -928,32 +928,362 @@
 l(meta);%0A    %7D%0A%0A
+    private static boolean startsWith(byte%5B%5D array, byte%5B%5D prefix) %7B%0A        return Bytes.indexOf(array, prefix) == 0;%0A    %7D%0A%0A    private static boolean endsWith(byte%5B%5D array, byte%5B%5D suffix) %7B%0A        int correctSuffixIndex = array.length - suffix.length;%0A        return Bytes.indexOf(array, suffix) == correctSuffixIndex;%0A    %7D%0A%0A
     @Test%0A    pu
@@ -1268,32 +1268,32 @@
    %7D%0A%0A    @Test%0A
-
     public void 
@@ -1421,82 +1421,47 @@
     
-int index = Bytes.indexOf(segArr, OPEN_ARR);%0A        assertEquals(0, index
+assertTrue(startsWith(segArr, OPEN_ARR)
 );%0A 
@@ -1621,122 +1621,46 @@
     
-int length = Bytes.indexOf(segArr, CLOSE_ARR) + CLOSE_ARR.length;%0A        assertEquals(XMP_BYTE_ARR_LENGTH, length
+assertTrue(endsWith(segArr, CLOSE_ARR)
 );%0A 

Refactor for readability.