org.fest.assertions.api.Assertions Java Examples

The following examples show how to use org.fest.assertions.api.Assertions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SensorbergServiceInternalTests.java    From android-sdk with MIT License 6 votes vote down vote up
@Test
public void registerPresentationDelegate_should_add_delegate_to_messengerList() {
    Messenger messenger = new Messenger(new Handler(InstrumentationRegistry.getContext().getMainLooper()));
    tested.presentationDelegates = spy(tested.presentationDelegates);

    try {
        tested.registerPresentationDelegate(SensorbergServiceIntents.getIntentWithReplyToMessenger(InstrumentationRegistry.getContext(),
                SensorbergServiceMessage.MSG_REGISTER_PRESENTATION_DELEGATE, messenger));
    } catch (Exception e) {
        /* this happens because the MessengerList, as an internal class of SensorbergService, has its own instance which is different
        from the proxied spy instance we use for testing; MessengerList.add() calls bootstrapper.sentPresentationDelegationTo()
        and that will cause the NPE */
        Assertions.assertThat(e).isInstanceOf(NullPointerException.class);
    }

    Assertions.assertThat(tested.presentationDelegates.getSize()).isEqualTo(1);
    Mockito.verify(tested.presentationDelegates, Mockito.times(1)).add(messenger);
}
 
Example #2
Source File: TheResolverWithRealApiShould.java    From android-sdk with MIT License 6 votes vote down vote up
/**
 * for BE integration check Ronaldo Pace user SDK_TEST app
 */
@Test
public void test_beacon_with_delay() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    tested.setListener(new ResolverListener() {
        @Override
        public void onResolutionFailed(Throwable cause, ScanEvent scanEvent) {
            fail(cause.getMessage());
            latch.countDown();
        }

        @Override
        public void onResolutionsFinished(List<BeaconEvent> events) {
            Assertions.assertThat(events.get(0).getAction().getDelayTime()).isEqualTo(120000);
            latch.countDown();
        }
    });

    tested.resolve(new ScanEvent.Builder()
            .withBeaconId(TestConstants.DELAY_BEACON_ID)
            .withEntry(true)
            .build()
    );
    Assertions.assertThat(latch.await(10, TimeUnit.SECONDS)).overridingErrorMessage("Request did not return within time").isEqualTo(true);
}
 
Example #3
Source File: SensorbergServiceInternalTests.java    From android-sdk with MIT License 6 votes vote down vote up
@Test
public void unregisterPresentationDelegate_should_remove_delegate_from_messengerList() {
    Messenger messenger = new Messenger(new Handler(InstrumentationRegistry.getContext().getMainLooper()));
    tested.presentationDelegates = spy(tested.presentationDelegates);

    try {
        tested.unregisterPresentationDelegate(SensorbergServiceIntents.getIntentWithReplyToMessenger(InstrumentationRegistry.getContext(),
                SensorbergServiceMessage.MSG_UNREGISTER_PRESENTATION_DELEGATE, messenger));
    } catch (Exception e) {
        /* this happens because the MessengerList, as an internal class of SensorbergService, has its own instance which is different
        from the proxied spy instance we use for testing; MessengerList.add() calls bootstrapper.sentPresentationDelegationTo()
        and that will cause the NPE */
        Assertions.assertThat(e).isInstanceOf(NullPointerException.class);
    }

    Assertions.assertThat(tested.presentationDelegates.getSize()).isEqualTo(0);
    Mockito.verify(tested.presentationDelegates, Mockito.times(1)).remove(messenger);
}
 
Example #4
Source File: ChangedPropertyNamesForNullifiedValuesCase.java    From javers with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCalculateChangedPropertyNamesForNullifiedValues() {
    //given
    Javers javers = JaversBuilder.javers().build();
    SimpleTypes obj = new SimpleTypes("1");
    javers.commit("anonymous", obj);

    //when
    obj.shortNumber = -1;
    javers.commit("anonymous", obj);
    CdoSnapshot s = javers.getLatestSnapshot("1", SimpleTypes.class).get();

    //then
    Assertions.assertThat(s.getChanged()).containsExactly("shortNumber");

    //when
    obj.nullify();
    javers.commit("anonymous", obj);
    s = javers.getLatestSnapshot("1", SimpleTypes.class).get();

    //then
    Assertions.assertThat(s.getChanged()).hasSize(11);
}
 
Example #5
Source File: ResolveActionTest.java    From android-sdk with MIT License 6 votes vote down vote up
@Test
public void test_should_convert_from_gmt_to_local_timezone() throws Exception {
    ResolveAction[] tested = gson.fromJson(Utils.getRawResourceAsString(com.sensorberg.sdk.test.R.raw.resolve_action_with_timeframes_in_gmt,
            InstrumentationRegistry.getContext()), ResolveAction[].class);

    Assertions.assertThat(tested).hasSize(2);
    ResolveAction action1 = tested[0];
    ResolveAction action2 = tested[1];

    //action TimeFrames get converted into local time
    //we compare against System.currentTimeMillis() which also starts from GMT and adds default device time zone
    //as well as DateTime that we use to test here

    //action 1 is active between 9:15 and 17:15 GMT, May 10, 2016
    //action 2 is active between 14:15 and 18:15 GMT, May 10, 2016
    testClock.setNowInMillis(new DateTime(2016, 5, 10, 9, 30, 0, DateTimeZone.UTC).getMillis()); //local time
    Assertions.assertThat(action1.isValidNow(testClock.now())).isTrue();
    Assertions.assertThat(action2.isValidNow(testClock.now())).isFalse();

    //action 1 is not active
    //action 2 is active between 14:15 and 18:15 GMT, May 11, 2016
    testClock.setNowInMillis(new DateTime(2016, 5, 11, 15, 30, 0, DateTimeZone.UTC).getMillis());//local time
    Assertions.assertThat(action1.isValidNow(testClock.now())).isFalse();
    Assertions.assertThat(action2.isValidNow(testClock.now())).isTrue();
}
 
Example #6
Source File: SensorbergSdkTests.java    From android-sdk with MIT License 6 votes vote down vote up
@Test
public void add_listener_also_registers_messenger_with_service() {
    SensorbergSdkEventListener listener = new SensorbergSdkEventListener() {
        @Override
        public void presentBeaconEvent(BeaconEvent beaconEvent) {
            //do nothing;
        }
    };

    Assertions.assertThat(SensorbergSdk.listeners.size()).isEqualTo(0);

    tested.registerEventListener(listener);

    Assertions.assertThat(SensorbergSdk.listeners.size()).isEqualTo(1);
    verify(tested, times(1)).setPresentationDelegationEnabled(true);
    verify(tested, times(1)).registerForPresentationDelegation();
}
 
Example #7
Source File: SensorbergSdkTests.java    From android-sdk with MIT License 6 votes vote down vote up
@Test
public void hostApplicationInForeground_with_listeners_also_registers_messenger_with_service() {
    SensorbergSdkEventListener listener = new SensorbergSdkEventListener() {
        @Override
        public void presentBeaconEvent(BeaconEvent beaconEvent) {
            //do nothing;
        }
    };

    tested.registerEventListener(listener);
    tested.hostApplicationInForeground();

    Assertions.assertThat(SensorbergSdk.listeners.size()).isEqualTo(1);
    /* called once by registerEventListener and once by hostApplicationInForeground */
    verify(tested, times(2)).registerForPresentationDelegation();
}
 
Example #8
Source File: TheInternalApplicationBootstrapperShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void beacon_should_allow_again_after_suppressiontime_is_over() {
    List<BeaconEvent> events = ListUtils.filter(Arrays.asList(beaconEventSupressionTime), tested.beaconEventFilter);
    Assertions.assertThat(events.size()).isEqualTo(1);

    testHandlerManager.getCustomClock().setNowInMillis(SUPPRESSION_TIME + 1);

    List<BeaconEvent> eventsWithSuppressionEvent = ListUtils.filter(Arrays.asList(beaconEventSupressionTime), tested.beaconEventFilter);
    Assertions.assertThat(eventsWithSuppressionEvent.size()).isEqualTo(1);
}
 
Example #9
Source File: ApiServiceShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void apiservice_should_have_null_default_advertiserid_in_header() throws Exception {
    MockResponse successfulCachedSettingsMockResponse = RawJSONMockResponse.fromRawResource(
            InstrumentationRegistry.getContext().getResources().openRawResource(com.sensorberg.sdk.test.R.raw.response_raw_layout_etag_001));
    server.enqueue(successfulCachedSettingsMockResponse);

    Call<ResolveResponse> call = realRetrofitApiService.updateBeaconLayout(null);

    Assertions.assertThat(realPlatformIdentifier.getAdvertiserIdentifier()).isNull();
    Response<ResolveResponse> responseWithAdvertiserId = call.clone().execute();

    Assertions.assertThat(responseWithAdvertiserId.raw().request().headers().get(Transport.HEADER_ADVERTISER_IDENTIFIER))
            .isEqualTo(realPlatformIdentifier.getAdvertiserIdentifier());
}
 
Example #10
Source File: TheSettingsShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void test_parsing_settings_from_network_response() throws Exception {
    SettingsResponse settingsResponse = gson.fromJson(
            Utils.getRawResourceAsString(com.sensorberg.sdk.test.R.raw.response_settings_newdefaults, InstrumentationRegistry
                    .getContext()), SettingsResponse.class);
    Mockito.when(mockRetrofitApiService.getSettings()).thenReturn(Calls.response(settingsResponse));

    Assertions.assertThat(settingsResponse).isNotNull();
    Assertions.assertThat(settingsResponse.getRevision()).isEqualTo(1L);
    Assertions.assertThat(settingsResponse.getSettings().getBackgroundWaitTime()).isEqualTo(100000L);
    Assertions.assertThat(settingsResponse.getSettings().getBeaconReportLevel()).isEqualTo(1);
    Assertions.assertThat(settingsResponse.getSettings().getScannerMinRssi()).isEqualTo(-10);
    Assertions.assertThat(settingsResponse.getSettings().getScannerMaxDistance()).isEqualTo(5);
}
 
Example #11
Source File: SensorbergServiceInternalTests.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void should_turn_debugging_off_in_transport_from_intent() {
    Intent serviceDebuggingOffIntent = SensorbergServiceIntents.getServiceLoggingIntent(InstrumentationRegistry.getContext(), false);

    tested.handleDebuggingIntent(serviceDebuggingOffIntent);

    Mockito.verify(tested.transport, times(1)).setLoggingEnabled(false);
    Assertions.assertThat(Logger.log).isEqualTo(Logger.QUIET_LOG);
}
 
Example #12
Source File: ActionFactoryTest.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void should_parse_action_type_inapp_action() throws IOException {
    Action result = getAction(action_factory_004);

    Assertions.assertThat(result).isNotNull();
    Assertions.assertThat(result).isInstanceOf(InAppAction.class);
    Assertions.assertThat(((InAppAction) result).getSubject()).isNotEmpty();
    Assertions.assertThat(((InAppAction) result).getBody()).isNotEmpty();
    Assertions.assertThat(((InAppAction) result).getUri().toString()).isEqualTo("http://www.google.com");
}
 
Example #13
Source File: TheBeaconScanShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void test_should_be_json_serializeable() throws Exception {
    String objectAsJSON = gson.toJson(tested);
    BeaconScan deserializedObject = gson.fromJson(objectAsJSON, BeaconScan.class);

    Assertions.assertThat(objectAsJSON).isNotEmpty();
    Assertions.assertThat(deserializedObject).isEqualTo(tested);
}
 
Example #14
Source File: InitialActivityTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onPreviouslyLoggedIn_ShouldOpenBaseActivity() {
    simulateLogin();
    InitialActivity activity = initInitialActivity();
    String activityStarted = shadowOf(activity).getNextStartedActivity()
            .getComponent().toString();
    Assertions.assertThat(activityStarted)
            .isEqualTo("ComponentInfo{com.mapzen.open/com.mapzen.open.activity.BaseActivity}");
}
 
Example #15
Source File: ActionFactoryTest.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void should_parse_action_type_url_message() throws IOException {
    Action result = getAction(action_factory_001);

    Assertions.assertThat(result).isNotNull();
    Assertions.assertThat(result).isInstanceOf(UriMessageAction.class);
    Assertions.assertThat(((UriMessageAction) result).getContent()).isNotEmpty();
    Assertions.assertThat(((UriMessageAction) result).getTitle()).isNotEmpty();
    Assertions.assertThat(((UriMessageAction) result).getUri()).isEqualToIgnoringCase("something://");
}
 
Example #16
Source File: TheThreadedRunLoop.java    From android-sdk with MIT License 5 votes vote down vote up
@Ignore
public void should_run_a_scheduled_runnable() throws InterruptedException {

    //this cannot work, since the instanciated handler is running this thread, so we´e pausing this thread
    // while waiting for something to happen on it...

    tested.scheduleExecution(myRunnable, 100);

    long before = System.currentTimeMillis();
    boolean countedDown = latch.await(200, TimeUnit.MILLISECONDS);
    long after = System.currentTimeMillis();

    Assertions.assertThat(after - before).isGreaterThan(300);
    Assertions.assertThat(countedDown).isTrue();
}
 
Example #17
Source File: CacheEventAssert.java    From fresco with MIT License 5 votes vote down vote up
public CacheEventAssert hasCacheKey(CacheKey expected) {
  Assertions.assertThat(actual.getCacheKey())
      .overridingErrorMessage(
          "Cache event mismatch - cache key <%s> does not match <%s>",
          actual.getCacheKey(), expected)
      .isEqualTo(expected);
  return this;
}
 
Example #18
Source File: ApiServiceShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void apiservice_should_have_apitoken_header() throws Exception {
    MockResponse successfulCachedSettingsMockResponse = RawJSONMockResponse.fromRawResource(
            InstrumentationRegistry.getContext().getResources().openRawResource(com.sensorberg.sdk.test.R.raw.response_raw_layout_etag_001));
    server.enqueue(successfulCachedSettingsMockResponse);

    Call<ResolveResponse> call = realRetrofitApiService.updateBeaconLayout(null);
    Response<ResolveResponse> response = call.execute();

    Assertions.assertThat(response.raw().request().headers()).isNotNull();
    Assertions.assertThat(response.raw().request().headers().get(Transport.HEADER_XAPIKEY))
            .isEqualTo(TestConstants.API_TOKEN_DEFAULT);
}
 
Example #19
Source File: TheSQLiteStoreShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void test_load_all_entries_to_memory() throws Exception {
    tested.put(new SQLiteStore.Entry(1, TIMESTAMP_OF_EVENT, IRRELEVANT, bundle));

    ArrayList<SQLiteStore.Entry> all = tested.loadRegistry();
    Assertions.assertThat(all).isNotNull().hasSize(1);
}
 
Example #20
Source File: TheInternalBootstrapperIntegration.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
    public void test_precaching() {
        try {
            ResolveResponse updateLayoutResponse = gson
                    .fromJson(Utils.getRawResourceAsString(com.sensorberg.sdk.test.R.raw.response_resolve_precaching,
                            InstrumentationRegistry.getContext()), ResolveResponse.class);
            Mockito.when(mockRetrofitApiService.updateBeaconLayout(Matchers.<TreeMap<String, String>>any())).thenReturn(Calls.response(updateLayoutResponse));

            ResolveResponse getBeaconResponse = gson.fromJson(Utils.getRawResourceAsString(com.sensorberg.sdk.test.R.raw.response_resolve_precaching,
                    InstrumentationRegistry.getContext()), ResolveResponse.class);
            Mockito.when(mockRetrofitApiService.getBeacon(Mockito.anyString(), Mockito.anyString(), Matchers.<TreeMap<String, String>>any()))
                    .thenReturn(Calls.response(getBeaconResponse));
        } catch (Exception e) {
            Assertions.fail(e.toString());
        }

        System.out.println("TheInternalBootstrapperIntegration start test_precaching");
        spiedInternalApplicationBootstrapper.updateBeaconLayout();

        //simulate the entry
        spiedInternalApplicationBootstrapper.onScanEventDetected(TestConstants.BEACON_SCAN_ENTRY_EVENT(0));

        Mockito.verify(spiedTransportWithMockService, Mockito.timeout(5000).times(1))
                .getBeacon(Mockito.any(ScanEvent.class), Matchers.<TreeMap<String, String>>any(), Mockito.any(BeaconResponseHandler.class));
        Mockito.verify(spiedTransportWithMockService, Mockito.timeout(5000).times(1))
                .updateBeaconLayout(Matchers.<TreeMap<String, String>>any());

        //TODO this does get called in real code and during debugging, but Mockito says it doesn't
//        Mockito.verify(spiedInternalApplicationBootstrapper, Mockito.timeout(5000).times(1))
//                .presentBeaconEvent(Mockito.any(BeaconEvent.class));
    }
 
Example #21
Source File: TheTimeFrameShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void answer_correctly_with_both_values() throws Exception {
    Timeframe tested = new Timeframe(0L, 1000L);

    Assertions.assertThat(tested.valid(-1)).isFalse();
    Assertions.assertThat(tested.valid(1)).isTrue();
    Assertions.assertThat(tested.valid(1000)).isTrue();
    Assertions.assertThat(tested.valid(1001)).isFalse();
}
 
Example #22
Source File: TheScannerHelperWithZeroBytesShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void find_a_beacon_with_nexus_style_flags() {
    Pair<BeaconId, Integer> beacon = ScanHelper.getBeaconID(wrapWithZeroBytes(TestBluetoothPlatform.BYTES_FOR_BEACON_WITH_NEXUS9_FLAGS, 62));

    Assertions.assertThat(beacon.first).isEqualTo(TestBluetoothPlatform.EXPECTED_ALIEN_1);
    Assertions.assertThat(beacon.second).isEqualTo(-58);
}
 
Example #23
Source File: TheResolverWithRealApiShould.java    From android-sdk with MIT License 5 votes vote down vote up
/**
 * for BE integration check Ronaldo Pace user SDK_TEST app
 */
@Test
public void test_resolve_in_app_function() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);

    ResolverListener mockListener = new ResolverListener() {
        @Override
        public void onResolutionFailed(Throwable cause, ScanEvent scanEvent) {
            fail(cause.getMessage() + scanEvent.toString());
            latch.countDown();
        }

        @Override
        public void onResolutionsFinished(List<BeaconEvent> events) {
            Assertions.assertThat(events).hasSize(3);
            latch.countDown();
        }

    };
    tested.setListener(mockListener);

    tested.resolve(new ScanEvent.Builder()
            .withBeaconId(TestConstants.IN_APP_BEACON_ID)
            .withEntry(true).build()
    );
    Assertions.assertThat(latch.await(10, TimeUnit.SECONDS)).overridingErrorMessage("Request did not return within time").isEqualTo(true);

}
 
Example #24
Source File: TheSettingsShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void test_initial_values_should_be_identical() throws Exception {
    Assertions.assertThat(tested.getBackgroundScanTime()).isEqualTo(DefaultSettings.DEFAULT_BACKGROUND_SCAN_TIME);
    Assertions.assertThat(tested.getBackgroundWaitTime()).isEqualTo(DefaultSettings.DEFAULT_BACKGROUND_WAIT_TIME);
    Assertions.assertThat(tested.getExitTimeoutMillis()).isEqualTo(DefaultSettings.DEFAULT_EXIT_TIMEOUT_MILLIS);
    Assertions.assertThat(tested.getForeGroundScanTime()).isEqualTo(DefaultSettings.DEFAULT_FOREGROUND_SCAN_TIME);
    Assertions.assertThat(tested.getForeGroundWaitTime()).isEqualTo(DefaultSettings.DEFAULT_FOREGROUND_WAIT_TIME);
    Assertions.assertThat(tested.getBeaconReportLevel()).isEqualTo(DefaultSettings.DEFAULT_BEACON_REPORT_LEVEL);
    Assertions.assertThat(tested.getScannerMinRssi()).isEqualTo(DefaultSettings.DEFAULT_SCANNER_MIN_RSSI);
    Assertions.assertThat(tested.getScannerMaxDistance()).isEqualTo(DefaultSettings.DEFAULT_SCANNER_MAX_DISTANCE);
}
 
Example #25
Source File: ActionFactoryTest.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void should_parse_action_type_inapp_action_empty_url() throws IOException {
    Action result = getAction(action_factory_empty_url);

    Assertions.assertThat(result).isNotNull();
    Assertions.assertThat(result).isInstanceOf(InAppAction.class);
    Assertions.assertThat(((InAppAction) result).getSubject()).isNotEmpty();
    Assertions.assertThat(((InAppAction) result).getBody()).isNotEmpty();
    Assertions.assertThat(((InAppAction) result).getUri().toString()).isEqualTo("");

}
 
Example #26
Source File: TheScannerHelperWithZeroBytesShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void find_a_beacon_with_variation_in_advertisement_packet() {
    Pair<BeaconId, Integer> beacon = ScanHelper.getBeaconID(wrapWithZeroBytes(TestBluetoothPlatform.BYTES_FOR_BEACON_WITH_DIFFERENT_FLAGS_1, 62));

    Assertions.assertThat(beacon.first).isEqualTo(TestBluetoothPlatform.EXPECTED_ALIEN_1);
    Assertions.assertThat(beacon.second).isEqualTo(-58);
}
 
Example #27
Source File: BranchesListTest.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testThatPruneRemovesBranch() {
    Branch branch = givenThatHasBranch();
    branchesList.prune(branch);

    Assertions.assertThat(branchesList).isEmpty();
}
 
Example #28
Source File: BranchesListTest.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testThatWhenFlowerIsOtherThanNoneAndNotEnoughOnListThenFlowerIsNotIncludedIntoListIfBranchCantBloom() {
    Branch branch = givenABranchThatCannotBloom();
    branchesList.bloomFrom(branch);

    Assertions.assertThat(branchesList).hasSize(0);
}
 
Example #29
Source File: TheScannerHelperWithZeroBytesShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void find_a_beacon_with_invalid_header_in_advertisement_packet() {
    Pair<BeaconId, Integer> beacon = ScanHelper.getBeaconID(wrapWithZeroBytes(TestBluetoothPlatform.BYTES_FOR_BEACON_WITH_ABSTRUSE_VARIATION_3, 62));

    Assertions.assertThat(beacon.first).isEqualTo(TestBluetoothPlatform.EXPECTED_ALIEN_1);
    Assertions.assertThat(beacon.second).isEqualTo(-58);
}
 
Example #30
Source File: TheResolveResponseShould.java    From android-sdk with MIT License 5 votes vote down vote up
@Test
public void resolve_an_exit_action() throws Exception {
    ResolveResponse tested = gson
            .fromJson(Utils.getRawResourceAsString(com.sensorberg.sdk.test.R.raw.resolve_response_001, InstrumentationRegistry.getContext()), ResolveResponse.class);

    Assertions.assertThat(tested.resolve(TestConstants.RESOLVABLE_EXIT_EVENT_WITH_ID_4, 0)).hasSize(1 + 1);
    Assertions.assertThat(tested.getInstantActions()).hasSize(1);
}