@@ -0,0 +1,2896 @@
+package com.siteshot.siteshot.test;%0A%0Aimport android.graphics.Bitmap;%0Aimport android.graphics.BitmapFactory;%0Aimport android.graphics.Color;%0Aimport android.os.Handler;%0Aimport android.test.ActivityInstrumentationTestCase2;%0A%0Aimport com.parse.ParseException;%0Aimport com.parse.ParseFile;%0Aimport com.parse.ParseObject;%0Aimport com.parse.ParseQuery;%0Aimport com.siteshot.siteshot.activities.ProfileActivity;%0Aimport com.siteshot.siteshot.utils.PhotoUtils;%0A%0Aimport java.io.IOException;%0Aimport java.util.Random;%0A%0A/**%0A * Created by aclissold on 10/6/14.%0A */%0Apublic class PhotoUtilsTest extends ActivityInstrumentationTestCase2%3CProfileActivity%3E %7B%0A%0A    private ProfileActivity mProfileActivity;%0A    private PhotoUtils mPhotoUtils;%0A%0A    public PhotoUtilsTest() %7B%0A        super(ProfileActivity.class);%0A    %7D%0A%0A    @Override%0A    public void setUp() throws Exception %7B%0A        super.setUp();%0A        mProfileActivity = getActivity();%0A        mPhotoUtils = new PhotoUtils();%0A    %7D%0A%0A    public void testPhotoUpload() throws IOException %7B%0A        // Create the photo file.%0A        mPhotoUtils.createPhotoFile();%0A        String photoPath = mPhotoUtils.getCurrentPhotoPath();%0A        assertNotNull(photoPath);%0A%0A        // Write mock data to it.%0A        final Bitmap mockBitmap = createMockBitmap();%0A%0A        // Upload it to Parse.%0A        mPhotoUtils.uploadPhoto(mockBitmap);%0A%0A        // Get it back from Parse.%0A        Handler handler = new Handler();%0A        handler.postDelayed(new Runnable() %7B%0A            public void run() %7B%0A                ParseQuery query = new ParseQuery(%22UserPhoto%22);%0A                query.orderByDescending(%22createdAt%22);%0A                ParseFile file = null;%0A                try %7B%0A                    ParseObject object = query.getFirst();%0A                    file = (ParseFile) object.get(%22photo%22);%0A                %7D catch (ParseException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A                assertNotNull(file);%0A%0A                // Verify its contents.%0A                byte%5B%5D data = null;%0A                try %7B%0A                    data = file.getData();%0A                %7D catch (ParseException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A%0A                assertNotNull(data);%0A                Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);%0A%0A                assertEquals(mockBitmap, bitmap);%0A            %7D%0A        %7D, 2000);%0A    %7D%0A%0A    private Bitmap createMockBitmap() %7B%0A        final int w = 25;%0A        final int h = 25;%0A        Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);%0A%0A        for (int x = 0; x %3C w; x++) %7B%0A            for (int y = 0; y %3C h; y++) %7B%0A                Random rnd = new Random();%0A                int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));%0A                bitmap.setPixel(x, y, color);%0A            %7D%0A        %7D%0A%0A        return bitmap;%0A    %7D%0A%0A%7D%0A

Test photo upload and retrieval