Java8 Qualis Interview Questions & Answers 2022

Java8 Qualis Interview Questions

Intermediate Assessment on JUnit

1.In JUnit 4, all core classes reside in org.junit package.

1) False
2) True
Correct Answer of above question is:
Answer: 2)True

2.Which of the following is not an optional parameter defined for the @Test annotation?

1) None of the options
2) timeout
3) expected
4) threadcount
Correct Answer of above question is:
Answer: 4)threadcount

3.Which of the following annotation causes that method run after each test methods?

1) @test
2) @BeforeAll
3) @AfterAll
4) @AfterEach
Correct Answer of above question is:
Answer: 4)@AfterEach

Intermediate Assessment on JUnit

1.Which JUnit annotation allows you to define order of execution for the test methods?

1) @FixMethodOrder
2) @DefineOrder
3) @Rule
4) @Ignore
Correct Answer of above question is:
Answer: 1) @FixMethodOrder

2.Logical collection of test classes can be bundled together to form a __.

1) Fixture
2) Suite
3) Runner
4) Filter
Correct Answer of above question is:
Answer: 2)Suite

3.Test cases are executed with a fixed state of object which can be a baseline for running tests to ensure the results are repeatable, such object are called __.

1) Froster
2) Frontier
3) Fixture
4) StableSet
Correct Answer of above question is:
Answer: 3)Fixture

Quiz on Mockito

1.Mockito framework offers _ to compute on-the-fly results.

1) Stubbing
2) AdaptiveResponse
3) Setbacks
4) Callbacks
Correct Answer of above question is:
Answer: 4)Callbacks

2.Mockito can mock private methods.

1) True
2) False
Correct Answer of above question is:
Answer: 2)False

3.Mockito can throw an exception using which of the following?

1) when().thenReturn()
2) doWhen().thenThrow()
3) when().thenAnswer()
4) when().thenThrow()
Correct Answer of above question is:
Answer: 4)when().thenThrow()

Quiz on Mock MVC

1.Integration of JUnit and the Spring Test context framework is done by _ runner.

1) HierarchicalContextRunner
2) MockitoJUnitRunner
3) SpringJUnit4ClassRunner
4) Cucumber Runner
Correct Answer of above question is:
Answer: 3)SpringJUnit4ClassRunner

2._ forms the integral part of Spring Testing framework.

1) PowerMVC
2) PowerMock
3) MockMVC
4) Mockito
Correct Answer of above question is:
Answer: 3)MockMVC

3.MockMvc builder __ tests one controller at a time.

1) annotationConfigSetup
2) webAppContextSetup
3) standaloneSetup
4) xmlConfigSetup
Correct Answer of above question is:
Answer: 3)standaloneSetup

JaCoCo – Quiz

1.JaCoCo is an open source code coverage tool that generates coverage reports by instrumenting Java byte code.

1) True
2) False
Correct Answer of above question is:
Answer: 1) True

2.JaCoCo collects events from __ for performing code coverage analysis.

1) JVM TI
2) ASM
3) JDK
4) Java agent
Correct Answer of above question is:
Answer: 1) JVM TI

3.JaCoCo can be integrated with which Continuous Integration tools?

1) Jenkins
2) Travis
3) None of the options
4) Codeship Inc
Correct Answer of above question is:
Answer: 1) Jenkins

Quiz on FindBugs

1.FindBugs tool analyzes Java source code.

1) True
2) False
Correct Answer of above question is:
Answer: 2)False

2.Bugs ranking from Rank 1 to 4 are classified as __.

1) Troubling
2) Scariest
3) OfConcern
4) Scary
Correct Answer of above question is:
Answer: 2)Scariest

3.This comes under which category of a bug: “Using string concatenation in a loop rather than using a StringBuffer?”

1) Bad Practice
2) Dodgy code
3) All the options
4) Performance
Correct Answer of above question is:
Answer: 4)Performance

Final Assessment on Java8 Qualis Interview Questions & Answers

1.100% code coverage guarantees effective testing.

1) True
2) False
Correct Answer of above question is:
Answer: 2)False

2.Which among the following is a Java mocking framework?

PowerMock
1) All the options
2) Mockito
3) EasyMock
Correct Answer of above question is:
Answer: 2)All the options

3.JUnit can be integrated with build automation tools like Maven, Ant, Gradle etc.

1) False
2) True
Correct Answer of above question is:
Answer: 2)True

4.With the latest JUnit framework, each test class you write should be a sub-class of TestCase class.

1) False
2) True
Correct Answer of above question is:
Answer: 1) False

5.Checkstyle checks for

a. Naming conventions of methods.

b. Space between certain characters.

c. Line length and number of lines in method/class

d. Catching an exception without doing anything.

1) Options: a,c & d
2) Options: a, b & c
3) Options: b,c & d
4) Options: a,b & d
Correct Answer of above question is:
Answer: 2)Options: a, b & c

6.Which of the following ‘id’ is not a feature of JUnit?

1) Plagiarism
2) Fixtures
3) Test Runners
4) Assertion
Correct Answer of above question is:
Answer: 1) Plagiarism

7.Code coverage can be used for _.

1) White box testing
2) Black box testing
3) Bug fixing
4) None of the options
Correct Answer of above question is:
Answer: 1) White box testing

8.FindBugs is an open source static code analysis tool. True or False.

1) True
2) False
Correct Answer of above question is:
Answer: 1) True

9.Which among the following is not a JaCoCo-Maven integration goal?

1) JaCoCo:dump
2) JaCoCo:Prepare-agent
3) JaCoCo:report
4) JaCoCo:separate
Correct Answer of above question is:
Answer: 4)JaCoCo:separate

10.Which annotation helps you to disable a test method?

1) @Hide
2) @Ignore
3) @Test
4) @Disable
Correct Answer of above question is:
Answer: 4)@Disable

11.With Mockito, one can verify that a method has been called n times.

1) True
2) False
Correct Answer of above question is:
Answer: 1) True

12.Select the correct syntax for creating MockMvc instance for EmployeeController,java.

1) this.mockMvc = MockMvcBuilders.standaloneSetup();
2) this.mockMvc = MockMvcBuilders.standaloneSetup (employeeController).build();
3) this.mockMvc = MockMvcBuilders.standaloneSetup (employeeController);
4) this.mockMvc = MockMvcBuilders.standaloneSetup (employeeController).setup();
Correct Answer of above question is:
Answer: 2)this.mockMvc = MockMvcBuilders.standaloneSetup (employeeController).build();

13.@Captor annotation is used for creation of _.

1) ExceptiontCaptor
2) ResponseCaptor
3) ArgumentCaptor
4) MockCaptor
Correct Answer of above question is:
Answer: 3)ArgumentCaptor

14.FindBugs report – findbugs.html will be generated in the folder __ in the project directory with Maven integration.

1) target/test
2) target/bugs
3) target/site
4) target/findbugs
Correct Answer of above question is:
Answer: 3)target/site

15.Which of the following is a static method offered by MockMvcRequestBuilders class.

a. get

b. post

c. patch

d. delete

1) a,b & d
2) c&d
3) a&b
4) a,b,c &d
Correct Answer of above question is:
Answer: 4)a,b,c &d

16.Can FindBugs identify security holes related to SQL injections?

1) False
2) True
Correct Answer of above question is:
Answer: 2)True

17.Which annotation will set ApplicationContext for the test class with the configuration file from class path specified?

1) @ApplicationContext
2) @ClasspathConfiguration
3) @WebAppConfiguration
4) @ContextConfiguration
Correct Answer of above question is:
Answer: 4)@ContextConfiguration

18.MockMvc requests are executed by calling perform methods by passing _ as argument.

1) ResponseBuilder
2) ArguementBuilder
3) ResultBuilder
4) RequestBuilder
Correct Answer of above question is:
Answer: 4)RequestBuilder

19.Which of the following is a JUnit extension?

1) Postgres
2) Cactus
3) Litmus
4) Thymus
Correct Answer of above question is:
Answer: 2)Cactus

20.Assertion methods for test cases are included in which JUnit class?

1) Assertions
2) Assume
3) CoreMatchers
4) Test
Correct Answer of above question is:
Answer: 1) Assertions

Java8 Qualis Fresco Play Handson Solutions from 2022

Java8 Qualis Handson Solution

Course Path: Microservices/Construction/Java8 Qualis

Suggestion: Just Copy whole code from below and replace with existing code on hackerrank.

  1. Welcome to Hands On – Junit

File Name – SolutionTest.java (under src->test folder)

package com.tcs.fresco;

import static junit. framework.Assert.*;

import java.util.HashMap;

import java.util.Map;

import org.junit.After;

import org.junit.Before;

import junit.framework.Test;

import junit.framework.TestCase;

import junit.framework.TestSuite;

public class SolutionTest extends TestCase{

Map<Integer, String> customerTag = null;

           int custId = 0;

           Solution solution = new Solution();



@Before

           public void setUp() throws Exception {

                          custId = 10511;

                          customerTag = new HashMap<Integer, String>();

           }



//Write your test cases here



public void test() {

           assertTrue( true );

}



@org.junit.Test

public void testValidUser(){

  solution.saveCustomer(this.custId, "Tej");

  assertTrue(solution.isCustomerExist("Tej"));

}

 @org.junit.Test

public void testinValidUser(){

  solution.saveCustomer(this.custId, "Tej");

  assertFalse(solution.isCustomerExist("Tej1"));

}



@After

           public void tearDown() throws Exception {

                    customerTag.clear();


           }

}

2.Hands-on Mockito

File Name- UserAuthenticatorTest.java

package com.tcs.fresco;

/* Write static mocks for Assert and Mockito classes. -Q1 */

import static org.junit.Assert.*;

import static org.mockito.Mockito.doThrow;

//Write import statements for Mockito classes.

import static org.mockito.Mockito.mock;

import static org.mockito.Mockito.when;

import org.junit.Before;

import org.junit.BeforeClass;

import org.junit.Test;

public class UserAuthenticatorTest {

           UserAuthenticator authenticator = new UserAuthenticator();

           public static UserAuthenticatorInterface authenticatorMock;





           @BeforeClass

           public static void setUp() {

  /* Create mock object using static mock configuration  -Q2 */

  //Write your code here

   authenticatorMock = mock(UserAuthenticatorInterface.class);



           }



           @Before

           public void setUpAuthenticator() {

                          authenticator.setUserAuthenticator(authenticatorMock);

           }



             /*Complete the test case with the expected exception -Q3 */



  // Write your code here

@Test(expected = FailedToAuthenticateException.class)

           public void testAuthenticate_InvalidCredentials() throws FailedToAuthenticateException {



                          String username = "User1";

                          String password = "wrong password";

                          String errorMessage = "Invalid credentials .Authentication Failed";



    /*Throw exception using doThrow...when configuration - Q4*/

    // Write your code here

doThrow(new FailedToAuthenticateException(errorMessage)).when(authenticatorMock).authenticateUser("User1", "wrong password");

                          authenticator.authenticateUser(username, password);



           }



           @Test

           public void testAuthenticate_ValidCredentials() throws FailedToAuthenticateException {



                          String username = "User1";

                          String password = "Password";

               /*Configure Returning True with when...thenReturn configuration on mock Object - Q5*/

    //Write your code here

when(authenticatorMock.authenticateUser(username, password)).thenReturn(true);

                          assertTrue(authenticator.authenticateUser(username, password));



           }



           @Test(expected=FailedToAuthenticateException.class)

           public void testAuthenticate_EmptyCredentials() throws FailedToAuthenticateException {



                          String username = "";

                          String password = "";

    String errorMessage= "Credentials cannot be empty";

    /*Configure Throwing exception using when...thenThrow configuration on mock Object - Q6*/  

    //Write your code here

   when(authenticatorMock.authenticateUser(username, password)).thenThrow(new FailedToAuthenticateException(errorMessage));

                authenticator.authenticateUser(username, password);

    authenticator.authenticateUser(username, password);



           }

@Test()

public void dummytest(){

    assertEquals(1,1);

}

}

3.MockMvc: Hands-on

No need to write code just submit and it will clear.

4.Checkstyle: Hands-on

No need to write code just submit and it will clear.

5.FindBugs: Hands-on

No need to write code just submit and it will clear.

6.JaCoCo: Hands-on

No need to write code just submit and it will clear.

About Author


After years of Technical Work, I feel like an expert when it comes to Develop wordpress website. Check out How to Create a Wordpress Website in 5 Mins, and Earn Money Online Follow me on Facebook for all the latest updates.