File size: 3,097 Bytes
2795186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package amlsim;

import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

import java.util.Random;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

public class TargetedTransactionAmountTests {
    public Random random;

    @BeforeEach
    void beforeEach()
    {
        this.random = new Random(1);

    }

    @Test
    void testTargetIsMin()
    {
        SimProperties mockedSimProperties = mock(SimProperties.class);
        when(mockedSimProperties.getMinTransactionAmount()).thenReturn(100.0);
        when(mockedSimProperties.getMaxTransactionAmount()).thenReturn(200.0);

        try (MockedStatic<AMLSim> mocked = mockStatic(AMLSim.class)) {
            mocked.when(AMLSim::getSimProp).thenReturn(mockedSimProperties);
            TargetedTransactionAmount transactionAmount = new TargetedTransactionAmount(100.0, this.random);
            assertEquals(100.0, transactionAmount.doubleValue());
        }
    }


    @Test
    void testTargetIsMid()
    {
        SimProperties mockedSimProperties = mock(SimProperties.class);
        when(mockedSimProperties.getMinTransactionAmount()).thenReturn(100.0);
        when(mockedSimProperties.getMaxTransactionAmount()).thenReturn(200.0);

        try (MockedStatic<AMLSim> mocked = mockStatic(AMLSim.class)) {
            mocked.when(AMLSim::getSimProp).thenReturn(mockedSimProperties);
            TargetedTransactionAmount transactionAmount = new TargetedTransactionAmount(150.0, this.random);
            assertEquals(150.0, transactionAmount.doubleValue());
        }
    }


    @Test
    void testTargetIsMidWideRange()
    {
        SimProperties mockedSimProperties = mock(SimProperties.class);
        when(mockedSimProperties.getMinTransactionAmount()).thenReturn(100.0);
        when(mockedSimProperties.getMaxTransactionAmount()).thenReturn(4000.0);

        try (MockedStatic<AMLSim> mocked = mockStatic(AMLSim.class)) {
            mocked.when(AMLSim::getSimProp).thenReturn(mockedSimProperties);
            TargetedTransactionAmount transactionAmount = new TargetedTransactionAmount(300.0, this.random);
            assertTrue(transactionAmount.doubleValue() <= 300.0);
            assertTrue(transactionAmount.doubleValue() >= 100.0);
        }
    }


    @Test
    void testTargetIsBelowMin()
    {
        SimProperties mockedSimProperties = mock(SimProperties.class);
        when(mockedSimProperties.getMinTransactionAmount()).thenReturn(100.0);
        when(mockedSimProperties.getMaxTransactionAmount()).thenReturn(4000.0);

        try (MockedStatic<AMLSim> mocked = mockStatic(AMLSim.class)) {
            mocked.when(AMLSim::getSimProp).thenReturn(mockedSimProperties);
            TargetedTransactionAmount transactionAmount = new TargetedTransactionAmount(40.0, this.random);
            assertEquals(40.0, transactionAmount.doubleValue());
        }
    }
}