You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2010/10/15 12:03:33 UTC

svn commit: r1022874 - in /commons/proper/net/trunk/src: main/java/org/apache/commons/net/ftp/FTPCommand.java test/java/org/apache/commons/net/ftp/FTPCommandTest.java

Author: sebb
Date: Fri Oct 15 10:03:32 2010
New Revision: 1022874

URL: http://svn.apache.org/viewvc?rev=1022874&view=rev
Log:
Add consistency check for commands array

Added:
    commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java   (with props)
Modified:
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java?rev=1022874&r1=1022873&r2=1022874&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPCommand.java Fri Oct 15 10:03:32 2010
@@ -76,6 +76,8 @@ public final class FTPCommand
     /** @since 2.2 */
     public static final int EPRT = 37;
 
+    // Must agree with final entry above; used to check array size
+    private static final int LAST = EPRT;
     
     public static final int USERNAME = USER;
     public static final int PASSWORD = PASS;
@@ -132,6 +134,17 @@ public final class FTPCommand
                                           "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM", "FEAT", "MFMT",
                                           "EPSV", "EPRT" };
 
+    
+    
+    // default access needed for Unit test
+    static void checkArray(){
+        int expectedLength = LAST+1;
+        if (_commands.length != expectedLength) {
+            throw new RuntimeException("Incorrect _commands array. Should have length "
+                    +expectedLength+" found "+_commands.length);
+        }
+    }
+
     /**
      * Retrieve the FTP protocol command string corresponding to a specified
      * command code.

Added: commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java?rev=1022874&view=auto
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java (added)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java Fri Oct 15 10:03:32 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.commons.net.ftp;
+
+import junit.framework.TestCase;
+
+public class FTPCommandTest extends TestCase {
+
+    public FTPCommandTest(String name) {
+        super(name);
+    }
+
+    public void testArray() {
+        FTPCommand.checkArray();
+    }
+
+}

Propchange: commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision