本文整理了Java中junitparams.Parameters
类的一些代码示例,展示了Parameters
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parameters
类的具体详情如下:
包路径:junitparams.Parameters
类名称:Parameters
暂无
代码示例来源:origin: apache/geode
@Test
@Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"})
public void runAndExpectNoException_withReturn(Execution execution) {
concurrencyRule.add(() -> {
invoked.set(true);
return true;
});
execution.execute(concurrencyRule);
assertThat(invoked.get()).isTrue();
}
代码示例来源:origin: pl.pragmatists/JUnitParams
@Override
public boolean isApplicable() {
return annotation != null
&& annotation.source().isAssignableFrom(NullType.class)
&& annotation.method().isEmpty()
&& !annotation.named().isEmpty();
}
}
代码示例来源:origin: pl.pragmatists/JUnitParams
@Override
public Object[] getParameters() {
Class<?> sourceClass = annotation.source();
return !annotation.method().isEmpty()
? paramsFromMethodCommon.paramsFromMethod(sourceClass)
: paramsFromMethodCommon.paramsFromNamedMethod(sourceClass);
}
代码示例来源:origin: pl.pragmatists/JUnitParams
Object[] paramsFromNamedMethod(Class<?> sourceClass) {
String namedMethodAnnotation = frameworkMethod.getAnnotation(Parameters.class).named();
if (namedMethodAnnotation.isEmpty()) {
return invokeMethodWithParams(defaultMethodName(), sourceClass);
}
List<Object> result = new ArrayList<Object>();
for (String name : namedMethodAnnotation.split(",")) {
for (Object param : invokeNamedMethodWithParams(name.trim(), sourceClass))
result.add(param);
}
return result.toArray();
}
代码示例来源:origin: pl.pragmatists/JUnitParams
Object[] paramsFromMethod(Class<?> sourceClass) {
String methodAnnotation = frameworkMethod.getAnnotation(Parameters.class).method();
if (methodAnnotation.isEmpty()) {
return invokeMethodWithParams(defaultMethodName(), sourceClass);
}
List<Object> result = new ArrayList<Object>();
for (String methodName : methodAnnotation.split(",")) {
for (Object param : invokeMethodWithParams(methodName.trim(), sourceClass))
result.add(param);
}
return result.toArray();
}
代码示例来源:origin: pl.pragmatists/JUnitParams
@Override
public boolean isApplicable() {
return annotation != null
&& !annotation.source().isAssignableFrom(NullType.class)
&& annotation.method().isEmpty()
&& annotation.named().isEmpty();
}
代码示例来源:origin: PipelineAI/pipeline
@Test
@Parameters(method = "classGenericDefinitionSuccess")
public void testClassGenericDefinitionSuccess(Class<?> type) {
testXKindGenericDefinitionSuccess(type);
}
代码示例来源:origin: pl.pragmatists/JUnitParams
@Override
public boolean isApplicable() {
return annotation != null
&& !annotation.source().isAssignableFrom(NullType.class)
&& (!annotation.method().isEmpty() || ! annotation.named().isEmpty());
}
}
代码示例来源:origin: PipelineAI/pipeline
@Test
@Parameters(method = "methodGenericDefinitionSuccess")
public void testMethodGenericDefinitionSuccess(Class<?> type) {
testXKindGenericDefinitionSuccess(type);
}
代码示例来源:origin: pl.pragmatists/JUnitParams
@Override
public boolean isApplicable() {
return annotation != null
&& annotation.source().isAssignableFrom(NullType.class)
&& (!annotation.method().isEmpty() || paramsFromMethodCommon.containsDefaultParametersProvidingMethod(testClass))
&& annotation.named().isEmpty();
}
}
代码示例来源:origin: apache/incubator-druid
@Test
@Parameters
public void testApply(DimensionSpec dimensionSpec, Map<String, String> map)
{
for (Map.Entry<String, String> entry : map.entrySet()) {
Assert.assertEquals(
NullHandling.emptyToNullIfNeeded(entry.getValue()),
dimensionSpec.getExtractionFn().apply(entry.getKey())
);
}
}
代码示例来源:origin: apache/geode
@Test
@Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"})
public void runAndExpectValue_failsForWrongValue(Execution execution) {
concurrencyRule.add(callWithRetVal).expectValue(Integer.valueOf(3));
assertThatThrownBy(() -> execution.execute(concurrencyRule))
.isInstanceOf(AssertionError.class);
assertThat(invoked.get()).isTrue();
}
代码示例来源:origin: apache/geode
@Test
@Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"})
public void repeatUntilValue_throwsIfValueIsNeverTrue(Execution execution) {
boolean expectedVal = true;
retVal.set(false);
concurrencyRule.add(callWithEventuallyCorrectRetVal)
.repeatUntilValue(expectedVal)
.repeatForDuration(Duration.ofSeconds(2));
assertThatThrownBy(() -> execution.execute(concurrencyRule))
.isInstanceOf(ComparisonFailure.class);
assertThat(invoked.get()).isTrue();
}
代码示例来源:origin: apache/geode
@Test
@Parameters(method = "getCommands")
public void whenLastReceivedIsSetThenCheckAndSetLastResultSentIfValidMustNotSetIt(
BaseCommand baseCommand) {
ServerToClientFunctionResultSender resultSender =
mock(ServerToClientFunctionResultSender.class);
when(resultSender.isLastResultReceived()).thenReturn(true);
baseCommand.setLastResultReceived(resultSender);
verify(resultSender, times(0)).setLastResultReceived(true);
}
代码示例来源:origin: apache/geode
@Test
@Parameters(method = "getCommands")
public void whenLastReceivedIsNotSetThenCheckAndSetLastResultSentIfValidMustSetIt(
BaseCommand baseCommand) {
ServerToClientFunctionResultSender resultSender =
mock(ServerToClientFunctionResultSender.class);
when(resultSender.isLastResultReceived()).thenReturn(false);
baseCommand.setLastResultReceived(resultSender);
verify(resultSender, times(1)).setLastResultReceived(true);
}
代码示例来源:origin: apache/geode
@Test
@Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"})
public void runAndExpectException_throwableInstance_wrongClass_fails(Execution execution) {
Callable<?> callable = () -> {
throw new IllegalArgumentException("foo");
};
concurrencyRule.add(callable).expectException(new NullPointerException("foo"));
assertThatThrownBy(() -> execution.execute(concurrencyRule))
.isInstanceOf(AssertionError.class);
}
代码示例来源:origin: apache/geode
@Test
@Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"})
public void runAndExpectNoException_withNoReturn(Execution execution) {
concurrencyRule.add(ConcurrencyRule.toCallable(() -> invoked.set(true)));
execution.execute(concurrencyRule);
assertThat(invoked.get()).isTrue();
}
代码示例来源:origin: apache/geode
@Test
@Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"})
public void repeatForIterations(Execution execution) {
int expectedIterations = 4;
this.iterations.set(0);
concurrencyRule.add(callWithRetValAndRepeatCount).repeatForIterations(4);
execution.execute(concurrencyRule);
assertThat(this.iterations.get()).isEqualTo(expectedIterations);
}
代码示例来源:origin: apache/geode
@Test
@Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"})
public void repeatForIterationsAndExpectValueForEach_failsWithOneWrongValue(Execution execution) {
int expectedIterations = 4;
this.iterations.set(0);
concurrencyRule.add(callWithRetValAndRepeatCountAndOneWrongValue).expectValue(expectedRetVal)
.repeatForIterations(expectedIterations);
assertThatThrownBy(() -> execution.execute(concurrencyRule)).isInstanceOf(AssertionError.class);
assertThat(this.iterations.get()).isEqualTo(stopIteration);
}
代码示例来源:origin: apache/geode
@Test
@Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"})
public void runAndExpectException_throwableInstance_wrongMessage_fails(Execution execution) {
Callable<?> callable = () -> {
throw new NullPointerException("foo");
};
concurrencyRule.add(callable).expectException(new NullPointerException("bar"));
assertThatThrownBy(() -> execution.execute(concurrencyRule))
.isInstanceOf(AssertionError.class);
}
内容来源于网络,如有侵权,请联系作者删除!