/** * {@inheritDoc} * <p> * If possible the given {@code filter} is wrapped by {@link DataProviderFilter} to enable filtering of tests using * a dataprovider. * * @param filter the {@link Filter} to be wrapped or apply, respectively */ @Override public void filter(Filter filter) throws NoTestsRemainException { if (filter == null) { throw new NullPointerException("filter must not be null"); } super.filter(new DataProviderFilter(filter)); }
if (shouldRun(each)) { return true;
@Override public boolean shouldRun(Description description) { Matcher filterDescriptionMatcher = DESCRIPTION_PATTERN.matcher(filter.describe()); if (!filterDescriptionMatcher.find()) { return filter.shouldRun(description); } String methodName = filterDescriptionMatcher.group(GROUP_METHOD_NAME); String className = filterDescriptionMatcher.group(GROUP_CLASS); if (description.isTest()) { return shouldRunTest(description, filterDescriptionMatcher, methodName, className); } // explicitly check if any children should to run for (Description each : description.getChildren()) { if (shouldRun(each)) { return true; } } return false; }
@Test public void testDescribeShouldReturnFilterDescripe() { // Given: doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe(); // When: String result = underTest.describe(); // Then: assertThat(result).isEqualTo("Method testMain[1: ](com.tngtech.Clazz)"); }
@Override public boolean shouldRun(Description description) { String filterDescription = filter.describe(); Matcher filterDescriptionMatcher = DESCRIPTION_PATTERN.matcher(filterDescription); if (filterDescription.contains(" OR ") || !filterDescriptionMatcher.find()) { return filter.shouldRun(description); } String methodName = filterDescriptionMatcher.group(GROUP_METHOD_NAME); String className = filterDescriptionMatcher.group(GROUP_CLASS); if (description.isTest()) { return shouldRunTest(description, filterDescriptionMatcher, methodName, className); } // explicitly check if any children should to run for (Description each : description.getChildren()) { if (shouldRun(each)) { return true; } } return false; }
@Test public void testShouldRunShouldReturnTrueWhenDescriptionHaveOnlyMethodNameAndEqualsExactly() { // Given: doReturn("Method testMain(com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testMain(com.tngtech.Clazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isTrue(); }
@Override public boolean shouldRun(Description description) { String filterDescription = filter.describe(); Matcher filterDescriptionMatcher = DESCRIPTION_PATTERN.matcher(filterDescription); if (filterDescription.contains(" OR ") || !filterDescriptionMatcher.find()) { return filter.shouldRun(description); } String methodName = filterDescriptionMatcher.group(GROUP_METHOD_NAME); String className = filterDescriptionMatcher.group(GROUP_CLASS); if (description.isTest()) { return shouldRunTest(description, filterDescriptionMatcher, methodName, className); } // explicitly check if any children should to run for (Description each : description.getChildren()) { if (shouldRun(each)) { return true; } } return false; }
/** * {@inheritDoc} * <p> * If possible the given {@code filter} is wrapped by {@link DataProviderFilter} to enable filtering of tests using * a dataprovider. * * @param filter the {@link Filter} to be wrapped or apply, respectively */ @Override public void filter(Filter filter) throws NoTestsRemainException { checkNotNull(filter, "filter must not be null"); super.filter(new DataProviderFilter(filter)); }
@Test public void testShouldRunShouldReturnTrueWhenDescriptionHavingSomeRandomCodeBetweenMethodNameAndClass() { // Given: doReturn("Method testMain(com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testMain 298zBZ=)& %(/$(=93A SD4)i(qzt)487 5z2 59isf&(com.tngtech.Clazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isTrue(); }
/** * {@inheritDoc} * <p> * If possible the given {@code filter} is wrapped by {@link DataProviderFilter} to enable filtering of tests using * a dataprovider. * * @param filter the {@link Filter} to be wrapped or apply, respectively */ @Override public void filter(Filter filter) throws NoTestsRemainException { checkNotNull(filter, "filter must not be null"); super.filter(new DataProviderFilter(filter)); }
@Test public void testShouldRunShouldReturnTrueWhenDescriptionHaveAdditionalMethodIdxAndMethodParamsAreDifferentButIdxIsEqual() { // Given: doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testMain[1: test](com.tngtech.Clazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isTrue(); }
/** * {@inheritDoc} * <p> * If possible the given {@code filter} is wrapped by {@link DataProviderFilter} to enable filtering of tests using * a dataprovider. * * @param filter the {@link Filter} to be wrapped or apply, respectively */ @Override public void filter(Filter filter) throws NoTestsRemainException { checkNotNull(filter, "filter must not be null"); super.filter(new DataProviderFilter(filter)); }
@Test public void testShouldRunShouldReturnFalseWhenDescriptionDoesNotHaveExpectedMethodIdx() { // Given: doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testMain[2: ](com.tngtech.Clazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isFalse(); }
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") @Test(expected = NullPointerException.class) public void testDataProviderFilterShouldThrowNullPointerExceptionWhenFilterIsNull() { // Given: // When: @SuppressWarnings("unused") DataProviderFilter result = new DataProviderFilter(null); // Then: expect exception }
@Test public void testShouldRunShouldReturnFalseWhenDescriptionHavingSomeRandomCodeBetweenMethodNameAndClassButMethodNameIsNotTheSame() { // Given: doReturn("Method testMain(com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testOther: test, 4(com.tngtech.Clazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isFalse(); }
@Test public void testShouldRunShouldReturnFalseWhenDescriptionHavingSomeRandomCodeBetweenMethodNameAndClassButClassIsNotTheSame() { // Given: doReturn("Method testMain(com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testMain 8zBZ=(qzt)487(com.tngtech.OtherClazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isFalse(); }
@Test public void testShouldRunShouldReturnTrueWhenDescriptionHaveAddtionalMethodIdxAndEqualsExcatly() { // Given: doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testMain[1: ](com.tngtech.Clazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isTrue(); }
@Test public void testShouldRunShouldReturnFalseWhenDescriptionDoesNotHaveExpectedMethodName() { // Given: doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testOther[1: ](com.tngtech.Clazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isFalse(); }
@Test public void testShouldRunShouldReturnFalseWhenDescriptionDoesNotHaveExpectedPackageName() { // Given: doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testMain[1: ](com.tngtech.other.Clazz)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isFalse(); }
@Test public void testShouldRunShouldReturnFalseWhenDescriptionDoesNotHaveExpectedClassName() { // Given: doReturn("Method testMain[1: ](com.tngtech.Clazz)").when(filter).describe(); Description description = setupDescription(true, "testMain[1: ](com.tngtech.ClazzOther)"); // When: boolean result = underTest.shouldRun(description); // Then: assertThat(result).isFalse(); }