Fixed typo error in VersionProperties + added unit test for it
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/0cf8186a Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/0cf8186a Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/0cf8186a Branch: refs/heads/master Commit: 0cf8186ad1ab1a3db7e66a3a4e5a13bbaf9a51fd Parents: 738264f Author: Goldstein Lyor <[email protected]> Authored: Wed Jul 25 09:13:33 2018 +0300 Committer: Goldstein Lyor <[email protected]> Committed: Wed Jul 25 09:13:33 2018 +0300 ---------------------------------------------------------------------- .../sshd/common/config/VersionProperties.java | 25 ++++++----- .../sshd/common/VersionPropertiesTest.java | 45 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0cf8186a/sshd-core/src/main/java/org/apache/sshd/common/config/VersionProperties.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/VersionProperties.java b/sshd-core/src/main/java/org/apache/sshd/common/config/VersionProperties.java index 16beb8e..c7e4271 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/config/VersionProperties.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/config/VersionProperties.java @@ -22,7 +22,7 @@ package org.apache.sshd.common.config; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Collections; -import java.util.Map; +import java.util.NavigableMap; import java.util.Properties; import java.util.TreeMap; @@ -36,19 +36,19 @@ import org.slf4j.LoggerFactory; */ public final class VersionProperties { private static class LazyHolder { - private static final Map<String, String> PROPERTIES = - Collections.unmodifiableMap(loadVersionProperties(LazyHolder.class)); + private static final NavigableMap<String, String> PROPERTIES = + Collections.unmodifiableNavigableMap(loadVersionProperties(LazyHolder.class)); - private static Map<String, String> loadVersionProperties(Class<?> anchor) { + private static NavigableMap<String, String> loadVersionProperties(Class<?> anchor) { return loadVersionProperties(anchor, ThreadUtils.resolveDefaultClassLoader(anchor)); } - private static Map<String, String> loadVersionProperties(Class<?> anchor, ClassLoader loader) { - Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + private static NavigableMap<String, String> loadVersionProperties(Class<?> anchor, ClassLoader loader) { + NavigableMap<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); try { InputStream input = loader.getResourceAsStream("org/apache/sshd/sshd-version.properties"); if (input == null) { - throw new FileNotFoundException("Resource does not exists"); + throw new FileNotFoundException("Version resource does not exist"); } Properties props = new Properties(); @@ -59,9 +59,10 @@ public final class VersionProperties { } for (String key : props.stringPropertyNames()) { - String value = GenericUtils.trimToEmpty(props.getProperty(key)); + String propValue = props.getProperty(key); + String value = GenericUtils.trimToEmpty(propValue); if (GenericUtils.isEmpty(value)) { - continue; // we have no need for empty value + continue; // we have no need for empty values } String prev = result.put(key, value); @@ -83,9 +84,11 @@ public final class VersionProperties { throw new UnsupportedOperationException("No instance"); } + /** + * @return A case <u>insensitive</u> un-modifiable {@link NavigableMap} of the {@code sshd-version.properties} data + */ @SuppressWarnings("synthetic-access") - public static Map<String, String> getVersionProperties() { + public static NavigableMap<String, String> getVersionProperties() { return LazyHolder.PROPERTIES; } - } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/0cf8186a/sshd-core/src/test/java/org/apache/sshd/common/VersionPropertiesTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/VersionPropertiesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/VersionPropertiesTest.java new file mode 100644 index 0000000..06cfffc --- /dev/null +++ b/sshd-core/src/test/java/org/apache/sshd/common/VersionPropertiesTest.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.sshd.common; + +import java.util.Map; + +import org.apache.sshd.common.config.VersionProperties; +import org.apache.sshd.common.util.GenericUtils; +import org.apache.sshd.util.test.BaseTestSupport; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +/** + * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class VersionPropertiesTest extends BaseTestSupport { + public VersionPropertiesTest() { + super(); + } + + @Test + public void testNonEmptyProperties() { + Map<?, ?> props = VersionProperties.getVersionProperties(); + assertTrue(GenericUtils.isNotEmpty(props)); + } +}
