[ 
https://issues.apache.org/jira/browse/VALIDATOR-336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14208450#comment-14208450
 ] 

Peter Lindberg commented on VALIDATOR-336:
------------------------------------------

Benedikt:
There is some weird behavior with CUSIPCheckDigitTest and/or 
AbstractCheckDigitTest:  Elements in CUSIPCheckDigitTest.invalid are passed to 
both calculate and isValid, in separate tests.  

If the string contains a non-alphanumeric character, BOTH methods will throw 
the "invalid character" exception, which is actually coming from the toInt 
method. 

However, if the string represents a code with an invalid checkdigit (e.g. 
{{DUS0421CW}}), only isValid throws an exception, which is expected, because 
calculate only determines what the checkdigit should be -- it does not 
determine correctness.

Because of this behavior, {{DUS0421CW}} will pass testIsValidFalse, but it will 
generate a failure for testCalculateInvalid.

I believe this is a bug, and I'll submit an issue for it when I get a chance.

A work-around would be to put the whole method testCheckDigitIsLetter from the 
CusipValidatorTest_v2.java into CUSIPCheckDigitTest, but that is a little 
messy, because it breaks the pattern of all the tests being in 
AbstractCheckDigitTest.  Thanks.

Regards,
Peter

> CUSIPCheckDigit Thinks Invalid CUSIP is Valid
> ---------------------------------------------
>
>                 Key: VALIDATOR-336
>                 URL: https://issues.apache.org/jira/browse/VALIDATOR-336
>             Project: Commons Validator
>          Issue Type: Bug
>            Reporter: Josh Meyer
>         Attachments: CUSIPCheckDigit.java.patch, CusipValidatorTest.java, 
> CusipValidatorTest_v2.java, VALIDATOR-336.patch
>
>
> When testing if a specific CUSIP is valid using 
> org.apache.commons.validator.routines.checkdigit.CUSIPCheckDigit.CUSIP_CHECK_DIGIT.isValid,
>  a call to this returns true when it should return false. A specific example 
> is with the following invalid CUSIP: DUS0421CW.
> What seems to be happening is when toInt is called on W it turns it to an int 
> value and then sends it to weightedValue. This is fine for the first 8 
> characters of a CUSIP, but not the check digit. The expected result should be 
> to return false because the check digit is a letter (on a CUSIP a check digit 
> must be 0-9). 
> With the current implementation, I believe each CUSIP can have up to 4 valid 
> check digits.
> A test is attached.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to