#programowanie #pracait #java
Mam w #!$%@? dziwny problem z testami jednostkowymi w groovy, odpalam jakikolwiek test i wywala mi atki blad. Robilem juz wszystko, cache, update ide do najnowszych, grzebalem w configu project structure tez wydaje sie byc okej. Ma ktos jakis pomysl co to moze byc? Dodawałem do poma rozne zaleznosci i bez zmian. Na masterze czy devie jest to samo, no ręce rozkladam juz po prostu (╯︵╰
Mam w #!$%@? dziwny problem z testami jednostkowymi w groovy, odpalam jakikolwiek test i wywala mi atki blad. Robilem juz wszystko, cache, update ide do najnowszych, grzebalem w configu project structure tez wydaje sie byc okej. Ma ktos jakis pomysl co to moze byc? Dodawałem do poma rozne zaleznosci i bez zmian. Na masterze czy devie jest to samo, no ręce rozkladam juz po prostu (╯︵╰
Mam pytanie. Posiadam taką klasę pomocniczą do testów:
@Component
public class SessionChecker {
private final DataSource dataSource;
public SessionChecker(DataSource dataSource) {
this.dataSource = dataSource;
}
public boolean checkExistence(String sessionId) {
try {
String query = "SELECT COUNT(*) FROM sessions WHERE session_id = ?";
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, sessionId);
ResultSet resultSet = statement.executeQuery();
return resultSet.next() && resultSet.getInt(1) > 0;
}
} catch (SQLException e) {
Zamiast tego na Twoim miejscu celowałbym w sygnaturę
private boolean checkExistence(String query, PreparedStatement statement)
. Wtedy każda z publicznych metodcheckExistence(String query, Consumer<PreparedStatement> propertySetter) {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
propertySetter.accept(statement);
ResultSet resultSet = statement.executeQuery();
return resultSet.next() && resultSet.getInt(1) > 0;
} catch (SQLException e) {
throw new RuntimeException("Error during checking existence: " + e.getMessage(), e);
}
public boolean userHasActiveSession(int userId) {
String query = "SELECT COUNT(*) FROM sessions WHERE user_id = ?";
return checkExistence(query, st -> st.setInt(1, userId));
}
public boolean sessionExist(String sessionId)