creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r1548271 - in /creadur/rat/branches/gsoc/apache-rat-core/src: main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java test/java/org/apache/rat/document/impl/guesser/NoteGuesserTest.java
Date Thu, 05 Dec 2013 20:24:22 GMT
Author: rdonkin
Date: Thu Dec  5 20:24:21 2013
New Revision: 1548271

URL: http://svn.apache.org/r1548271
Log:
Prepare to factor into an object

Modified:
    creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java
    creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/document/impl/guesser/NoteGuesserTest.java

Modified: creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java
URL: http://svn.apache.org/viewvc/creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java?rev=1548271&r1=1548270&r2=1548271&view=diff
==============================================================================
--- creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java
(original)
+++ creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/document/impl/guesser/NoteGuesser.java
Thu Dec  5 20:24:21 2013
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the    *
  * specific language governing permissions and limitations      *
  * under the License.                                           *
- */ 
+ */
 package org.apache.rat.document.impl.guesser;
 
 import java.util.Arrays;
@@ -25,51 +25,40 @@ import org.apache.rat.api.Document;
 
 public class NoteGuesser {
 
+    private static final String[] NOTE_FILE_NAMES = { "NOTICE", "LICENSE",
+            "LICENSE.TXT", "NOTICE.TXT", "INSTALL", "INSTALL.TXT", "README",
+            "README.TXT", "NEWS", "NEWS.TXT", "AUTHOR", "AUTHOR.TXT",
+            "AUTHORS", "AUTHORS.txt", "CHANGELOG", "CHANGELOG.TXT",
+            "DISCLAIMER", "DISCLAIMER.TXT", "KEYS", "KEYS.TXT",
+            "RELEASE-NOTES", "RELEASE-NOTES.TXT", "RELEASE_NOTES",
+            "RELEASE_NOTES.TXT", "UPGRADE", "UPGRADE.TXT", "STATUS",
+            "STATUS.TXT", "THIRD_PARTY_NOTICES", "THIRD_PARTY_NOTICES.TXT",
+            "COPYRIGHT", "COPYRIGHT.TXT", "BUILDING", "BUILDING.TXT", "BUILD",
+            "BUILT.TXT", };
+    private static final String[] NOTE_FILE_EXTENSIONS = { "LICENSE",
+            "LICENSE.TXT", "NOTICE", "NOTICE.TXT", };
 
-    public static final String[] NOTE_FILE_NAMES = {
-        "NOTICE", "LICENSE",
-        "LICENSE.TXT", "NOTICE.TXT",
-        "INSTALL", "INSTALL.TXT",
-        "README", "README.TXT", 
-        "NEWS", "NEWS.TXT",
-        "AUTHOR", "AUTHOR.TXT",
-        "AUTHORS", "AUTHORS.txt",
-        "CHANGELOG", "CHANGELOG.TXT",
-        "DISCLAIMER", "DISCLAIMER.TXT",
-        "KEYS", "KEYS.TXT",
-        "RELEASE-NOTES", "RELEASE-NOTES.TXT",
-        "RELEASE_NOTES", "RELEASE_NOTES.TXT",
-        "UPGRADE", "UPGRADE.TXT",
-        "STATUS", "STATUS.TXT",
-        "THIRD_PARTY_NOTICES", "THIRD_PARTY_NOTICES.TXT",
-        "COPYRIGHT", "COPYRIGHT.TXT",
-        "BUILDING", "BUILDING.TXT",
-        "BUILD", "BUILT.TXT",
-    };
-    public static final String[] NOTE_FILE_EXTENSIONS = {
-        "LICENSE", "LICENSE.TXT",
-        "NOTICE", "NOTICE.TXT",
-    };
-    
     /**
      * Is a file by that name a note file?
      */
-    public static final boolean isNote(final String name) {
-        if (name == null) {return false;}
-    
-        List<String> l = Arrays.asList(NoteGuesser.NOTE_FILE_NAMES);
-        String normalisedName = GuessUtils.normalise(name);
-        
+    private static final boolean isNote(final String name) {
+        if (name == null) {
+            return false;
+        }
+
+        final List<String> l = Arrays.asList(NoteGuesser.NOTE_FILE_NAMES);
+        final String normalisedName = GuessUtils.normalise(name);
+
         if (l.contains(name) || l.contains(normalisedName)) {
             return true;
         }
 
-        for (int i = 0; i < NoteGuesser.NOTE_FILE_EXTENSIONS.length; i++) {
-            if (normalisedName.endsWith("." + NoteGuesser.NOTE_FILE_EXTENSIONS[i])) {
+        for (final String element : NoteGuesser.NOTE_FILE_EXTENSIONS) {
+            if (normalisedName.endsWith("." + element)) {
                 return true;
             }
         }
-        
+
         return false;
     }
 

Modified: creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/document/impl/guesser/NoteGuesserTest.java
URL: http://svn.apache.org/viewvc/creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/document/impl/guesser/NoteGuesserTest.java?rev=1548271&r1=1548270&r2=1548271&view=diff
==============================================================================
--- creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/document/impl/guesser/NoteGuesserTest.java
(original)
+++ creadur/rat/branches/gsoc/apache-rat-core/src/test/java/org/apache/rat/document/impl/guesser/NoteGuesserTest.java
Thu Dec  5 20:24:21 2013
@@ -15,49 +15,39 @@
  * KIND, either express or implied.  See the License for the    *
  * specific language governing permissions and limitations      *
  * under the License.                                           *
- */ 
+ */
 package org.apache.rat.document.impl.guesser;
 
+import static org.junit.Assert.assertTrue;
+
 import org.apache.rat.document.MockDocument;
 import org.junit.Test;
 
-import static org.junit.Assert.assertTrue;
-
 public class NoteGuesserTest {
 
     @Test
     public void testMatches() {
-        assertTrue(NoteGuesser.isNote(new MockDocument("LICENSE")));
-        assertTrue(NoteGuesser.isNote(new MockDocument("LICENSE.txt")));
-        assertTrue(NoteGuesser.isNote(new MockDocument("NOTICE")));
-        assertTrue(NoteGuesser.isNote(new MockDocument("NOTICE.txt")));
-        assertTrue(NoteGuesser.isNote(new MockDocument("README")));
-        assertTrue(NoteGuesser.isNote(new MockDocument("README.txt")));
+        assertThatGuesserMatches("LICENSE");
+        assertThatGuesserMatches("LICENSE.txt");
+        assertThatGuesserMatches("NOTICE");
+        assertThatGuesserMatches("NOTICE.txt");
+        assertThatGuesserMatches("README");
+        assertThatGuesserMatches("README.txt");
+        assertThatGuesserMatches("src/test/LICENSE");
+        assertThatGuesserMatches("src/test/LICENSE.txt");
+        assertThatGuesserMatches("src/test/NOTICE");
+        assertThatGuesserMatches("src/test/NOTICE.txt");
+        assertThatGuesserMatches("src/test/README");
+        assertThatGuesserMatches("src/test/README.txt");
+        assertThatGuesserMatches("src\\test\\LICENSE");
+        assertThatGuesserMatches("src\\test\\LICENSE.txt");
+        assertThatGuesserMatches("src\\test\\NOTICE");
+        assertThatGuesserMatches("src\\test\\NOTICE.txt");
+        assertThatGuesserMatches("src\\test\\README");
+        assertThatGuesserMatches("src\\test\\README.txt");
     }
 
-    @Test
-    public void isNote() {
-        assertTrue(NoteGuesser.isNote("LICENSE"));
-        assertTrue(NoteGuesser.isNote("LICENSE.txt"));
-        assertTrue(NoteGuesser.isNote("NOTICE"));
-        assertTrue(NoteGuesser.isNote("NOTICE.txt"));
-        assertTrue(NoteGuesser.isNote("README"));
-        assertTrue(NoteGuesser.isNote("README.txt"));
-    }
-    
-    @Test
-    public void isNoteWithPath() {
-        assertTrue(NoteGuesser.isNote("src/test/LICENSE"));
-        assertTrue(NoteGuesser.isNote("src/test/LICENSE.txt"));
-        assertTrue(NoteGuesser.isNote("src/test/NOTICE"));
-        assertTrue(NoteGuesser.isNote("src/test/NOTICE.txt"));
-        assertTrue(NoteGuesser.isNote("src/test/README"));
-        assertTrue(NoteGuesser.isNote("src/test/README.txt"));
-        assertTrue(NoteGuesser.isNote("src\\test\\LICENSE"));
-        assertTrue(NoteGuesser.isNote("src\\test\\LICENSE.txt"));
-        assertTrue(NoteGuesser.isNote("src\\test\\NOTICE"));
-        assertTrue(NoteGuesser.isNote("src\\test\\NOTICE.txt"));
-        assertTrue(NoteGuesser.isNote("src\\test\\README"));
-        assertTrue(NoteGuesser.isNote("src\\test\\README.txt"));
+    private void assertThatGuesserMatches(final String name) {
+        assertTrue(NoteGuesser.isNote(new MockDocument(name)));
     }
 }



Mime
View raw message