Last active
December 17, 2015 19:09
-
-
Save jonatasemidio/5658146 to your computer and use it in GitHub Desktop.
Mock UnitTest with DataSource
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
import grails.test.mixin.TestFor | |
@TestFor(DadosService) | |
class DadosServiceTests { | |
void test_obtemDados() { | |
def dadosBuscasService = new DadosBuscasService() | |
def result = ['CVT', '2', '2', 'AAAA', 'Grat'] | |
def sqlUtilService = [select: {result}] as SqlUtilService | |
dadosBuscasService.sqlUtilService = sqlUtilService | |
service.dadosBuscasService = dadosBuscasService | |
assert result == service.obtemDados(1) | |
} | |
} |
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
package br.gov.rj.faetec.assunto.transporte.exportarRioCardGratuidade | |
import br.com.montreal.grails.util.SqlUtilService | |
import br.gov.rj.faetec.modulo.transporte.exportarRioCardGratuidade.ExportarRioCardGratuidadeBuscasService | |
import grails.test.mixin.TestFor | |
/** | |
* See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions | |
*/ | |
@TestFor(ExportarRioCardGratuidadeService) | |
class ExportarRioCardGratuidadeServiceTests { | |
void test_obtemDadosParaNomeDoArquivo() { | |
def exportarRioCardGratuidadeBuscasService = new ExportarRioCardGratuidadeBuscasService() | |
def result = ['CVT', '2', '2', 'AAAA', 'Grat'] | |
def sqlUtilService = [select: {result}] as SqlUtilService | |
exportarRioCardGratuidadeBuscasService.sqlUtilService = sqlUtilService | |
service.exportarRioCardGratuidadeBuscasService = exportarRioCardGratuidadeBuscasService | |
assert result == service.obtemDadosParaNomeDoArquivo(1) | |
} | |
} |
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
class DadosBuscasService{ | |
def sqlUtilService | |
def obtemDados(int codigo){ | |
def sql = "select sigla, codigo, numero, nome, sobrenome from dados where codigo = ${codigo}" | |
return sqlUtilService.select(sql) | |
} | |
} |
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
class DadosService{ | |
def dadosBuscasService | |
def obtemDados(int codigo){ | |
return dadosBuscasService.obtemDados(codigo) | |
} | |
} |
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
import groovy.sql.Sql | |
class SqlUtilService { | |
def dataSource | |
def select(String query) { | |
Sql sql = new Sql(dataSource); | |
return sql.rows(query) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment