Skip to content

Do not use mockito times 1 as that is already the default and do not use equals were not necessary #3353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/test/java/org/apache/ibatis/jdbc/ScriptRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -44,7 +43,6 @@
import org.apache.ibatis.io.Resources;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

class ScriptRunnerTest extends BaseDataTest {

Expand Down Expand Up @@ -244,11 +242,10 @@ void shouldAcceptDelimiterVariations() throws Exception {
Reader reader = new StringReader(sql);
runner.runScript(reader);

verify(stmt, Mockito.times(1))
.execute(eq("line 1;" + LINE_SEPARATOR + "line 2;" + LINE_SEPARATOR + LINE_SEPARATOR));
verify(stmt, Mockito.times(1)).execute(eq("line 3" + LINE_SEPARATOR));
verify(stmt, Mockito.times(1)).execute(eq("line 4" + LINE_SEPARATOR));
verify(stmt, Mockito.times(1)).execute(eq("line 5" + LINE_SEPARATOR));
verify(stmt).execute("line 1;" + LINE_SEPARATOR + "line 2;" + LINE_SEPARATOR + LINE_SEPARATOR);
verify(stmt).execute("line 3" + LINE_SEPARATOR);
verify(stmt).execute("line 4" + LINE_SEPARATOR);
verify(stmt).execute("line 5" + LINE_SEPARATOR);
}

@Test
Expand Down Expand Up @@ -282,8 +279,7 @@ void shouldAcceptMultiCharDelimiter() throws Exception {
Reader reader = new StringReader(sql);
runner.runScript(reader);

verify(stmt, Mockito.times(1))
.execute(eq("line 1;" + LINE_SEPARATOR + "line 2;" + LINE_SEPARATOR + LINE_SEPARATOR));
verify(stmt, Mockito.times(1)).execute(eq("line 3" + LINE_SEPARATOR));
verify(stmt).execute("line 1;" + LINE_SEPARATOR + "line 2;" + LINE_SEPARATOR + LINE_SEPARATOR);
verify(stmt).execute("line 3" + LINE_SEPARATOR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -138,7 +137,7 @@ void parameterObjectGetPropertyValueWithAdditionalParameter() throws SQLExceptio

defaultParameterHandler.setParameters(ps);

verify(ps, times(1)).setInt(1, 2);
verify(ps).setInt(1, 2);
}

@Test
Expand Down Expand Up @@ -166,7 +165,7 @@ void parameterObjectGetPropertyValueWithNull() throws SQLException {

defaultParameterHandler.setParameters(ps);

verify(ps, times(1)).setNull(1, config.getJdbcTypeForNull().TYPE_CODE);
verify(ps).setNull(1, config.getJdbcTypeForNull().TYPE_CODE);
}

@Test
Expand Down Expand Up @@ -194,7 +193,7 @@ void parameterObjectGetPropertyValueWithTypeHandler() throws SQLException {

defaultParameterHandler.setParameters(ps);

verify(ps, times(1)).setInt(1, (Integer) parameterObject);
verify(ps).setInt(1, (Integer) parameterObject);
}

@Test
Expand Down Expand Up @@ -229,12 +228,12 @@ void parameterObjectGetPropertyValueWithMetaObject() throws SQLException {

defaultParameterHandler.setParameters(ps);

verify(ps, times(1)).setInt(1, parameterObject.getId());
verify(ps, times(1)).setString(2, parameterObject.getUsername());
verify(ps, times(1)).setString(3, parameterObject.getPassword());
verify(ps, times(1)).setString(4, parameterObject.getEmail());
verify(ps, times(1)).setString(5, parameterObject.getBio());
verify(ps, times(1)).setObject(6, parameterObject.getFavouriteSection().name(), JdbcType.VARCHAR.TYPE_CODE);
verify(ps).setInt(1, parameterObject.getId());
verify(ps).setString(2, parameterObject.getUsername());
verify(ps).setString(3, parameterObject.getPassword());
verify(ps).setString(4, parameterObject.getEmail());
verify(ps).setString(5, parameterObject.getBio());
verify(ps).setObject(6, parameterObject.getFavouriteSection().name(), JdbcType.VARCHAR.TYPE_CODE);
}

@Test
Expand Down Expand Up @@ -283,13 +282,13 @@ void parameterObjectGetPropertyValueWithMetaObjectAndCreateOnce() {

defaultParameterHandler.setParameters(ps);

verify(parameterObject, times(1)).getId();
verify(parameterObject, times(1)).getUsername();
verify(parameterObject, times(1)).getPassword();
verify(parameterObject, times(1)).getEmail();
verify(parameterObject, times(1)).getBio();
verify(parameterObject, times(1)).getFavouriteSection();
verify(parameterObject).getId();
verify(parameterObject).getUsername();
verify(parameterObject).getPassword();
verify(parameterObject).getEmail();
verify(parameterObject).getBio();
verify(parameterObject).getFavouriteSection();

verify(mockConfig, times(1)).newMetaObject(parameterObject);
verify(mockConfig).newMetaObject(parameterObject);
}
}
Loading