All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.util.ArrayUtilImplTest.ftl Maven / Gradle / Ivy

Go to download

Maven plugin to generate Java classes from StoredProcedure and Functions in Database

There is a newer version: 1.8.20
Show newest version
package ${javaPackage}.${utilFolderName};
<#assign importList = ["java.sql.Connection", "java.sql.SQLException", "com.github.javafaker.Faker"]>
<#if driverName == 'oracle'>
<#assign importList = importList + ["oracle.jdbc.OracleConnection"]>
<#if driverVersionName == 'ojdbc6' >
<#assign importList = importList + ["oracle.sql.ARRAY"]>
<#else>
<#assign importList = importList + ["java.sql.Array"]>


<#assign importList = importList + ["org.mockito.Mock", "org.mockito.Mockito"]>
<#if junit == 'junit5'>
<#assign importList = importList + ["org.junit.jupiter.api.extension.ExtendWith", "org.mockito.junit.jupiter.MockitoExtension", "org.junit.jupiter.api.Assertions", "org.junit.jupiter.api.BeforeEach", "org.junit.jupiter.api.Test"]>
<#else>
<#assign importList = importList + ["org.junit.runner.RunWith", "org.mockito.runners.MockitoJUnitRunner", "org.junit.Assert", "org.junit.Before", "org.junit.Test"]>

<#assign importList = importList + ["org.mockito.ArgumentCaptor", "org.mockito.Captor", "org.mockito.Mock", "org.mockito.Mockito"]>

<#list importSort(importList) as import>
<#if previousImportMatch?? && !import?starts_with(previousImportMatch)>


import ${import};
<#assign previousImportMatch = import?keep_before_last(".") >

<#if importList?has_content>


<#if junit == 'junit5'>
@ExtendWith(MockitoExtension.class)
<#else>
@RunWith(MockitoJUnitRunner.class)

class ${prefixUtilityName}ArrayUtilImplTest {
<#if driverName == 'oracle'>

    @Mock
    private OracleConnection oracleConnectionMock;


    @Mock
    private <#if driverVersionName == 'ojdbc6' >ARRAY<#else>Array arrayMock;

    @Mock
    private Connection connectionMock;

    private Faker faker;

    private ${prefixUtilityName}ArrayUtil arrayUtil;

    @<#if junit == 'junit5'>BeforeEach<#else>Before
    void setUp() {
        faker = new Faker();
        arrayUtil = new ${prefixUtilityName}ArrayUtilImpl();
    }
<#if driverName == 'oracle' >

    @Test
    void testProcessArray() throws SQLException {
        Object[] objects = new Object[0];
        String nameValue = faker.internet().uuid();

        Mockito.when(connectionMock.unwrap(OracleConnection.class)).thenReturn(oracleConnectionMock);
        Mockito.when(oracleConnectionMock.<#if driverVersionName == 'ojdbc6' >createARRAY<#else>createOracleArray(Mockito.anyString(), Mockito.same(objects))).thenReturn(arrayMock);

        Object result = arrayUtil.process(connectionMock, nameValue, objects);

        <#if junit == 'junit5'>Assertions<#else>Assert.assertNotNull(result);
        <#if junit == 'junit5'>Assertions<#else>Assert.assertSame(arrayMock, result);

        Mockito.verify(oracleConnectionMock).<#if driverVersionName == 'ojdbc6' >createARRAY<#else>createOracleArray(Mockito.eq(nameValue), Mockito.same(objects));
    }


    @Test<#if junit != 'junit5'>(expected = SQLException.class)
    void testProcessArrayError()<#if driverName == 'oracle'> throws SQLException {
        Object[] objects = new Object[0];
        String nameValue = faker.internet().uuid();
<#if driverName == 'oracle' >

        Mockito.when(connectionMock.unwrap(OracleConnection.class)).thenReturn(oracleConnectionMock);
        Mockito.when(oracleConnectionMock.<#if driverVersionName == 'ojdbc6' >createARRAY<#else>createOracleArray(Mockito.anyString(), Mockito.same(objects))).thenThrow(new RuntimeException());


        <#if junit == 'junit5'>Assertions.assertThrows(SQLException.class,() -> arrayUtil.process(connectionMock, nameValue, objects)<#if junit == 'junit5'>);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy