Skip to content

Commit

Permalink
Polish "Improve test coverage of RdbmsOperation"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jul 29, 2022
1 parent 608be54 commit f9ee8a9
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,6 @@
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import static java.util.Map.entry;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

Expand All @@ -51,14 +50,6 @@ public void emptySql() {
operation::compile);
}

@Test
public void getSql() {
String sql = "select * from mytable";
operation.setDataSource(new DriverManagerDataSource());
operation.setSql(sql);
String strGotten = operation.getSql();
assertThat(strGotten.equals(sql));
}
@Test
public void setTypeAfterCompile() {
operation.setDataSource(new DriverManagerDataSource());
Expand Down Expand Up @@ -87,38 +78,39 @@ public void tooFewParameters() {

@Test
public void tooFewMapParameters() {
operation.setDataSource(new DriverManagerDataSource());
operation.setSql("select * from mytable");
operation.setTypes(new int[] { Types.INTEGER });
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
operation.validateNamedParameters((Map<String, String>) null));
}

@Test
public void operationConfiguredViaJdbcTemplateMustGetDataSource() throws Exception {
public void operationConfiguredViaJdbcTemplateMustGetDataSource() {
operation.setSql("foo");
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
operation.compile())
.withMessageContaining("ataSource");
.withMessageContaining("'dataSource'");
}

@Test
public void tooManyParameters() {
operation.setDataSource(new DriverManagerDataSource());
operation.setSql("select * from mytable");
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
operation.validateParameters(new Object[] { 1, 2 }));
}
@Test
public void tooManyMapParameters() {
operation.setDataSource(new DriverManagerDataSource());
operation.setSql("select * from mytable");
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
operation.validateNamedParameters(Map.ofEntries(
entry("a", "b"),
entry("c", "d")
) ));
operation.validateNamedParameters(Map.of("a", "b", "c", "d")));
}

@Test
public void unspecifiedMapParameters() {
operation.setDataSource(new DriverManagerDataSource());
operation.setSql("select * from mytable");
Map<String, String> params = new HashMap<>();
params.put("col1", "value");
Expand Down

0 comments on commit f9ee8a9

Please sign in to comment.