-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Test class for BytesUtil (#783)
* Created test class for IdTypeUtil => IdTypeUtilTest * Created test class for IdTypeUtil => IdTypeUtilTest * Created test class for IdTypeUtil => IdTypeUtilTest * Created test class for BytesUtil => BytesUtilTest * Created test class for BytesUtil => BytesUtilTest * Created test class for BytesUtil => BytesUtilTest * Created test class for BytesUtil => BytesUtilTest * Created test class for BytesUtil => BytesUtilTest * Created test class for HotlistScheduledCleanupJob => HotlistScheduledCleanupJobTest Co-authored-by: Vipul Dhurve <[email protected]>
- Loading branch information
1 parent
6deaa5d
commit 2c23fd2
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...on/authentication-core/src/test/java/io/mosip/authentication/core/util/BytesUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package io.mosip.authentication.core.util; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.TestContext; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
|
||
@WebMvcTest | ||
@ContextConfiguration(classes = {TestContext.class, WebApplicationContext.class}) | ||
@RunWith(SpringRunner.class) | ||
public class BytesUtilTest { | ||
|
||
@InjectMocks | ||
private BytesUtil bytesUtil; | ||
|
||
/** | ||
* This class tests the prependZeros method | ||
*/ | ||
@Test | ||
public void prependZerosTest(){ | ||
byte[] str = {(byte)0xe0, 0x4f, (byte)0xd0, | ||
0x20, (byte)0xea}; | ||
int n=3; | ||
//[B@39dec536 | ||
byte[] expected = {0, 0, 0, -32, 79, -48, 32, -22 }; | ||
Assert.assertArrayEquals(expected, bytesUtil.prependZeros(str, n)); | ||
} | ||
|
||
/** | ||
* This class tests the getXOR method | ||
*/ | ||
@Test | ||
public void getXORTest(){ | ||
//length of b > leangth of a | ||
String a = "test", b = "sample"; | ||
byte[] expected = {115, 97, 25, 21, 31, 17}; | ||
Assert.assertArrayEquals(expected, ReflectionTestUtils.invokeMethod(bytesUtil, "getXOR", a, b)); | ||
//length of a > leangth of b | ||
a = "sample"; | ||
b = "test"; | ||
Assert.assertArrayEquals(expected, ReflectionTestUtils.invokeMethod(bytesUtil, "getXOR", a, b)); | ||
// length of a == length of b | ||
byte[] exp = {0, 0, 0, 0, 0, 0 }; | ||
b="sample"; | ||
Assert.assertArrayEquals(exp, ReflectionTestUtils.invokeMethod(bytesUtil, "getXOR", a, b)); | ||
} | ||
|
||
/** | ||
* This class tests the getLastBytes method | ||
*/ | ||
@Test | ||
public void getLastBytesTest(){ | ||
byte[] xorBytes = {(byte)0xe0, 0x4f, (byte)0xd0, | ||
0x20, (byte)0xea}; | ||
int lastBytesNum = 1; | ||
byte[] ans = {-22}; | ||
Assert.assertArrayEquals(ans, ReflectionTestUtils.invokeMethod(bytesUtil, "getLastBytes", xorBytes, lastBytesNum)); | ||
} | ||
|
||
/** | ||
* This class tests the main method | ||
*/ | ||
@Test | ||
public void mainTest(){ | ||
String[]args = new String[10]; | ||
ReflectionTestUtils.invokeMethod(bytesUtil, "main", (Object) args); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...t/java/io/mosip/authentication/internal/service/batch/HotlistScheduledCleanupJobTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.mosip.authentication.internal.service.batch; | ||
|
||
import io.mosip.authentication.common.service.repository.HotlistCacheRepository; | ||
import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.TestContext; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
@WebMvcTest | ||
@ContextConfiguration(classes ={TestContext.class, WebApplicationContext.class}) | ||
@RunWith(SpringRunner.class) | ||
public class HotlistScheduledCleanupJobTest { | ||
|
||
@InjectMocks | ||
private HotlistScheduledCleanupJob hotlistScheduledCleanupJob; | ||
|
||
@Mock | ||
private IdAuthSecurityManager securityManager; | ||
|
||
@Mock | ||
private HotlistCacheRepository hotlistRepo; | ||
|
||
@Test | ||
public void cleanupUnblockedIdsTest(){ | ||
hotlistScheduledCleanupJob.cleanupUnblockedIds(); | ||
|
||
ReflectionTestUtils.setField(hotlistScheduledCleanupJob, "hotlistRepo", null); | ||
hotlistScheduledCleanupJob.cleanupUnblockedIds(); | ||
} | ||
|
||
@Test | ||
public void cleanupExpiredIds(){ | ||
hotlistScheduledCleanupJob.cleanupExpiredIds(); | ||
|
||
ReflectionTestUtils.setField(hotlistScheduledCleanupJob, "hotlistRepo", null); | ||
hotlistScheduledCleanupJob.cleanupExpiredIds(); | ||
} | ||
} |