refactor: replace anonymous types with lambdas

This commit is contained in:
broDom
2017-07-03 17:07:07 +02:00
parent db2d82b9ec
commit 397904adde
29 changed files with 285 additions and 640 deletions

View File

@@ -34,7 +34,6 @@ package sonia.scm.cache;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Function;
import com.google.common.collect.Iterators;
import com.google.common.io.ByteSource;
import com.google.common.io.Files;
@@ -196,15 +195,7 @@ public class CacheConfigurationTestLoader implements CacheConfigurationLoader
else
{
urlIterator = Iterators.transform(moduleConfigurations,
new Function<String, URL>()
{
@Override
public URL apply(String resource)
{
return getResource(resource);
}
});
this::getResource);
}
return urlIterator;

View File

@@ -35,18 +35,14 @@ package sonia.scm.cache;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Predicate;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import sonia.scm.util.IOUtil;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.*;
import org.junit.Assume;
/**
*
@@ -166,14 +162,7 @@ public abstract class CacheTestBase
cache.put("a-1", "test123");
cache.put("a-2", "test123");
Iterable<String> previous = cache.removeAll(new Predicate<String>()
{
@Override
public boolean apply(String item)
{
return item.startsWith("test");
}
});
Iterable<String> previous = cache.removeAll(item -> item != null && item.startsWith("test"));
assertThat(previous, containsInAnyOrder("test123", "test456"));
assertNull(cache.get("test-1"));

View File

@@ -34,31 +34,27 @@ package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Charsets;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Set;
import java.util.stream.StreamSupport;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
/**
*
@@ -370,15 +366,10 @@ public class PluginProcessorTest
private PluginWrapper findPlugin(Iterable<PluginWrapper> plugin,
final String id)
{
return Iterables.find(plugin, new Predicate<PluginWrapper>()
{
@Override
public boolean apply(PluginWrapper input)
{
return id.equals(input.getId());
}
});
return StreamSupport.stream(plugin.spliterator(), false)
.filter(input -> id.equals(input.getId()))
.findFirst()
.orElse(null);
}
//~--- inner classes --------------------------------------------------------

View File

@@ -33,26 +33,22 @@ package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
@@ -265,15 +261,7 @@ public class PluginTreeTest
*/
private List<String> unwrapIds(List<PluginNode> nodes)
{
return Lists.transform(nodes, new Function<PluginNode, String>()
{
@Override
public String apply(PluginNode input)
{
return input.getId();
}
});
return Lists.transform(nodes, PluginNode::getId);
}
//~--- fields ---------------------------------------------------------------

View File

@@ -35,22 +35,15 @@ package sonia.scm.security;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.Sets;
import org.junit.Test;
import java.util.Set;
import java.util.concurrent.*;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
*
* @author Sebastian Sdorra
@@ -96,28 +89,22 @@ public class DefaultKeyGeneratorTest
for (int i = 0; i < 10; i++)
{
Future<Set<String>> future = executor.submit(new Callable<Set<String>>()
{
Future<Set<String>> future = executor.submit(() -> {
Set<String> keys = Sets.newHashSet();
@Override
public Set<String> call()
for (int i1 = 0; i1 < 1000; i1++)
{
Set<String> keys = Sets.newHashSet();
String key = generator.createKey();
for (int i = 0; i < 1000; i++)
if (keys.contains(key))
{
String key = generator.createKey();
if (keys.contains(key))
{
fail("dublicate key");
}
keys.add(key);
fail("dublicate key");
}
return keys;
keys.add(key);
}
return keys;
});
futureSet.add(future);

View File

@@ -34,27 +34,23 @@ package sonia.scm.security;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Predicate;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.SimpleAccountRealm;
import org.junit.Before;
import org.junit.Test;
import sonia.scm.AbstractTestBase;
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
import sonia.scm.util.MockUtil;
import static org.hamcrest.Matchers.*;
import java.util.List;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.util.List;
/**
*
* @author Sebastian Sdorra
@@ -184,15 +180,7 @@ public class DefaultSecuritySystemTest extends AbstractTestBase
createPermission("hitchhiker", true, "repository:*:READ");
List<StoredAssignedPermission> filtered =
securitySystem.getPermissions(new Predicate<AssignedPermission>()
{
@Override
public boolean apply(AssignedPermission input)
{
return !input.isGroupPermission();
}
});
securitySystem.getPermissions(input -> !(input != null && input.isGroupPermission()));
assertEquals(2, filtered.size());
assertThat(filtered, containsInAnyOrder(trillian, dent));

View File

@@ -89,15 +89,8 @@ public class MustacheTemplateTest extends TemplateTestBase
@Override
protected void prepareEnv(Map<String, Object> env)
{
env.put("test", new Function<String, String>()
{
@Override
public String apply(String input)
{
throw new UnsupportedOperationException("Not supported yet.");
}
env.put("test", (Function<String, String>) input -> {
throw new UnsupportedOperationException("Not supported yet.");
});
}