[SSHD-732] Fixed BuiltinClientIdentitiesWatcherTest in view

Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/6ecd949a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/6ecd949a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/6ecd949a

Branch: refs/heads/master
Commit: 6ecd949a9d855feee2f1d2231b7c002d1df7f4cb
Parents: 3148667
Author: Lyor Goldstein <lyor.goldst...@gmail.com>
Authored: Tue Mar 21 06:49:16 2017 +0200
Committer: Guillaume Nodet <gno...@apache.org>
Committed: Tue Mar 28 11:59:15 2017 +0200

----------------------------------------------------------------------
 .../client/config/keys/ClientIdentitiesWatcher.java     | 12 +++++++++---
 .../config/keys/BuiltinClientIdentitiesWatcherTest.java |  7 ++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6ecd949a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
 
b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
index 6c2bb0b..094766f 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/client/config/keys/ClientIdentitiesWatcher.java
@@ -76,7 +76,7 @@ public class ClientIdentitiesWatcher extends 
AbstractKeyPairProvider implements
         return loadKeys(null);
     }
 
-    protected Iterable<KeyPair> loadKeys(Predicate<KeyPair> filter) {
+    protected Iterable<KeyPair> loadKeys(Predicate<? super KeyPair> filter) {
         return () -> {
             Stream<KeyPair> stream = safeMap(GenericUtils.stream(providers), 
this::doGetKeyPair);
             if (filter != null) {
@@ -89,14 +89,20 @@ public class ClientIdentitiesWatcher extends 
AbstractKeyPairProvider implements
     /**
      * Performs a mapping operation on the stream, discarding any null values
      * returned by the mapper.
+     *
+     * @param <U> Original type
+     * @param <V> Mapped type
+     * @param stream Original values stream
+     * @param mapper Mapper to target type
+     * @return Mapped stream
      */
-    private <U, V> Stream<V> safeMap(Stream<U> stream, Function<U, V> mapper) {
+    protected <U, V> Stream<V> safeMap(Stream<U> stream, Function<? super U, ? 
extends V> mapper) {
         return stream.map(u -> Optional.ofNullable(mapper.apply(u)))
                 .filter(Optional::isPresent)
                 .map(Optional::get);
     }
 
-    private KeyPair doGetKeyPair(ClientIdentityProvider p) {
+    protected KeyPair doGetKeyPair(ClientIdentityProvider p) {
         try {
             KeyPair kp = p.getClientIdentity();
             if (kp == null) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/6ecd949a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
 
b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
index 9599684..70cc197 100644
--- 
a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
+++ 
b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
@@ -28,6 +28,7 @@ import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 import java.security.GeneralSecurityException;
 import java.security.KeyPair;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.EnumMap;
@@ -141,7 +142,11 @@ public class BuiltinClientIdentitiesWatcherTest extends 
BaseTestSupport {
     }
 
     private static void testMultipleFilesWatch(String phase, 
KeyIdentityProvider watcher, Collection<? extends KeyPair> expected) {
-        Collection<? extends KeyPair> actual = (Collection<? extends KeyPair>) 
watcher.loadKeys();
+        Iterable<KeyPair> keys = watcher.loadKeys();
+        Collection<KeyPair> actual = new ArrayList<>();
+        for (KeyPair kp : keys) {
+            actual.add(kp);
+        }
         assertEquals(phase + ": mismatched sizes", 
GenericUtils.size(expected), GenericUtils.size(actual));
 
         if (!GenericUtils.isEmpty(expected)) {

Reply via email to