Sophisticated behavior

Report a typo

Inspect the following class and the test and write the value of the result that will be printed to the console:

Class:

public class SomeClass {

    public int getValue(int value) {
        return value == 10 ? -value : value;
    }
}

Test:

import org.junit.jupiter.api.Test;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class MyTest {
    private SomeClass someMock = mock(SomeClass.class);

    @Test
    void test() {
        when(someMock.getValue(anyInt())).thenReturn(8);
        when(someMock.getValue(0)).thenReturn(2);

        int arg1 = someMock.getValue(10);
        int arg2 = someMock.getValue(3);
        int arg3 = someMock.getValue(0);

        int result = arg1 + arg2 + arg3;
        System.out.println(result);
    }
}
Enter a number
___

Create a free account to access the full topic