@Override
  public synchronized void addFunction(final KsqlScalarFunction ksqlFunction) {
    final UdfFactory udfFactory = udfs.get(ksqlFunction.name().text().toUpperCase());
    if (udfFactory == null) {
      throw new KsqlException("Unknown function factory: " + ksqlFunction.name());
    }
    udfFactory.addFunction(ksqlFunction);
  }
@Test
  public void shouldNotAddFunctionWithSameNameAsExistingFunctionAndOnDifferentClass() {
    // Given:
    givenUdfFactoryRegistered();

    final KsqlScalarFunction func2 = KsqlScalarFunction.createLegacyBuiltIn(
        SqlTypes.STRING,
        Collections.emptyList(),
        func.name(),
        Func2.class);

    functionRegistry.addFunction(func);

    // When:
    final Exception e = assertThrows(
        KsqlException.class,
        () -> functionRegistry.addFunction(func2)
    );

    // Then:
    assertThat(e.getMessage(), containsString(
        "a function with the same name exists in a different class"));
  }