本文整理汇总了Java中gov.samhsa.c2s.common.util.UniqueValueGenerator类的典型用法代码示例。如果您正苦于以下问题:Java UniqueValueGenerator类的具体用法?Java UniqueValueGenerator怎么用?Java UniqueValueGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UniqueValueGenerator类属于gov.samhsa.c2s.common.util包,在下文中一共展示了UniqueValueGenerator类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGenerateUniqueValue_Success_First_Trial
import gov.samhsa.c2s.common.util.UniqueValueGenerator; //导入依赖的package包/类
@Test
public void testGenerateUniqueValue_Success_First_Trial() {
// Arrange
AtomicInteger counter = new AtomicInteger(0);
// Act
String value = UniqueValueGenerator.generateUniqueValue(
() -> TEST_VALUE, v -> {
counter.incrementAndGet();
return true;
}, LIMIT);
// Assert
assertEquals(TEST_VALUE, value);
assertEquals(1, counter.get());
}
示例2: testGenerateUniqueValue_Throws_UniqueValueGeneratorException_Last_Trial1
import gov.samhsa.c2s.common.util.UniqueValueGenerator; //导入依赖的package包/类
@Test
public void testGenerateUniqueValue_Throws_UniqueValueGeneratorException_Last_Trial1() {
// Arrange
AtomicInteger counter = new AtomicInteger(0);
thrown.expect(UniqueValueGeneratorException.class);
// Act
String value = null;
try {
value = UniqueValueGenerator.generateUniqueValue(() -> TEST_VALUE,
v -> {
counter.incrementAndGet();
return false;
}, LIMIT);
} catch (Exception e) {
// Assert
assertEquals(null, value);
assertEquals(LIMIT, counter.get());
throw e;
}
}
示例3: testGenerateUniqueValue_Throws_UniqueValueGeneratorException_Last_Trial2
import gov.samhsa.c2s.common.util.UniqueValueGenerator; //导入依赖的package包/类
@Test
public void testGenerateUniqueValue_Throws_UniqueValueGeneratorException_Last_Trial2() {
// Arrange
AtomicInteger counter = new AtomicInteger(0);
thrown.expect(UniqueValueGeneratorException.class);
// Act
String value = null;
try {
value = UniqueValueGenerator.generateUniqueValue(() -> TEST_VALUE,
v -> counter.incrementAndGet() > LIMIT, LIMIT);
} catch (Exception e) {
// Assert
assertEquals(null, value);
assertEquals(LIMIT, counter.get());
throw e;
}
}
示例4: generatePolicyId
import gov.samhsa.c2s.common.util.UniqueValueGenerator; //导入依赖的package包/类
@Override
public String generatePolicyId(ConsentDto consentDto, String mrn) {
final short iterationLimit = 3;
return UniqueValueGenerator
.generateUniqueValue(() -> generateRandomPolicyId(consentDto, mrn),
generatedValue -> consentRepository.findAllByConsentReferenceId(generatedValue)
.size() == 0, iterationLimit);
}
示例5: generateMrn
import gov.samhsa.c2s.common.util.UniqueValueGenerator; //导入依赖的package包/类
@Override
public String generateMrn() {
final short iterationLimit = 3;
return UniqueValueGenerator
.generateUniqueValue(this::generateRandomMrn,
generatedValue -> patientRepository
.findAllByMedicalRecordNumber(generatedValue)
.size() == 0, iterationLimit);
}
示例6: testGenerateUniqueValue_Success_Last_Trial
import gov.samhsa.c2s.common.util.UniqueValueGenerator; //导入依赖的package包/类
@Test
public void testGenerateUniqueValue_Success_Last_Trial() {
// Arrange
AtomicInteger counter = new AtomicInteger(0);
// Act
String value = UniqueValueGenerator.generateUniqueValue(
() -> TEST_VALUE, v -> counter.incrementAndGet() >= LIMIT,
LIMIT);
// Assert
assertEquals(TEST_VALUE, value);
assertEquals(LIMIT, counter.get());
}
示例7: generateEmailToken
import gov.samhsa.c2s.common.util.UniqueValueGenerator; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public String generateEmailToken() {
short trialLimit = 3;
return UniqueValueGenerator.generateUniqueValue(tokenGenerator::generateToken, this::isUnique, trialLimit);
}