package com.cloudhandson.vpdbackoffice.service;

import static org.mockito.Mockito.verify;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

class ExternalAuthorizationChangeNotifierTest {

  @Test
  void invokesTheOptionalExternalSynchronizerWhenOneIsConfigured() {
    ExternalAuthorizationSynchronizer synchronizer = org.mockito.Mockito.mock(ExternalAuthorizationSynchronizer.class);
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerSingleton("externalAuthorizationSynchronizer", synchronizer);

    new ExternalAuthorizationChangeNotifier(factory.getBeanProvider(ExternalAuthorizationSynchronizer.class))
        .changed("PERMISSION_SAVED");

    verify(synchronizer).synchronize("PERMISSION_SAVED");
  }
}
