Search in sources :

Example 1 with TestPreferences

use of com.nightscout.core.preferences.TestPreferences in project android-uploader by nightscout.

the class AbstractRestUploaderTest method setUp.

@Before
public void setUp() throws Exception {
    URI uri = URI.create("http://test.com");
    restUploader = new NoopRestUploader(new TestPreferences(), uri);
    mockHttpClient = mock(HttpClient.class);
    restUploader.setClient(mockHttpClient);
    captor = ArgumentCaptor.forClass(HttpUriRequest.class);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpClient(org.apache.http.client.HttpClient) TestPreferences(com.nightscout.core.preferences.TestPreferences) URI(java.net.URI) Before(org.junit.Before)

Example 2 with TestPreferences

use of com.nightscout.core.preferences.TestPreferences in project android-uploader by nightscout.

the class UploaderTest method shouldSendToastIntentOnInvalidMongoUri.

@Test
public void shouldSendToastIntentOnInvalidMongoUri() throws Exception {
    TestPreferences prefs = new TestPreferences();
    prefs.setMongoUploadEnabled(true);
    prefs.setMongoClientUri(null);
    whenOnBroadcastReceived(ToastReceiver.ACTION_SEND_NOTIFICATION, new Function<Intent, Void>() {

        @Override
        public Void apply(Intent input) {
            assertThat(input.getStringExtra(ToastReceiver.TOAST_MESSAGE), is(not(nullValue())));
            assertThat(input.getStringExtra(ToastReceiver.TOAST_MESSAGE), is(getContext().getString(R.string.unknown_mongo_host)));
            return null;
        }
    });
    new Uploader(getContext(), prefs);
    assertIntentSeen();
}
Also used : TestPreferences(com.nightscout.core.preferences.TestPreferences) Intent(android.content.Intent) Test(org.junit.Test)

Example 3 with TestPreferences

use of com.nightscout.core.preferences.TestPreferences in project android-uploader by nightscout.

the class UploaderTest method shouldSendToastIntentOnInvalidRestUri.

@Test
public void shouldSendToastIntentOnInvalidRestUri() throws Exception {
    TestPreferences prefs = new TestPreferences();
    prefs.setRestApiEnabled(true);
    prefs.setRestApiBaseUris(Lists.newArrayList("\\invalid"));
    whenOnBroadcastReceived(ToastReceiver.ACTION_SEND_NOTIFICATION, new Function<Intent, Void>() {

        @Override
        public Void apply(Intent input) {
            assertThat(input.getStringExtra(ToastReceiver.TOAST_MESSAGE), is(not(nullValue())));
            assertThat(input.getStringExtra(ToastReceiver.TOAST_MESSAGE), is(getContext().getString(R.string.illegal_rest_url)));
            return null;
        }
    });
    new Uploader(getContext(), prefs);
    assertIntentSeen();
}
Also used : TestPreferences(com.nightscout.core.preferences.TestPreferences) Intent(android.content.Intent) Test(org.junit.Test)

Example 4 with TestPreferences

use of com.nightscout.core.preferences.TestPreferences in project android-uploader by nightscout.

the class UploaderTest method initializeShouldFailOnInvalidMongoUri.

@Test
public void initializeShouldFailOnInvalidMongoUri() throws Exception {
    TestPreferences prefs = new TestPreferences();
    prefs.setMongoUploadEnabled(true);
    prefs.setMongoClientUri("http://test.com");
    Uploader uploader = new Uploader(getContext(), prefs);
    assertThat(uploader.areAllUploadersInitialized(), is(false));
}
Also used : TestPreferences(com.nightscout.core.preferences.TestPreferences) Test(org.junit.Test)

Example 5 with TestPreferences

use of com.nightscout.core.preferences.TestPreferences in project android-uploader by nightscout.

the class UploaderTest method shouldSendToastIntentOnInvalidRestv1Uri.

@Test
public void shouldSendToastIntentOnInvalidRestv1Uri() throws Exception {
    TestPreferences prefs = new TestPreferences();
    prefs.setRestApiEnabled(true);
    prefs.setRestApiBaseUris(Lists.newArrayList("http://test/v1"));
    whenOnBroadcastReceived(ToastReceiver.ACTION_SEND_NOTIFICATION, new Function<Intent, Void>() {

        @Override
        public Void apply(Intent input) {
            assertThat(input.getStringExtra(ToastReceiver.TOAST_MESSAGE), is(not(nullValue())));
            assertThat(input.getStringExtra(ToastReceiver.TOAST_MESSAGE), is(getContext().getString(R.string.illegal_rest_url)));
            return null;
        }
    });
    new Uploader(getContext(), prefs);
    assertIntentSeen();
}
Also used : TestPreferences(com.nightscout.core.preferences.TestPreferences) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

TestPreferences (com.nightscout.core.preferences.TestPreferences)9 Before (org.junit.Before)5 Test (org.junit.Test)4 Intent (android.content.Intent)3 HttpClient (org.apache.http.client.HttpClient)3 DBCollection (com.mongodb.DBCollection)1 MongoClientURI (com.mongodb.MongoClientURI)1 URI (java.net.URI)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1