ApexMocks Number Matching Methods

A reference guide for the ApexMocks library's number matching methods. It includes examples for both stubbing responses and verifying behaviour.

Number Matchers

The methods are all accessible as static methods of the fflib_Match class.

decimalMoreThan(lower)

Matches on any Decimal that is greater than the specified lower argument (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDecimal()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.decimalMoreThan(100.0)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 100.0 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(100.0));
System.assertEquals('MATCH', mockApi.getStatus(100.01));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(100.0);
mockApi.getStatus(100.01);

// Passing verify statement
// Not inclusive so 100.0 not included in the count
((MyApi)mocks.verify(mockApi, 1))
    .getStatus(fflib_Match.decimalMoreThan(100.0));

decimalMoreThan(lower, isInclusive)

Matches on any Decimal more than the specified lower argument. Inclusivity determined by isInclusive.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDecimal()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(fflib_Match.decimalMoreThan(100.0, isInclusive)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Is inclusive so 100.0 is a match
System.assertEquals('MATCH', mockApi.getStatus(100.0));
System.assertEquals('MATCH', mockApi.getStatus(100.01));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(100.0);
mockApi.getStatus(100.01);

// Passing verify statement
// Is inclusive so 100.0 is included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.decimalMoreThan(100.0, isInclusive));

decimalLessThan(upper)

Matches on any Decimal less than the specified upper argument (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDecimal()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.decimalLessThan(100.0)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
System.assertEquals('MATCH', mockApi.getStatus(99.99));
// Not inclusive so 100.0 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(100.0));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(99.99);
mockApi.getStatus(100.00);

// Passing verify statement
// Not inclusive so 100.0 not included in the count
((MyApi)mocks.verify(mockApi, 1))
    .getStatus(fflib_Match.decimalLessThan(100.0));

decimalLessThan(upper, isInclusive)

Matches on any Decimal less than the specified upper argument. Inclusivity determined by isInclusive.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDecimal()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.decimalLessThan(100.0, isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
System.assertEquals('MATCH', mockApi.getStatus(99.99));
// Is inclusive so 100.0 is a match
System.assertEquals('MATCH', mockApi.getStatus(100.00));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(99.99);
mockApi.getStatus(100.00);

// Passing verify statement
// Is inclusive so 100.0 is included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.decimalLessThan(100.0, true));

decimalBetween(lower, upper)

Matches on any Decimal between the specified lower and upper arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDecimal()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(
        fflib_Match.decimalBetween(100.0, 200.0)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 100.0 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(100.0));
System.assertEquals('MATCH', mockApi.getStatus(100.01));
System.assertEquals('MATCH', mockApi.getStatus(199.99));
// Not inclusive so 200.0 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(200.0));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(100.00);
mockApi.getStatus(100.01);
mockApi.getStatus(199.99);
mockApi.getStatus(200.0);

// Passing verify statement
// Not inclusive so 100.0 and 200.00 not included in the count
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.decimalBetween(100.0, 200.0));

decimalBetween(lower, isInclusive, upper, isInclusive)

Matches on any Decimal between the specified lower and upper arguments. Inclusivity determined by isInclusive arguments.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDecimal()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.decimalBetween(100.0, isInclusive, 200.0, isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Is inclusive so 100.0 is a match
System.assertEquals('MATCH', mockApi.getStatus(100.00));
System.assertEquals('MATCH', mockApi.getStatus(100.01));
System.assertEquals('MATCH', mockApi.getStatus(199.99));
// Is inclusive so 200.0 is a match
System.assertEquals('MATCH', mockApi.getStatus(200.00));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(100.00);
mockApi.getStatus(100.01);
mockApi.getStatus(199.99);
mockApi.getStatus(200.00);

// Passing verify statement
// Is inclusive so 100.0 and 200.0 are included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 4))
    .getStatus(fflib_Match.decimalBetween(100.0, isInclusive, 200.0, isInclusive));

anyDecimal()

Matches on any non-null Decimal.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus((Decimal)fflib_Match.isNull()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.anyDecimal()))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
Decimal nullDecimal = null;
System.assertEquals('DEFAULT', mockApi.getStatus(nullDecimal));
System.assertEquals('MATCH', mockApi.getStatus(-1000000.0));
System.assertEquals('MATCH', mockApi.getStatus(0.0));
System.assertEquals('MATCH', mockApi.getStatus(1000000.0));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
Decimal nullDecimal = null;
mockApi.getStatus(nullDecimal);
mockApi.getStatus(-1000000.0);
mockApi.getStatus(0.0);
mockApi.getStatus(1000000.0);

// Passing verify statement
((MyApi)mocks.verify(mockApi, 3))
    .getStatus(fflib_Match.anyDecimal());

doubleMoreThan(lower)

Matches on any Double that is greater than the specified lower arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDouble()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(
        fflib_Match.doubleMoreThan(Double.valueOf(100.0))))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 100.0 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(Double.valueOf(100.0)));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(100.01)));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(Double.valueOf(100.0));
mockApi.getStatus(Double.valueOf(100.01));

// Passing verify statement
// Not inclusive so 100.0 not included in the count
((MyApi)mocks.verify(mockApi, 1))
    .getStatus(fflib_Match.doubleMoreThan(Double.valueOf(100.0)));

doubleMoreThan(lower, isInclusive)

Matches on any Double more than the specified lower arguments. Inclusivity determined by isInclusive.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDouble()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.doubleMoreThan(Double.valueOf(100.0), isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Is inclusive so 100.0 is a match
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(100.0)));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(100.01)));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(Double.valueOf(100.0));
mockApi.getStatus(Double.valueOf(100.01));

// Passing verify statement
// Is inclusive so 100.0 is included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(
        fflib_Match.doubleMoreThan(
        Double.valueOf(100.0), isInclusive
    ));

doubleLessThan(upper)

Matches on any Double less than the specified upper arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDouble()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(
        fflib_Match.doubleLessThan(Double.valueOf(100.0))))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(99.99)));
// Not inclusive so 100.0 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(Double.valueOf(100.0)));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(Double.valueOf(99.99));
mockApi.getStatus(Double.valueOf(100.00));

// Passing verify statement
// Not inclusive so 100.0 not included in the count
((MyApi)mocks.verify(mockApi, 1))
    .getStatus(fflib_Match.doubleLessThan(Double.valueOf(100.0)));

doubleLessThan(upper, isInclusive)

Matches on any Double less than the specified upper arguments. Inclusivity determined by isInclusive.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDouble()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.doubleLessThan(Double.valueOf(100.0), isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test

System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(99.99)));
// Is inclusive so 100.0 is a match
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(100.0)));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(Double.valueOf(99.99));
mockApi.getStatus(Double.valueOf(100.00));

// Passing verify statement
// Is inclusive so 100.0 is included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.doubleLessThan(Double.valueOf(100.0), true));

doubleBetween(lower, upper)

Matches on any Double between the specified lower and upper arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDouble()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(
        fflib_Match.doubleBetween(
            Double.valueOf(100.0),
            Double.valueOf(200.0))))
                .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 100.0 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(Double.valueOf(100.0)));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(100.01)));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(199.99)));
// Not inclusive so 200.0 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(Double.valueOf(200.0)));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(Double.valueOf(100.00));
mockApi.getStatus(Double.valueOf(100.01));
mockApi.getStatus(Double.valueOf(199.99));
mockApi.getStatus(Double.valueOf(200.00));

// Passing verify statement
// Not inclusive so 100.0 and 200.00 not included in the count
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.doubleBetween(
        Double.valueOf(100.0),
        Double.valueOf(200.0)
    ));

doubleBetween(lower, isInclusive, upper, isInclusive)

Matches on any Double between the specified lower and upper arguments. Inclusivity determined by isInclusive arguments.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyDouble()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.doubleBetween(
            Double.valueOf(100.0), isInclusive,
            Double.valueOf(200.0), isInclusive)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Is inclusive so 100.0 is a match
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(100.00)));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(100.01)));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(199.99)));
// Is inclusive so 200.0 is a match
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(200.0)));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(Double.valueOf(100.00));
mockApi.getStatus(Double.valueOf(100.01));
mockApi.getStatus(Double.valueOf(199.99));
mockApi.getStatus(Double.valueOf(200.00));

// Passing verify statement
// Is inclusive so 100.0 and 200.00 are included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 4))
    .getStatus(fflib_Match.doubleBetween(
        Double.valueOf(100.0), isInclusive,
        Double.valueOf(200.0), isInclusive
    ));

anyDouble()

Matches on any non-null Double.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus((Double)fflib_Match.isNull()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.anyDouble()))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
Double nullDouble = null;
System.assertEquals('DEFAULT', mockApi.getStatus(nullDouble));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(-1000000.0)));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(0.0)));
System.assertEquals('MATCH', mockApi.getStatus(Double.valueOf(1000000.0)));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
Double nullDouble = null;
mockApi.getStatus(nullDouble);
mockApi.getStatus(Double.valueOf(-1000000.0));
mockApi.getStatus(Double.valueOf(0.0));
mockApi.getStatus(Double.valueOf(1000000.0));

// Passing verify statement
((MyApi)mocks.verify(mockApi, 3))
    .getStatus(fflib_Match.anyDouble());

integerMoreThan(lower)

Matches on any Integer that is greater than the specified lower arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyInteger()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.integerMoreThan(100)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 100 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(100));
System.assertEquals('MATCH', mockApi.getStatus(101));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(100);
mockApi.getStatus(101);

// Passing verify statement
// Not inclusive so 100 not included in the count
((MyApi)mocks.verify(mockApi, 1))
    .getStatus(fflib_Match.integerMoreThan(100));

integerMoreThan(lower, isInclusive)

Matches on any Integer more than the specified lower arguments. Inclusivity determined by isInclusive.

Stubbing Example

// // Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyInteger()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.integerMoreThan(100, isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Is inclusive so 100 is a match
System.assertEquals('MATCH', mockApi.getStatus(100));
System.assertEquals('MATCH', mockApi.getStatus(101));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(100);
mockApi.getStatus(101);

// Passing verify statement
// Is inclusive so 100 is included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.integerMoreThan(100, isInclusive));

integerLessThan(upper)

Matches on any Integer less than the specified upper arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyInteger()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.integerLessThan(100)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
System.assertEquals('MATCH', mockApi.getStatus(99));
// Not inclusive so 100 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(100));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(99);
mockApi.getStatus(100);

// Passing verify statement
// Not inclusive so 100 not included in the count
((MyApi)mocks.verify(mockApi, 1))
    .getStatus(fflib_Match.integerLessThan(100));

integerLessThan(upper, isInclusive)

Matches on any Integer less than the specified upper arguments. Inclusivity determined by isInclusive.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyInteger()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.integerLessThan(100, isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
System.assertEquals('MATCH', mockApi.getStatus(99));
// Is inclusive so 100 is a match
System.assertEquals('MATCH', mockApi.getStatus(100));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(99);
mockApi.getStatus(100);

// Passing verify statement
// Is inclusive so 100 is included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.integerLessThan(100, isInclusive));

integerBetween(lower, upper)

Matches on any Integer between the specified lower and upper arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyInteger()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.integerBetween(100, 200)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 100 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(100));
System.assertEquals('MATCH', mockApi.getStatus(101));
System.assertEquals('MATCH', mockApi.getStatus(199));
// Not inclusive so 200 is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(200));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(100);
mockApi.getStatus(101);
mockApi.getStatus(199);
mockApi.getStatus(200);

// Passing verify statement
// Not inclusive so 100 and 200 not included in the count
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.integerBetween(100, 200));

integerBetween(lower, isInclusive, upper, isInclusive)

Matches on any Integer between the specified lower and upper arguments. Inclusivity determined by isInclusive arguments.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyInteger()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.integerBetween(100, isInclusive, 200, isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Is inclusive so 100 is a match
System.assertEquals('MATCH', mockApi.getStatus(100));
System.assertEquals('MATCH', mockApi.getStatus(101));
System.assertEquals('MATCH', mockApi.getStatus(199));
// Is inclusive so 200 is a match
System.assertEquals('MATCH', mockApi.getStatus(200));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(100);
mockApi.getStatus(101);
mockApi.getStatus(199);
mockApi.getStatus(200);

// Passing verify statement
// Is inclusive so 100 and 200 are included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 4))
    .getStatus(fflib_Match.integerBetween(
        100, isInclusive, 200, isInclusive));

anyInteger()

Matches on any non-null Integer.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus((Integer)fflib_Match.isNull()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.anyInteger()))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
Integer nullInteger = null;
System.assertEquals('DEFAULT', mockApi.getStatus(nullInteger));
// Min Integer value for 32-bit number
System.assertEquals('MATCH', mockApi.getStatus(-2147483647));
System.assertEquals('MATCH', mockApi.getStatus(0));
// Max Integer value for 32-bit number
System.assertEquals('MATCH', mockApi.getStatus(2147483647));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
Integer nullInteger = null;
mockApi.getStatus(nullInteger);
// Min Integer value for 32-bit number
mockApi.getStatus(-2147483647);
mockApi.getStatus(0);
// Max Integer value for 32-bit number
mockApi.getStatus(2147483647);

// Passing verify statement
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 3))
    .getStatus(fflib_Match.anyInteger());

longMoreThan(lower)

Matches on any Long that is greater than the specified lower arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyLong()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.longMoreThan(1000L)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 1000L is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(1000L));
System.assertEquals('MATCH', mockApi.getStatus(1001L));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(1000L);
mockApi.getStatus(1001L);

// Passing verify statement
// Not inclusive so 1000L not included in the count
((MyApi)mocks.verify(mockApi, 1))
    .getStatus(fflib_Match.longMoreThan(1000L));

longMoreThan(lower, isInclusive)

Matches on any Long more than the specified lower arguments. Inclusivity determined by isInclusive.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyLong()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.longMoreThan(1000L, isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Is inclusive so 1000L is a match
System.assertEquals('MATCH', mockApi.getStatus(1000L));
System.assertEquals('MATCH', mockApi.getStatus(1001L));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(1000L);
mockApi.getStatus(1001L);

// Passing verify statement
// Is inclusive so 1000L is included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.longMoreThan(1000L, isInclusive));

longLessThan(upper)

Matches on any Long less than the specified upper arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyLong()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.longLessThan(1000L)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 1000L is not a match
System.assertEquals('MATCH', mockApi.getStatus(999L));
System.assertEquals('DEFAULT', mockApi.getStatus(1000L));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(999L);
mockApi.getStatus(1000L);

// Passing verify statement
// Not inclusive so 1000L not included in the count
((MyApi)mocks.verify(mockApi, 1))
    .getStatus(fflib_Match.longLessThan(1000L));

longLessThan(upper, isInclusive)

Matches on any Long less than the specified upper arguments. Inclusivity determined by isInclusive.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyLong()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(fflib_Match.longLessThan(1000L, isInclusive)))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
System.assertEquals('MATCH', mockApi.getStatus(999L));
// Is inclusive so 1000L is a match
System.assertEquals('MATCH', mockApi.getStatus(1000L));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(999L);
mockApi.getStatus(1000L);

// Passing verify statement
// Is inclusive so 1000L is included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.longLessThan(1000L, isInclusive));

longBetween(lower, upper)

Matches on any Long between the specified lower and upper arguments (not inclusive).

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyLong()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(
        fflib_Match.longBetween(1000L, 2000L)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Not inclusive so 1000L is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(1000L));
System.assertEquals('MATCH', mockApi.getStatus(1001L));
System.assertEquals('MATCH', mockApi.getStatus(1999L));
// Not inclusive so 2000L is not a match
System.assertEquals('DEFAULT', mockApi.getStatus(2000L));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(1000L);
mockApi.getStatus(1001L);
mockApi.getStatus(1999L);
mockApi.getStatus(2000L);

// Passing verify statement
// Not inclusive so 1000L and 2000L not included in the count
((MyApi)mocks.verify(mockApi, 2))
    .getStatus(fflib_Match.longBetween(1000L, 2000L));

longBetween(lower, isInclusive, upper, isInclusive)

Matches on any Long between the specified lower and upper arguments. Inclusivity determined by isInclusive arguments.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus(fflib_Match.anyLong()))
        .thenReturn('DEFAULT');
    Boolean isInclusive = true;
    mocks.when(mockApi.getStatus(
        fflib_Match.longBetween(1000L, isInclusive, 2000L, isInclusive)))
            .thenReturn('MATCH');
mocks.stopStubbing();

// Test
// Is inclusive so 1000L is a match
System.assertEquals('MATCH', mockApi.getStatus(1000L));
System.assertEquals('MATCH', mockApi.getStatus(1001L));
System.assertEquals('MATCH', mockApi.getStatus(1999L));
// Is inclusive so 2000L is a match
System.assertEquals('MATCH', mockApi.getStatus(2000L));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
mockApi.getStatus(1000L);
mockApi.getStatus(1001L);
mockApi.getStatus(1999L);
mockApi.getStatus(2000L);

// Passing verify statement
// Is inclusive so 1000L and 2000L are included in the count
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 4))
    .getStatus(fflib_Match.longBetween(1000L, isInclusive, 2000L, isInclusive));

anyLong()

Matches on any non-null Long.

Stubbing Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

mocks.startStubbing();
    mocks.when(mockApi.getStatus((Long)fflib_Match.isNull()))
        .thenReturn('DEFAULT');
    mocks.when(mockApi.getStatus(fflib_Match.anyLong()))
        .thenReturn('MATCH');
mocks.stopStubbing();

// Test
Long nullLong = null;
System.assertEquals('DEFAULT', mockApi.getStatus(nullLong));
System.assertEquals('MATCH', mockApi.getStatus(-12147483647L));
System.assertEquals('MATCH', mockApi.getStatus(0L));
System.assertEquals('MATCH', mockApi.getStatus(12147483647L));

Verify Example

// Setup
fflib_ApexMocks mocks = new fflib_ApexMocks();
MyApi mockApi = (MyApi)mocks.mock(MyApi.class);

// Test
Long nullLong = null;
mockApi.getStatus(nullLong);
mockApi.getStatus(-12147483647L);
mockApi.getStatus(0L);
mockApi.getStatus(12147483647L);

// Passing verify statement
Boolean isInclusive = true;
((MyApi)mocks.verify(mockApi, 3))
    .getStatus(fflib_Match.anyLong());