-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage for PostgreSQLEnumDataTypeHelper
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...gresql/src/test/java/schemacrawler/integration/test/PostgreSQLEnumDataTypeHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package schemacrawler.integration.test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static schemacrawler.plugin.EnumDataTypeInfo.EnumDataTypeTypes.not_enumerated; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import schemacrawler.plugin.EnumDataTypeInfo; | ||
import schemacrawler.schema.Column; | ||
import schemacrawler.schema.ColumnDataType; | ||
import schemacrawler.server.postgresql.PostgreSQLEnumDataTypeHelper; | ||
|
||
public class PostgreSQLEnumDataTypeHelperTest { | ||
|
||
@Test | ||
public void testGetEnumDataTypeInfo() throws Exception { | ||
final Column column = mock(Column.class); | ||
final ColumnDataType columnDataType = mock(ColumnDataType.class); | ||
final Connection connection = mock(Connection.class); | ||
|
||
when(columnDataType.getName()).thenReturn("enum_type"); | ||
when(connection.createStatement()).thenReturn(mock(java.sql.Statement.class)); | ||
when(connection.createStatement().executeQuery(Mockito.anyString())) | ||
.thenReturn(mock(java.sql.ResultSet.class)); | ||
|
||
final PostgreSQLEnumDataTypeHelper helper = new PostgreSQLEnumDataTypeHelper(); | ||
final EnumDataTypeInfo enumDataTypeInfo = | ||
helper.getEnumDataTypeInfo(column, columnDataType, connection); | ||
|
||
assertThat(enumDataTypeInfo.getType(), is(not_enumerated)); | ||
|
||
final List<String> enumValues = enumDataTypeInfo.getEnumValues(); | ||
|
||
assertThat(enumValues.size(), is(0)); | ||
} | ||
|
||
@Test | ||
public void testSQLException() throws Exception { | ||
final Column column = mock(Column.class); | ||
final ColumnDataType columnDataType = mock(ColumnDataType.class); | ||
final Connection connection = mock(Connection.class); | ||
|
||
when(columnDataType.getName()).thenReturn("enum_type"); | ||
when(connection.createStatement()).thenThrow(SQLException.class); | ||
|
||
final PostgreSQLEnumDataTypeHelper helper = new PostgreSQLEnumDataTypeHelper(); | ||
final EnumDataTypeInfo enumDataTypeInfo = | ||
helper.getEnumDataTypeInfo(column, columnDataType, connection); | ||
|
||
assertThat(enumDataTypeInfo.getType(), is(not_enumerated)); | ||
|
||
final List<String> enumValues = enumDataTypeInfo.getEnumValues(); | ||
|
||
assertThat(enumValues.size(), is(0)); | ||
} | ||
} |