-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b1c3b97
Showing
9 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app | ||
|
||
import "pjm.dev/mock/calculator" | ||
|
||
type Application struct { | ||
Calculator calculator.Calculatorer | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package app | ||
|
||
func (application *Application) CoolAlgorithm(x int) int { | ||
var output int = x | ||
|
||
output = application.Calculator.Add(output, 0) | ||
output = application.Calculator.Subtract(output, 0) | ||
output = application.Calculator.Multiply(output, 1) | ||
output = application.Calculator.Divide(output, 1) | ||
|
||
return output | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package app_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.uber.org/mock/gomock" | ||
"pjm.dev/mock/app" | ||
"pjm.dev/mock/mock_calculator" | ||
) | ||
|
||
func TestCoolAlgorithm(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockCalculator := mock_calculator.NewMockCalculatorer(ctrl) | ||
|
||
number := 100 | ||
|
||
mockCalculator. | ||
EXPECT(). | ||
Add(number, 0). | ||
Times(1). | ||
Return(number) | ||
|
||
mockCalculator. | ||
EXPECT(). | ||
Subtract(number, 0). | ||
Times(1). | ||
Return(number) | ||
|
||
mockCalculator. | ||
EXPECT(). | ||
Multiply(number, 1). | ||
Times(1). | ||
Return(number) | ||
|
||
mockCalculator. | ||
EXPECT(). | ||
Divide(number, 1). | ||
Times(1). | ||
Return(number) | ||
|
||
application := app.Application{Calculator: mockCalculator} | ||
if application.CoolAlgorithm(number) != number { | ||
t.Fail() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package calculator | ||
|
||
type Calculatorer interface { | ||
Add(int, int) int | ||
Subtract(int, int) int | ||
Multiply(int, int) int | ||
Divide(int, int) int | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package calculator | ||
|
||
type Client struct{} | ||
|
||
func (client *Client) Add(a int32, b int32) int32 { | ||
panic("Can't call this in unit tests!") | ||
} | ||
|
||
func (client *Client) Subtract(a int32, b int32) int32 { | ||
panic("Can't call this in unit tests!") | ||
} | ||
|
||
func (client *Client) Multiply(a int32, b int32) int32 { | ||
panic("Can't call this in unit tests!") | ||
} | ||
|
||
func (client *Client) Divide(a int32, b int32) int32 { | ||
panic("Can't call this in unit tests!") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module pjm.dev/mock | ||
|
||
go 1.21.1 | ||
|
||
require go.uber.org/mock v0.3.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo= | ||
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.