app/src/androidTest/java/ch/epfl/sweng/studdybuddy/ExampleInstrumentedTest.java
package ch.epfl.sweng.studdybuddy;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TimePicker;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest
{
@Test
public void useAppContext()
{
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("ch.epfl.sweng.studdybuddy", appContext.getPackageName());
}
public static Matcher<View> matchesTime(final int hours, final int minutes) {
return new BoundedMatcher<View, TimePicker>(TimePicker.class) {
@Override
public void describeTo(Description description) {
description.appendText("matches date:");
}
@Override
protected boolean matchesSafely(TimePicker item) {
int h, min;
int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion > android.os.Build.VERSION_CODES.LOLLIPOP_MR1){
h = item.getHour();
min = item.getMinute();
} else {
h = item.getCurrentHour();
min = item.getCurrentMinute();
}
return (hours == h && minutes == min);
}
};
}
public static Matcher<View> matchesDate(final int year, final int month, final int day) {
return new BoundedMatcher<View, DatePicker>(DatePicker.class) {
@Override
public void describeTo(Description description) {
description.appendText("matches date:");
}
@Override
protected boolean matchesSafely(DatePicker item) {
return (year == item.getYear() && month == item.getMonth() && day == item.getDayOfMonth());
}
};
}
}