@Test @Parameters(method = "classGenericDefinitionSuccess") public void testClassGenericDefinitionSuccess(Class<?> type) { testXKindGenericDefinitionSuccess(type); }
@Test @Parameters(method = "methodGenericDefinitionSuccess") public void testMethodGenericDefinitionSuccess(Class<?> type) { testXKindGenericDefinitionSuccess(type); }
@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()) ); } }
@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(); }
@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); }
@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); }
@Test @Parameters public void testGetCacheKey(DimensionSpec dimensionSpec, boolean expectedResult) { Assert.assertEquals(expectedResult, Arrays.equals(lookupDimSpec.getCacheKey(), dimensionSpec.getCacheKey())); }
@Test @Parameters(source = FieldType.class) public void readWritesFieldGivenPdxFieldType(FieldType fieldType) throws Exception { setupResultSet(resultSet, fieldType); when(resultSet.next()).thenReturn(true).thenReturn(false); PdxInstanceFactory factory = setupPdxInstanceFactory(fieldType); when(regionMapping.getFieldNameForColumn(eq(COLUMN_NAME_1), any())) .thenReturn(PDX_FIELD_NAME_1); createPdxInstance(); verifyPdxFactoryWrite(factory, fieldType); verify(factory).create(); }
@Test @Parameters(method = "getCommands") public void whenLastReceivedIsNotSetThenCheckAndSetLastResultSentIfValidMustReturnFalse( BaseCommand baseCommand) { ServerToClientFunctionResultSender resultSender = mock(ServerToClientFunctionResultSender.class); when(resultSender.isLastResultReceived()).thenReturn(false); assertTrue(baseCommand.setLastResultReceived(resultSender)); }
@Test @Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"}) public void runAndExpectValueRepeatedly_failsIfExceptionIsThrown(Execution execution) { concurrencyRule.add(callWithOneExceptionAndRepeatCount).expectValue(expectedRetVal) .repeatForIterations(5); assertThatThrownBy(() -> execution.execute(concurrencyRule)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining(expectedException.getMessage()); assertThat(iterations.get()).isEqualTo(stopIteration); }
@Test @Parameters({MAC_OSX_NAME, LINUX_OS_NAME, SOLARIS_OS_NAME, WINDOWS_OS_NAME}) public void shouldUseComputerNameIfAvailableOnOS(String osName) throws IOException { setHostNameProperties(osName); String result = new HostName().determineHostName(); assertThat(result).isEqualTo(EXPECTED_HOSTNAME); }
@Test @Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"}) public void runAndExpectExceptionAndCauseTypes_wrongCauseTypeFails(Execution execution) { concurrencyRule.add(callWithExceptionAndCause) .expectExceptionType(expectedExceptionWithCause.getClass()) .expectExceptionCauseType(IllegalStateException.class); assertThatThrownBy(() -> execution.execute(concurrencyRule)).isInstanceOf(AssertionError.class); }
@Test(expected = FallbackDefinitionException.class) @Parameters(method = "methodGenericDefinitionFailure") public void testMethodGenericDefinitionFailure(Class<?> type) { Object p = createProxy(type); executeCommand(p); }
@Test(expected = FallbackDefinitionException.class) @Parameters(method = "classGenericDefinitionFailure") public void testClassGenericDefinitionFailure(Class<?> type) { Object p = createProxy(type); executeCommand(p); }
@Parameters @Test public void testSerDesr(DimensionSpec lookupDimSpec) throws IOException { ObjectMapper mapper = new DefaultObjectMapper(); mapper.registerSubtypes(new NamedType(LookupDimensionSpec.class, "lookup")); InjectableValues injectableValues = new InjectableValues.Std().addValue( LookupReferencesManager.class, LOOKUP_REF_MANAGER ); String serLookup = mapper.writeValueAsString(lookupDimSpec); Assert.assertEquals(lookupDimSpec, mapper.readerFor(DimensionSpec.class).with(injectableValues).readValue(serLookup)); }
@Test @Parameters(method = "getCompiledValuesWhichDoNotImplementGetReceiver") public void whenGetReceiverIsNotImplementedThenHasIdentifierAtLeafMustReturnFalse( CompiledValue compiledValue) { assertFalse(compiledValue.hasIdentifierAtLeafNode()); }
@Test @Parameters(method = "getCompiledValuesWhichImplementGetReceiver") public void whenGetReceiverIsImplementedThenHasIdentifierAtLeafMustReturnTrue( CompiledValue compiledValue) { assertTrue(compiledValue.hasIdentifierAtLeafNode()); }
@Test @Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"}) public void runAndExpectExceptionAndCauseTypes(Execution execution) { concurrencyRule.add(callWithExceptionAndCause) .expectExceptionType(expectedExceptionWithCause.getClass()) .expectExceptionCauseType(expectedExceptionWithCause.getCause().getClass()); execution.execute(concurrencyRule); }
@Test @Parameters({"EXECUTE_IN_SERIES", "EXECUTE_IN_PARALLEL"}) public void runAndExpectExceptionCauseType(Execution execution) { concurrencyRule.add(callWithExceptionAndCause) .expectExceptionCauseType(expectedExceptionWithCause.getCause().getClass()); execution.execute(concurrencyRule); }
@Test @Parameters({MAC_OSX_NAME, LINUX_OS_NAME, SOLARIS_OS_NAME, WINDOWS_OS_NAME}) public void shouldExecHostNameIfEnvValueNotAvailableOnOS(String osName) throws IOException { setHostNamePropertiesNull(osName); String result = new HostName().determineHostName(); assertThat(result).isNotNull(); }