package org.example;

import org.example.Entity.Control.Base.Component;
import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import static org.junit.jupiter.api.Assertions.assertSame;

class JdbcTemplateReuseRegressionTest {

    @Test
    void componentReusesInjectedJdbcTemplateWhenResolvingDbOperator() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(new DriverManagerDataSource());
        TestComponent component = new TestComponent();
        component.setJdbcTemplate(jdbcTemplate);

        assertSame(jdbcTemplate, component.dbOperator());
    }

    private static class TestComponent extends Component {
        void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
            this.jdbcTemplate = jdbcTemplate;
        }

        JdbcTemplate dbOperator() {
            return getDbOperator();
        }
    }
}
