I am new to mockito Junit testing.This one is my main class which i want to test
package com.ge.health.gam.contactge.util;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@Component
public class IlinqChecksumCalculator {
private static Logger DATA_LOADER_CHECKSUM_CALCULATOR_LOGGER = Logger.getLogger(IlinqChecksumCalculator.class);
public String calculateCheckSum(String rfsdata) throws IOException {
System.out.println(rfsdata);
String checkSumValue = null;
if (StringUtils.isNotBlank(rfsdata)) {
try {
// Create MessageDigest object for MD5
MessageDigest digest = MessageDigest.getInstance("MD5");
// Update input string in message digest
digest.update(rfsdata.getBytes(), 0, rfsdata.getBytes().length);
// Converts message digest value in base 16 (hex)
checkSumValue = new BigInteger(1, digest.digest()).toString(16);
} catch (NoSuchAlgorithmException exception) {
DATA_LOADER_CHECKSUM_CALCULATOR_LOGGER.error(
"Error in determineInputCheckSum() method during calculation of checksum for Input JSON String for ",
exception);
}
}
System.out.println("Final checksum value is:" + checkSumValue);
return checkSumValue;
}
}
this one is my test class
package com.ge.health.gam.contactge.util.test;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
import com.ge.health.gam.contactge.util.IlinqChecksumCalculator;
@RunWith(MockitoJUnitRunner.class)
public class IlinqChecksumCalculatorTest {
private IlinqChecksumCalculator ilinqCheckSum;
@Before
public void setUp() throws Throwable {
MockitoAnnotations.initMocks(this);
}
@Test
public void testCheckSum() throws IOException {
when(ilinqCheckSum.calculateCheckSum("abcde")).thenReturn("defgh");
assertEquals("defgh", ilinqCheckSum.calculateCheckSum("abcde"));
}
}
I am new to mockito Junit testing.This one is my main class which i want to test I am new to mockito Junit testing.This one is my main class which i want to test I am getting null pointer exception...
Aucun commentaire:
Enregistrer un commentaire