Skip to content

Commit

Permalink
#209: Few unit tests added for FilePickerProxy (#208)
Browse files Browse the repository at this point in the history
* few unit tests added for FilePickerProxy
  • Loading branch information
jwojciec authored and malsolec committed Dec 1, 2017
1 parent 0861abc commit 6c40aa8
Showing 1 changed file with 32 additions and 0 deletions.
Expand Up @@ -2,23 +2,34 @@

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.when;

import android.content.Intent;
import com.nbsp.materialfilepicker.ui.FilePickerActivity;
import java.util.regex.Pattern;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.internal.WhiteboxImpl;
import pg.autyzm.friendly_plans.asset.AssetType;

@RunWith(PowerMockRunner.class)
public class FilePickerProxyTest {

private static final String FILE_PATH = "test_result_file_path";
private FilePickerProxy filePickerProxy;

@Mock
private Intent intentMock;

@Before
public void setUp() {
filePickerProxy = new FilePickerProxy();
when(intentMock.getStringExtra(FilePickerActivity.RESULT_FILE_PATH)).thenReturn(FILE_PATH);
}

@Test
Expand Down Expand Up @@ -50,6 +61,27 @@ public void whenGettingPatternForSoundExpectPatternToNotMatchOnlyExtension()
assertFalse(pattern.matcher(".mp3").matches());
}

@Test
public void whenCheckingPickFileRequestedExpectCorrectResult() {
assertTrue(filePickerProxy.isPickFileRequested(0, AssetType.PICTURE));
assertTrue(filePickerProxy.isPickFileRequested(1, AssetType.SOUND));
}

@Test
public void whenCheckingFilePickedWithOkExpectTrue() {
assertTrue(filePickerProxy.isFilePicked(FilePickerActivity.RESULT_OK));
}

@Test
public void whenCheckingFilePickedWithCanceledExpectFalse() {
assertFalse(filePickerProxy.isFilePicked(FilePickerActivity.RESULT_CANCELED));
}

@Test
public void whenGettingFilePathExpectCorrectResult() {
assertThat(filePickerProxy.getFilePath(intentMock), is(FILE_PATH));
}

private Pattern getPattern(AssetType assetType) throws Exception {
return WhiteboxImpl.invokeMethod(filePickerProxy, "getPattern", assetType);
}
Expand Down

0 comments on commit 6c40aa8

Please sign in to comment.