Skip to content

Commit

Permalink
Convert nested test classes to top-level classes.
Browse files Browse the repository at this point in the history
This improves the chances that they're found by test runners.

In this case, I've left some _abstract_ test classes as nested classes. Maybe I should just make them top-level classes, too. But test runners don't look for them, so it probably doesn't matter.

PiperOrigin-RevId: 435166129
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Mar 16, 2022
1 parent a183b59 commit aa45235
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.common.collect;

import com.google.common.base.Predicate;
import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredCollectionTest;
import java.util.Collection;

public final class Collections2FilterArrayListTest
extends AbstractFilteredCollectionTest<Collection<Integer>> {
@Override
Collection<Integer> createUnfiltered(Iterable<Integer> contents) {
return Lists.newArrayList(contents);
}

@Override
Collection<Integer> filter(Collection<Integer> elements, Predicate<? super Integer> predicate) {
return Collections2.filter(elements, predicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import junit.framework.TestCase;

/**
* Tests for filtered collection views.
* Class that contains nested abstract tests for filtered collection views, along with their
* implementation helpers.
*
* @author Louis Wasserman
*/
public class FilteredCollectionsTest extends TestCase {
/*
* TODO(cpovirk): Should all the tests for filtered collections run under GWT, too? Currently, they
* don't.
*/
public final class FilteredCollectionsTestUtil {
private static final Predicate<Integer> EVEN =
new Predicate<Integer>() {
@Override
Expand Down Expand Up @@ -374,79 +378,5 @@ public void testNavigation() {
}
}

// implementation tests

public static final class IterablesFilterArrayListTest
extends AbstractFilteredIterableTest<Iterable<Integer>> {
@Override
Iterable<Integer> createUnfiltered(Iterable<Integer> contents) {
return Lists.newArrayList(contents);
}

@Override
Iterable<Integer> filter(Iterable<Integer> elements, Predicate<? super Integer> predicate) {
return Iterables.filter(elements, predicate);
}
}

public static final class Collections2FilterArrayListTest
extends AbstractFilteredCollectionTest<Collection<Integer>> {
@Override
Collection<Integer> createUnfiltered(Iterable<Integer> contents) {
return Lists.newArrayList(contents);
}

@Override
Collection<Integer> filter(Collection<Integer> elements, Predicate<? super Integer> predicate) {
return Collections2.filter(elements, predicate);
}
}

public static final class SetsFilterHashSetTest extends AbstractFilteredSetTest<Set<Integer>> {
@Override
Set<Integer> createUnfiltered(Iterable<Integer> contents) {
return Sets.newHashSet(contents);
}

@Override
Set<Integer> filter(Set<Integer> elements, Predicate<? super Integer> predicate) {
return Sets.filter(elements, predicate);
}
}

public static final class SetsFilterSortedSetTest
extends AbstractFilteredSortedSetTest<SortedSet<Integer>> {
@Override
SortedSet<Integer> createUnfiltered(Iterable<Integer> contents) {
final TreeSet<Integer> result = Sets.newTreeSet(contents);
// we have to make the result not Navigable
return new ForwardingSortedSet<Integer>() {
@Override
protected SortedSet<Integer> delegate() {
return result;
}
};
}

@Override
SortedSet<Integer> filter(SortedSet<Integer> elements, Predicate<? super Integer> predicate) {
return Sets.filter(elements, predicate);
}
}

public static final class SetsFilterNavigableSetTest extends AbstractFilteredNavigableSetTest {
@Override
NavigableSet<Integer> createUnfiltered(Iterable<Integer> contents) {
return Sets.newTreeSet(contents);
}

@Override
NavigableSet<Integer> filter(
NavigableSet<Integer> elements, Predicate<? super Integer> predicate) {
return Sets.filter(elements, predicate);
}
}

/** No-op test so that the class has at least one method, making Maven's test runner happy. */
public void testNoop() {}
private FilteredCollectionsTestUtil() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.common.collect;

import com.google.common.base.Predicate;
import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredIterableTest;

public final class IterablesFilterArrayListTest
extends AbstractFilteredIterableTest<Iterable<Integer>> {
@Override
Iterable<Integer> createUnfiltered(Iterable<Integer> contents) {
return Lists.newArrayList(contents);
}

@Override
Iterable<Integer> filter(Iterable<Integer> elements, Predicate<? super Integer> predicate) {
return Iterables.filter(elements, predicate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.common.collect;

import com.google.common.base.Predicate;
import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredSetTest;
import java.util.Set;

public final class SetsFilterHashSetTest extends AbstractFilteredSetTest<Set<Integer>> {
@Override
Set<Integer> createUnfiltered(Iterable<Integer> contents) {
return Sets.newHashSet(contents);
}

@Override
Set<Integer> filter(Set<Integer> elements, Predicate<? super Integer> predicate) {
return Sets.filter(elements, predicate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.common.collect;

import com.google.common.base.Predicate;
import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredNavigableSetTest;
import java.util.NavigableSet;

public final class SetsFilterNavigableSetTest extends AbstractFilteredNavigableSetTest {
@Override
NavigableSet<Integer> createUnfiltered(Iterable<Integer> contents) {
return Sets.newTreeSet(contents);
}

@Override
NavigableSet<Integer> filter(
NavigableSet<Integer> elements, Predicate<? super Integer> predicate) {
return Sets.filter(elements, predicate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.common.collect;

import com.google.common.base.Predicate;
import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredSortedSetTest;
import java.util.SortedSet;
import java.util.TreeSet;

public final class SetsFilterSortedSetTest
extends AbstractFilteredSortedSetTest<SortedSet<Integer>> {
@Override
SortedSet<Integer> createUnfiltered(Iterable<Integer> contents) {
final TreeSet<Integer> result = Sets.newTreeSet(contents);
// we have to make the result not Navigable
return new ForwardingSortedSet<Integer>() {
@Override
protected SortedSet<Integer> delegate() {
return result;
}
};
}

@Override
SortedSet<Integer> filter(SortedSet<Integer> elements, Predicate<? super Integer> predicate) {
return Sets.filter(elements, predicate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.common.collect;

import com.google.common.base.Predicate;
import com.google.common.collect.FilteredCollectionsTestUtil.AbstractFilteredCollectionTest;
import java.util.Collection;

public final class Collections2FilterArrayListTest
extends AbstractFilteredCollectionTest<Collection<Integer>> {
@Override
Collection<Integer> createUnfiltered(Iterable<Integer> contents) {
return Lists.newArrayList(contents);
}

@Override
Collection<Integer> filter(Collection<Integer> elements, Predicate<? super Integer> predicate) {
return Collections2.filter(elements, predicate);
}
}
Loading

0 comments on commit aa45235

Please sign in to comment.