Skip to content

Commit

Permalink
Replace nextOrThrow in ApplicationErrorJdbc with one from KiwiJdbc (#329
Browse files Browse the repository at this point in the history
)

* Replace usages of ApplicationErrorJdbc#nextOrThrow with the
  one from KiwiJdbc
* Remove the nextOrThrow method from ApplicationErrorJdbc; this
  was never in an actual release so doesn't break any existing code
  and doesn't require a major version bump
* Remove the nextOrThrow tests from ApplicationErrorJdbcTest; we
  don't need to test it anymore since it's now the one in KiwiJdbc

Closes #321
  • Loading branch information
sleberknight authored Nov 26, 2023
1 parent 122b83b commit 12b8603
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 46 deletions.
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

0 comments on commit 12b8603

Please sign in to comment.