mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] cleanup tests code: lambdify, remove unused imports, use method references and diamonds
This commit is contained in:
@@ -17,11 +17,9 @@ package com.intellij.vcs.log;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.vcs.log.impl.HashImpl;
|
||||
@@ -161,7 +159,8 @@ public abstract class VcsLogUserFilterTest {
|
||||
private void checkTurkishAndEnglishLocales(@NotNull VcsUser user,
|
||||
@NotNull Collection<VcsUser> synonymUsers,
|
||||
@NotNull MultiMap<VcsUser, String> commits,
|
||||
@NotNull List<VcsCommitMetadata> metadata, @NotNull StringBuilder builder) throws VcsException {
|
||||
@NotNull List<VcsCommitMetadata> metadata, @NotNull StringBuilder builder)
|
||||
throws VcsException {
|
||||
Set<String> expectedCommits = ContainerUtil.newHashSet(commits.get(user));
|
||||
for (VcsUser synonym : synonymUsers) {
|
||||
expectedCommits.addAll(commits.get(synonym));
|
||||
@@ -235,27 +234,12 @@ public abstract class VcsLogUserFilterTest {
|
||||
private List<String> getFilteredHashes(@NotNull VcsLogUserFilter filter) throws VcsException {
|
||||
VcsLogFilterCollectionImpl filters = new VcsLogFilterCollectionImpl(null, filter, null, null, null, null, null);
|
||||
List<TimedVcsCommit> commits = myLogProvider.getCommitsMatchingFilter(myProject.getBaseDir(), filters, -1);
|
||||
return ContainerUtil.map(commits, new Function<TimedVcsCommit, String>() {
|
||||
@Override
|
||||
public String fun(TimedVcsCommit commit) {
|
||||
return commit.getId().asString();
|
||||
}
|
||||
});
|
||||
return ContainerUtil.map(commits, commit -> commit.getId().asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<String> getFilteredHashes(@NotNull VcsLogUserFilter filter, @NotNull List<VcsCommitMetadata> metadata) {
|
||||
return ContainerUtil.map(ContainerUtil.filter(metadata, new Condition<VcsCommitMetadata>() {
|
||||
@Override
|
||||
public boolean value(VcsCommitMetadata t) {
|
||||
return filter.matches(t);
|
||||
}
|
||||
}), new Function<VcsCommitMetadata, String>() {
|
||||
@Override
|
||||
public String fun(VcsCommitMetadata metadata) {
|
||||
return metadata.getId().asString();
|
||||
}
|
||||
});
|
||||
return ContainerUtil.map(ContainerUtil.filter(metadata, filter::matches), metadata1 -> metadata1.getId().asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -65,7 +65,7 @@ class VcsLogJoinerTest {
|
||||
val vcsNewRefs = newRefs!!.map { HashImpl.build(it) }
|
||||
|
||||
val result = VcsLogJoiner<Hash, TimedVcsCommit>().addCommits(vcsFullLog, vcsOldRefs, vcsRecentCommits, vcsNewRefs).getFirst()!!
|
||||
val actual = result.map { it.getId().asString() }.joinToString(separator = "\n")
|
||||
val actual = result.map { it.id.asString() }.joinToString(separator = "\n")
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.Consumer
|
||||
import com.intellij.util.Function
|
||||
import com.intellij.vcs.log.*
|
||||
import com.intellij.vcs.log.data.index.VcsLogIndex
|
||||
import com.intellij.vcs.log.graph.GraphCommit
|
||||
import com.intellij.vcs.log.graph.GraphCommitImpl
|
||||
import com.intellij.vcs.log.graph.PermanentGraph
|
||||
@@ -30,7 +29,6 @@ import com.intellij.vcs.log.graph.VisibleGraph
|
||||
import com.intellij.vcs.log.impl.*
|
||||
import com.intellij.vcs.log.impl.TestVcsLogProvider.BRANCH_TYPE
|
||||
import com.intellij.vcs.log.impl.TestVcsLogProvider.DEFAULT_USER
|
||||
import com.intellij.vcs.log.impl.VcsLogUserFilterImpl
|
||||
import org.junit.Test
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
@@ -99,16 +97,14 @@ class VisiblePackBuilderTest {
|
||||
4() +null
|
||||
}
|
||||
|
||||
val func = object : Function<VcsLogFilterCollection, MutableList<TimedVcsCommit>> {
|
||||
override fun `fun`(param: VcsLogFilterCollection?): MutableList<TimedVcsCommit>? {
|
||||
return ArrayList(listOf(2, 3, 4).map {
|
||||
val id = it
|
||||
val commit = graph.commits.firstOrNull {
|
||||
it.id == id
|
||||
}
|
||||
commit!!.toVcsCommit(graph.hashMap)
|
||||
})
|
||||
}
|
||||
val func = Function<VcsLogFilterCollection, MutableList<TimedVcsCommit>> {
|
||||
ArrayList(listOf(2, 3, 4).map {
|
||||
val id = it
|
||||
val commit = graph.commits.firstOrNull {
|
||||
it.id == id
|
||||
}
|
||||
commit!!.toVcsCommit(graph.hashMap)
|
||||
})
|
||||
}
|
||||
|
||||
graph.providers.entries.iterator().next().value.setFilteredCommitsProvider(func)
|
||||
@@ -138,7 +134,7 @@ class VisiblePackBuilderTest {
|
||||
val dataPack = DataPack.build(commits, mapOf(root to hashMap.refsReversed.keys).mapValues { CompressedRefs(it.value, hashMap) }, providers, hashMap, true)
|
||||
val detailsCache = TopCommitsCache(hashMap)
|
||||
detailsCache.storeDetails(ArrayList(data.entries.mapNotNull {
|
||||
val hash = hashMap.getCommitId(it.key.id)!!.hash
|
||||
val hash = hashMap.getCommitId(it.key.id).hash
|
||||
if (it.value.user == null)
|
||||
null
|
||||
else VcsCommitMetadataImpl(hash, hashMap.getHashes(it.key.parents), 1L, root, it.value.subject,
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.VcsKey;
|
||||
import com.intellij.openapi.vcs.changes.committed.MockAbstractVcs;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -52,7 +53,7 @@ public class TestVcsLogProvider implements VcsLogProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public Color getBackgroundColor() {
|
||||
return Color.white;
|
||||
return JBColor.WHITE;
|
||||
}
|
||||
};
|
||||
private static final String SAMPLE_SUBJECT = "Sample subject";
|
||||
@@ -64,7 +65,7 @@ public class TestVcsLogProvider implements VcsLogProvider {
|
||||
@NotNull private final MockRefManager myRefManager;
|
||||
@NotNull private final ReducibleSemaphore myFullLogSemaphore;
|
||||
@NotNull private final ReducibleSemaphore myRefreshSemaphore;
|
||||
@NotNull private AtomicInteger myReadFirstBlockCounter = new AtomicInteger();
|
||||
@NotNull private final AtomicInteger myReadFirstBlockCounter = new AtomicInteger();
|
||||
|
||||
private final Function<TimedVcsCommit, VcsCommitMetadata> myCommitToMetadataConvertor =
|
||||
new Function<TimedVcsCommit, VcsCommitMetadata>() {
|
||||
@@ -102,7 +103,7 @@ public class TestVcsLogProvider implements VcsLogProvider {
|
||||
assertRoot(root);
|
||||
List<VcsCommitMetadata> metadatas = ContainerUtil.map(myCommits.subList(0, requirements.getCommitCount()),
|
||||
myCommitToMetadataConvertor);
|
||||
return new LogDataImpl(Collections.<VcsRef>emptySet(), metadatas);
|
||||
return new LogDataImpl(Collections.emptySet(), metadatas);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -120,7 +121,7 @@ public class TestVcsLogProvider implements VcsLogProvider {
|
||||
for (TimedVcsCommit commit : myCommits) {
|
||||
commitConsumer.consume(commit);
|
||||
}
|
||||
return new LogDataImpl(myRefs, Collections.<VcsUser>emptySet());
|
||||
return new LogDataImpl(myRefs, Collections.emptySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -234,12 +235,7 @@ public class TestVcsLogProvider implements VcsLogProvider {
|
||||
|
||||
private static class MockRefManager implements VcsLogRefManager {
|
||||
|
||||
public static final Comparator<VcsRef> FAKE_COMPARATOR = new Comparator<VcsRef>() {
|
||||
@Override
|
||||
public int compare(VcsRef o1, VcsRef o2) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
public static final Comparator<VcsRef> FAKE_COMPARATOR = (o1, o2) -> 0;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -250,12 +246,7 @@ public class TestVcsLogProvider implements VcsLogProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<RefGroup> groupForBranchFilter(@NotNull Collection<VcsRef> refs) {
|
||||
return ContainerUtil.map(refs, new Function<VcsRef, RefGroup>() {
|
||||
@Override
|
||||
public RefGroup fun(VcsRef ref) {
|
||||
return new SingletonRefGroup(ref);
|
||||
}
|
||||
});
|
||||
return ContainerUtil.map(refs, SingletonRefGroup::new);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -271,7 +262,7 @@ public class TestVcsLogProvider implements VcsLogProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public VcsRefType deserialize(@NotNull DataInput in) throws IOException {
|
||||
return null;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user