Skip to content

Commit

Permalink
Test interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
testower committed Aug 2, 2024
1 parent a1048e1 commit d056b22
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/java/org/entur/gbfs/GBFSSubscriptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.net.URISyntaxException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.entur.gbfs.loader.v2.GbfsV2Delivery;
import org.entur.gbfs.loader.v3.GbfsV3Delivery;
Expand Down Expand Up @@ -83,6 +84,31 @@ void testV3Subscription() throws URISyntaxException, InterruptedException {
loader.unsubscribe(subscriber);
}

@Test
void testSubscriptionUpdateInterceptor()
throws URISyntaxException, InterruptedException {
waiter = new CountDownLatch(3);
GbfsSubscriptionManager loader = new GbfsSubscriptionManager();
String subscriber = loader.subscribeV3(
getV3TestOptions("file:src/test/resources/gbfs/v3/getaroundstavanger/gbfs.json"),
getV3TestConsumer(),
new SubscriptionUpdateInterceptor() {
@Override
public void beforeUpdate() {
waiter.countDown();
}

@Override
public void afterUpdate() {
waiter.countDown();
}
}
);
loader.update();
Assertions.assertTrue(waiter.await(500, TimeUnit.MILLISECONDS));
loader.unsubscribe(subscriber);
}

Consumer<GbfsV3Delivery> getV3TestConsumer() {
return delivery -> {
Assertions.assertNotNull(delivery);
Expand Down

0 comments on commit d056b22

Please sign in to comment.