> Java 8 Qualis Hands-On Solutions - TECH UPDATE

Java 8 Qualis Hands-On Solutions

 Java 8 Qualis Hands-On Solutions 

The main agenda of this solution is those who are unable to do this course due to facing some issues, a little bit of lack of knowledge on these hands-on questions. Try to understand these codes and solve your hands-On Problems. (Not encourage copy and paste these solutions).

The course Id of Java 8 Qualis is 56911

1. JUnit Hands-On






  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. Mockito 




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





No Need to write the Test Cases

4. Checkstyle




No need to write the Test Cases


5. FindBugs




No need to write anything just submit


6. JoCoCo 




No Need to write anything just submit 


Thank You 
Java 8 Qualis Hands-On Solutions Java 8 Qualis Hands-On Solutions Reviewed by TECH UPDATE on August 29, 2021 Rating: 5

No comments:

Powered by Blogger.