> 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

11 comments:

  1. HI bro,

    Thank you so much for this, can you please recheck for Mockito once 1/4 test cases are not passing.

    ReplyDelete
    Replies
    1. in the last test case assertEquals(1,1); instead of 0,1

      Delete
  2. Hi bro,
    thank you for this, can you please recheck once for mockito, all the test cases are not getting passed.

    ReplyDelete
  3. my junit program is executed and i get build success, but in fresco play it is showing not passes, from three days i have facing the issue, please help me

    ReplyDelete
    Replies
    1. Yeah.. Facing the same issue

      Delete
    2. facing the same issue again and again. Kindly help.

      Delete
  4. Hello!
    Tried to solve Junit hands-on many times but unable to clear everytime.
    Even copy-pasting this entire code didn't help me to clear it.

    What to do now? Please help

    ReplyDelete
  5. Yes , please check once Mockito ,it is not passing testcases

    ReplyDelete
  6. Hi
    Can you please provide code for wings1 T1 courses, 62638...

    ReplyDelete
  7. Hi
    I am trying a course again and again and not able to complete it, can you please help me in this course
    #mini project .net backend development using .net core hands on
    Ievolve id 63433
    This is frescoplay handson in hacker rank
    Thanks and regards
    Bhanu

    ReplyDelete
  8. Hi
    I am trying a course again and again and not able to complete it, can you please help me in this course
    #mini project .net backend development using .net core hands on
    Ievolve id 63433
    This is frescoplay handson in hacker rank
    Thanks and regards
    Bhanu

    ReplyDelete

Powered by Blogger.