Skip to content

Commit

Permalink
New tests for BasicFieldImageView image from /assets/. (google#444)
Browse files Browse the repository at this point in the history
Tests for google#442.
  • Loading branch information
AnmAtAnm authored Dec 2, 2016
1 parent 406ce48 commit f715c1e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Binary file added blocklytest/src/androidTest/assets/localIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.google.blockly.android.ui.fieldview;

import android.content.Context;

import com.google.blockly.android.MockitoAndroidTestCase;

import org.mockito.AdditionalAnswers;
import org.mockito.Mockito;

import java.io.IOException;
import java.io.InputStream;

/**
* Tests for {@link BasicFieldImageView}.
*/
public class BasicFieldImageViewTest extends MockitoAndroidTestCase {
Context mMockContext;

BasicFieldImageView mImageFieldView;

@Override
public void setUp() throws Exception {
super.setUp();

mMockContext = Mockito.mock(Context.class, AdditionalAnswers.delegatesTo(getContext()));

mImageFieldView = new BasicFieldImageView(mMockContext);
}

public void testImageSourceFromAssets() throws IOException {
InputStream in = null;
try {
in = mImageFieldView.getStreamForSource("localIcon.png");
assertNotEmpty(in);
in.close();

in = mImageFieldView.getStreamForSource("/localIcon.png");
assertNotEmpty(in);
in.close();

in = mImageFieldView.getStreamForSource("file:///android_assets/localIcon.png");
assertNotEmpty(in);
} finally {
in.close();
}
}

private void assertNotEmpty(InputStream in) throws IOException {
assertNotNull(in);
assertTrue(in.available() > 0);
}
}

0 comments on commit f715c1e

Please sign in to comment.