components/src/test/java/eu/internetofus/common/components/personal_context_builder/WeNetPersonalContextBuilderSimulatorTest.java
/**
   * Should obtain the closest users into a location.
   *
   * @param vertx       that contains the event bus to use.
   * @param testContext context over the tests.
   */
Should obtain the closest users into a location.
@param vertx       that contains the event bus to use.
@param testContext context over the tests.
Should obtain the closest users into a location . @param vertx that contains the event bus to use . @param testContext context over the tests .
@Test
  public void shouldAddLocationsAndObtainClosestUsers(final Vertx vertx, final VertxTestContext testContext) {
    final var expectedDistances = new ArrayList<UserDistance>();
    Future<?> future = Future.succeededFuture();
    for (var i = 0; i < 10; i++) {
      final var location = new UserLocationTest().createModelExample(i);
      future = future
          .compose(ignored -> WeNetPersonalContextBuilderSimulator.createProxy(vertx).addUserLocation(location));
      final var userDistance = new UserDistance();
      userDistance.userId = location.userId;
      userDistance.distance = UserDistance.calculateDistance(0, 0, location.latitude, location.longitude);
      expectedDistances.add(userDistance);
    }
    future = future
        .compose(ignored -> WeNetPersonalContextBuilderSimulator.createProxy(vertx).obtainClosestUsersTo(0, 0, 10));
    testContext.assertComplete(future).onSuccess(closest1 -> testContext.verify(() -> {
      assertThat(closest1).isEqualTo(expectedDistances);
      testContext.assertComplete(WeNetPersonalContextBuilderSimulator.createProxy(vertx).obtainClosestUsersTo(0, 0, 5))
          .onSuccess(closest2 -> testContext.verify(() -> {
            assertThat(closest2).isEqualTo(expectedDistances.subList(0, 5));
            testContext.completeNow();
          }));
    }));
  }
@ Test public void shouldAddLocationsAndObtainClosestUsers ( final Vertx vertx , final VertxTestContext testContext ) { final var expectedDistances = new ArrayList < UserDistance > ( ) ; Future < ? > future = Future . succeededFuture ( ) ; for ( var i = 0 ; i < 10 ; i ++ ) { final var location = new UserLocationTest ( ) . createModelExample ( i ) ; future = future . compose ( ignored -> WeNetPersonalContextBuilderSimulator . createProxy ( vertx ) . addUserLocation ( location ) ) ; final var userDistance = new UserDistance ( ) ; userDistance . userId = location . userId ; userDistance . distance = UserDistance . calculateDistance ( 0 , 0 , location . latitude , location . longitude ) ; expectedDistances . add ( userDistance ) ; } future = future . compose ( ignored -> WeNetPersonalContextBuilderSimulator . createProxy ( vertx ) . obtainClosestUsersTo ( 0 , 0 , 10 ) ) ; testContext . assertComplete ( future ) . onSuccess ( closest1 -> testContext . verify ( ( ) -> { assertThat ( closest1 ) . isEqualTo ( expectedDistances ) ; testContext . assertComplete ( WeNetPersonalContextBuilderSimulator . createProxy ( vertx ) . obtainClosestUsersTo ( 0 , 0 , 5 ) ) . onSuccess ( closest2 -> testContext . verify ( ( ) -> { assertThat ( closest2 ) . isEqualTo ( expectedDistances . subList ( 0 , 5 ) ) ; testContext . completeNow ( ) ; } ) ) ; } ) ) ; }
Should obtain the closest users into a location.
Should obtain the closest users into a location .