Skip to content

refactor: remove redundant check in ReturnMethodSetup#398

Merged
vbreuss merged 2 commits into
mainfrom
topic/refactor-returnmethodsetup
Jan 24, 2026
Merged

refactor: remove redundant check in ReturnMethodSetup#398
vbreuss merged 2 commits into
mainfrom
topic/refactor-returnmethodsetup

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Jan 24, 2026

This PR removes redundant null checks in the ReturnMethodSetup class that were checking if _returnCallbacks.Count == 0 before processing method invocations. These checks are unnecessary because the base class implementation already handles this scenario appropriately.

Key Changes:

  • Removed redundant early-return checks for empty _returnCallbacks from four overloaded GetReturnValue methods
  • Added comprehensive test coverage to verify that the setup behavior works correctly both with and without explicit return values

@vbreuss vbreuss self-assigned this Jan 24, 2026
@vbreuss vbreuss added the coverage Additional tests for edge cases or improvement of test coverage label Jan 24, 2026
Copilot AI review requested due to automatic review settings January 24, 2026 19:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes redundant null checks in the ReturnMethodSetup class that were checking if _returnCallbacks.Count == 0 before processing method invocations. These checks are unnecessary because the base class implementation already handles this scenario appropriately.

Changes:

  • Removed redundant early-return checks for empty _returnCallbacks from four overloaded GetReturnValue methods
  • Added comprehensive test coverage to verify that the setup behavior works correctly both with and without explicit return values

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
Source/Mockolate/Setup/ReturnMethodSetup.cs Removed redundant _returnCallbacks.Count == 0 checks from four GetReturnValue method overloads
Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs Added test cases SetupWithReturn_ShouldUseBaseValue and SetupWithReturn_ShouldIgnoreBaseValue for methods with 0-5 parameters to ensure proper behavior after removing the checks

Comment thread Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs Outdated
Comment thread Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs Outdated
Comment thread Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs Outdated
Comment thread Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs Outdated
@vbreuss vbreuss enabled auto-merge (squash) January 24, 2026 19:57
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 24, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.61GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.102
[Host] : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.579 μs 0.0153 μs 0.0128 μs 0.2270 - 3.73 KB
Simple_Moq 178.966 μs 0.8526 μs 0.7558 μs 0.4883 - 14.71 KB
Simple_NSubstitute 5.784 μs 0.0159 μs 0.0141 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.842 μs 0.0295 μs 0.0276 μs 0.4959 - 8.11 KB

@github-actions
Copy link
Copy Markdown

Test Results

    21 files  ± 0      21 suites  ±0   5m 35s ⏱️ -17s
 2 374 tests + 6   2 373 ✅ + 6  1 💤 ±0  0 ❌ ±0 
15 923 runs  +42  15 922 ✅ +42  1 💤 ±0  0 ❌ ±0 

Results for commit 7b40c13. ± Comparison against base commit 5dab55b.

@vbreuss vbreuss merged commit 07bd5d9 into main Jan 24, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/refactor-returnmethodsetup branch January 24, 2026 20:01
@github-actions
Copy link
Copy Markdown

This is addressed in release v1.0.3.

@github-actions github-actions Bot added the state: released The issue is released label Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coverage Additional tests for edge cases or improvement of test coverage state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants