-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
170 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
library/src/main/java/nl/endevelopment/r2randroid/r2rlib/parser/DayFlagsParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package nl.endevelopment.r2randroid.r2rlib.parser; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import nl.endevelopment.r2randroid.r2rlib.models.DayFlags; | ||
|
||
/** | ||
* Created by jan on 28/08/2017. | ||
*/ | ||
|
||
public class DayFlagsParser implements JsonDeserializer<DayFlags> { | ||
@Override | ||
public DayFlags deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | ||
|
||
//Expected input should be a int in the [0-127] range (7 bytes) | ||
int intFlag = json.getAsInt(); | ||
|
||
if (intFlag < 0 || intFlag > 127) { | ||
return new DayFlags(0); | ||
} | ||
|
||
return new DayFlags(intFlag); | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
library/src/main/java/nl/endevelopment/r2randroid/r2rlib/parser/SearchParser.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
library/src/test/java/nl/endevelopment/r2randroid/r2rlib/SearchParserUnitTest.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
library/src/test/java/nl/endevelopment/r2randroid/r2rlib/models/DayFlagsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package nl.endevelopment.r2randroid.r2rlib.models; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Created by jan on 28/08/2017. | ||
* test dayflag bitwise and operator | ||
*/ | ||
|
||
public class DayFlagsTest { | ||
@Test | ||
public void isSunday() throws Exception { | ||
DayFlags dayFlags = new DayFlags(DayFlags.SUNDAY); | ||
|
||
assertThat(dayFlags.isDay(DayFlags.SUNDAY), is(true)); | ||
} | ||
|
||
@Test | ||
public void isWeekday() throws Exception { | ||
DayFlags dayFlags = new DayFlags(DayFlags.WEEKDAYS); | ||
|
||
assertThat(dayFlags.isDay(DayFlags.FRIDAY), is(true)); | ||
} | ||
|
||
@Test | ||
public void isNotWeekday() throws Exception { | ||
DayFlags dayFlags = new DayFlags(DayFlags.WEEKDAYS); | ||
|
||
assertThat(dayFlags.isDay(DayFlags.SUNDAY), is(false)); | ||
} | ||
|
||
@Test | ||
public void isWeekend() throws Exception { | ||
DayFlags dayFlags = new DayFlags(DayFlags.WEEKENDS); | ||
|
||
assertThat(dayFlags.isDay(DayFlags.SATURDAY), is(true)); | ||
} | ||
|
||
@Test | ||
public void isNotWeekend() throws Exception { | ||
DayFlags dayFlags = new DayFlags(DayFlags.WEEKENDS); | ||
|
||
assertThat(dayFlags.isDay(DayFlags.THURSDAY), is(false)); | ||
} | ||
|
||
@Test | ||
public void isAlways() throws Exception { | ||
DayFlags dayFlags = new DayFlags(DayFlags.EVERYDAY); | ||
|
||
assertThat(dayFlags.isDay(DayFlags.SATURDAY), is(true)); | ||
} | ||
|
||
@Test | ||
public void isAlwaysWeekend() throws Exception { | ||
DayFlags dayFlags = new DayFlags(DayFlags.EVERYDAY); | ||
|
||
assertThat(dayFlags.isDay(DayFlags.WEEKENDS), is(true)); | ||
} | ||
|
||
@Test | ||
public void isNever() throws Exception { | ||
DayFlags dayFlags = new DayFlags(DayFlags.NEVER); | ||
|
||
assertThat(dayFlags.isDay(DayFlags.SATURDAY), is(false)); | ||
} | ||
|
||
} |