Java Basic


  1. How can junits be implemented using maven?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    JUnits can be used using dependency tag in maven in pom.xml. The version as desired and available in repository can be used.


  1. What is used to inject mock fields into the tested object automatically?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    @InjectMocks annotation is used to inject mock fields into the tested object automatically.



  1. How can we simulate if then behavior in Junits?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Mockito.when(mockList.size()).thenReturn(100); assertEquals(100, mockList.size()); is the usage to implement if and then behavior.


  1. How to let junits know that they need to be run using PowerMock?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    @RunWith(PowerMockRunner.class) signifies to use PowerMock JUnit runner. Along with that @PrepareForTest(User.class) is used to declare the class being tested. mockStatic(Resource.class) is used to mock the static methods.



  1. What does assertSame() method use for assertion?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    == is used to compare the objects not the content. assertSame() method compares to check if actual and expected are the same objects. It does not compare their content.