diff --git a/lib/JapaChar/Random.pm b/lib/JapaChar/Random.pm index e6456e6..608ebd8 100644 --- a/lib/JapaChar/Random.pm +++ b/lib/JapaChar/Random.pm @@ -9,7 +9,7 @@ use Moo; use Crypt::URandom qw( urandom ); -sub get($min = 1, $max = 100) { +sub get($class, $min = 1, $max = 100) { my $rng = urandom(4); $rng = unpack 'L', $rng; $rng = ($rng % $max) + $min; diff --git a/t/01-characters.t b/t/01-characters.t index 0744a52..ac4bb40 100644 --- a/t/01-characters.t +++ b/t/01-characters.t @@ -5,7 +5,7 @@ use v5.38.2; use strict; use warnings; -use Test::Most tests => 2; +use Test::Most tests => 3; use Test::MockModule; use Path::Tiny; @@ -14,6 +14,7 @@ use File::Basename; use lib dirname(dirname(__FILE__)).'/lib'; use JapaChar::DB; +use JapaChar::Random; BEGIN { use_ok 'JapaChar::Characters'; @@ -24,5 +25,16 @@ BEGIN { $mock_db->mock(_db_path => sub { return path(__FILE__)->parent->child('all-learned-basic-characters.db'); }); + my $mock_random = Test::MockModule->new('JapaChar::Random'); + $mock_random->mock(get => sub { + return 100; + }); + my $mock_characters = Test::MockModule->new('JapaChar::Characters'); + my $called_next_review_char = 0; + $mock_characters->mock(_next_review_char => sub { + $called_next_review_char = 1; + return $mock_characters->original('_next_review_char')->(@_); + }); ok defined(JapaChar::Characters->new->next_char), 'The next char is defined.'; + ok $called_next_review_char, 'The next char is a review.'; }