Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace nextOrThrow in ApplicationErrorJdbc with one from KiwiJdbc #329

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.kiwiproject.dropwizard.error.dao;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.isNull;
import static java.util.Objects.requireNonNull;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
Expand Down Expand Up @@ -215,10 +214,6 @@ public static ApplicationError mapFrom(ResultSet rs) throws SQLException {
.build();
}

public static void nextOrThrow(ResultSet rs) throws SQLException {
checkState(rs.next(), "ResultSet.next() returned false");
}

/**
* Runtime exception wrapper around JDBC-related exceptions, e.g. {@link SQLException}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static org.kiwiproject.base.KiwiStrings.f;
import static org.kiwiproject.collect.KiwiLists.first;
import static org.kiwiproject.dropwizard.error.dao.ApplicationErrorDao.checkPagingArgumentsAndCalculateZeroBasedOffset;
import static org.kiwiproject.dropwizard.error.dao.ApplicationErrorJdbc.nextOrThrow;
import static org.kiwiproject.jdbc.KiwiJdbc.nextOrThrow;
import static org.kiwiproject.jdbc.KiwiJdbc.timestampFromZonedDateTime;

import org.kiwiproject.dropwizard.error.dao.ApplicationErrorDao;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package org.kiwiproject.dropwizard.error.dao;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.kiwiproject.dropwizard.error.dao.ApplicationErrorJdbc.nextOrThrow;
import static org.kiwiproject.jdbc.KiwiJdbc.nextOrThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import io.dropwizard.db.DataSourceFactory;
import org.h2.Driver;
Expand All @@ -29,7 +24,6 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

@DisplayName("ApplicationErrorJdbc")
Expand Down Expand Up @@ -317,38 +311,6 @@ void shouldReturnTrue_WhenGivenEmbeddedH2DataSourceFactory(String url, boolean i
}
}

@Nested
class NextOrThrow {

private ResultSet resultSet;

@BeforeEach
void setUp() {
resultSet = mock(ResultSet.class);
}

@Test
void shouldAdvanceResultSet() throws SQLException {
when(resultSet.next()).thenReturn(true);

assertThatCode(() -> ApplicationErrorJdbc.nextOrThrow(resultSet))
.doesNotThrowAnyException();

verify(resultSet, only()).next();
}

@Test
void shouldThrowIllegalState_WhenNextReturnsFalse() throws SQLException {
when(resultSet.next()).thenReturn(false);

assertThatIllegalStateException()
.isThrownBy(() -> ApplicationErrorJdbc.nextOrThrow(resultSet))
.withMessage("ResultSet.next() returned false");

verify(resultSet, only()).next();
}
}

@Nested
class ApplicationErrorJdbcExceptionClass {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.kiwiproject.dropwizard.error.dao.jdk;

import static com.google.common.base.Preconditions.checkState;
import static org.kiwiproject.dropwizard.error.dao.ApplicationErrorJdbc.nextOrThrow;
import static org.kiwiproject.jdbc.KiwiJdbc.nextOrThrow;
import static org.kiwiproject.jdbc.KiwiJdbc.timestampFromZonedDateTime;

import org.junit.jupiter.api.AfterEach;
Expand Down