Skip to content

Commit

Permalink
Adding categories method
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoestivill committed Apr 25, 2018
1 parent 5d40295 commit ed24afc
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,10 @@
Change Log
==========

Version 0.1.2 *(2018-04-25)*
----------------------------

* Added `categories` method. Issue #6.

Version 0.1.1 *(2015-05-09)*
----------------------------
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -23,7 +23,7 @@ Maven
<dependency>
<groupId>com.robertoestivill.intentbuilder</groupId>
<artifactId>intentbuilder</artifactId>
<version>0.1.0</version>
<version>0.1.2</version>
</dependency>
```

Expand All @@ -32,7 +32,7 @@ Gradle

```groovy
dependencies {
compile 'com.robertoestivill.intentbuilder:intentbuilder:0.1.0'
compile 'com.robertoestivill.intentbuilder:intentbuilder:0.1.2'
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,4 +1,4 @@
VERSION_NAME=0.1.1
VERSION_NAME=0.1.2
GROUP=com.robertoestivill.intentbuilder

POM_DESCRIPTION=Android Intent wrapper with fluid API and argument validations.
Expand Down
8 changes: 8 additions & 0 deletions intentbuilder/src/main/java/intentbuilder/IntentBuilder.java
Expand Up @@ -142,6 +142,14 @@ public IntentBuilder flags(int... flags) {
return this;
}

public IntentBuilder categories(String... categories) {
validateNotEmpty(categories, "Categories");
for (String category : categories) {
mIntent.addCategory(category);
}
return this;
}

public IntentBuilder extras(Bundle extras) {
validateNotNull(extras, "Extras bundle");
mIntent.putExtras(extras);
Expand Down
61 changes: 52 additions & 9 deletions intentbuilder/src/test/java/intentbuilder/IntentBuilderTest.java
Expand Up @@ -252,12 +252,14 @@ public void flagOne() {

@Test(expected = IllegalArgumentException.class)
public void flagsNull() {
new IntentBuilder().flags(null);
int[] sample = null;
new IntentBuilder().flags(sample);
}

@Test(expected = IllegalArgumentException.class)
public void flagsEmpty() {
new IntentBuilder().flags(new int[]{});
int[] sample = {};
new IntentBuilder().flags(sample);
}

@Test
Expand All @@ -270,13 +272,36 @@ public void flagsOne() {
@Test
public void flagsTwo() {
Intent mock = mock(Intent.class);
new IntentBuilder(mock).flags(
Intent.FLAG_ACTIVITY_CLEAR_TASK,
Intent.FLAG_ACTIVITY_CLEAR_TOP);
verify(mock, times(1)).addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TASK);
verify(mock, times(1)).addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP);
new IntentBuilder(mock).flags(Intent.FLAG_ACTIVITY_CLEAR_TASK, Intent.FLAG_ACTIVITY_CLEAR_TOP);
verify(mock, times(1)).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
verify(mock, times(1)).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}

@Test
public void categoriesOne() {
Intent mock = mock(Intent.class);
new IntentBuilder(mock).categories(Intent.CATEGORY_APP_BROWSER);
verify(mock, times(1)).addCategory(Intent.CATEGORY_APP_BROWSER);
}

@Test(expected = IllegalArgumentException.class)
public void categoriesNull() {
String[] sample = null;
new IntentBuilder().categories(sample);
}

@Test(expected = IllegalArgumentException.class)
public void categoriesEmpty() {
String[] sample = {};
new IntentBuilder().categories(sample);
}

@Test
public void categoriesTwo() {
Intent mock = mock(Intent.class);
new IntentBuilder(mock).categories(Intent.CATEGORY_APP_BROWSER, Intent.CATEGORY_APP_EMAIL);
verify(mock, times(1)).addCategory(Intent.CATEGORY_APP_BROWSER);
verify(mock, times(1)).addCategory(Intent.CATEGORY_APP_EMAIL);
}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -1127,6 +1152,24 @@ public void extraStringList() {

static class MyObject implements Parcelable, Serializable {

MyObject() {
}

MyObject(Parcel in) {
}

public static final Creator<MyObject> CREATOR = new Creator<MyObject>() {
@Override
public MyObject createFromParcel(Parcel in) {
return new MyObject(in);
}

@Override
public MyObject[] newArray(int size) {
return new MyObject[size];
}
};

@Override
public int describeContents() {
return 0;
Expand Down

0 comments on commit ed24afc

Please sign in to comment.