cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rafaelweingartner <>
Subject [GitHub] cloudstack pull request: Cwe 190
Date Wed, 11 Nov 2015 11:55:56 GMT
Github user rafaelweingartner commented on a diff in the pull request:
    --- Diff: utils/src/main/java/com/cloud/utils/net/ ---
    @@ -775,11 +776,19 @@ public static String getSubNet(final String ip, final String netmask)
         public static String getCidrSubNet(final String ip, final long cidrSize) {
    -        final long numericNetmask = 0xffffffff >> MAX_CIDR - cidrSize <<
MAX_CIDR - cidrSize;
    +        final long numericNetmask = netMaskFromCidr(cidrSize);
             final String netmask = NetUtils.long2Ip(numericNetmask);
             return getSubNet(ip, netmask);
    +    /**
    +     * @param cidrSize
    +     * @return
    +     */
    +    static long netMaskFromCidr(final long cidrSize) {
    +        return ((long)0xffffffff) >> MAX_CIDR - cidrSize << MAX_CIDR - cidrSize;
    +    }
    --- End diff --
    I think that it is fine letting the method with default modifier. 
    The point of a test case is that we can/should write tests for a single method. Therefore,
if we want to test the method “getCidrSizeFromString”, we should write a test case for
that specific method, and not for another one that uses it. 
    After we make sure that a method works fine, when we test another method (let’s say
“cidrToLong”)  that uses the first one already tested, we can use EasyMock/Mockito or
another test suite to mock the method that we know works, this way we facilitate the writing
of test cases. 

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

View raw message