harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Beyer <ndbe...@apache.org>
Subject Re: svn commit: r769633 - in /harmony/enhanced/classlib/trunk/modules/lang-management/src: main/java/java/lang/management/MemoryNotificationInfo.java test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/HARMONY6149Test.java
Date Wed, 29 Apr 2009 03:45:34 GMT
If you create a patch for it, I'll do it. Please remove the use of
instance variables though - it's easier to maintain the tests when
they are isolated.

-Nathan

On Tue, Apr 28, 2009 at 10:36 PM, Kevin Zhou <zhoukevin83@gmail.com> wrote:
> Hi Nathan,
> I think the content of HARMONY6149Test should be merged into
> MemoryNotificationInfoTest.java. The HARMONY6149Test name does not follow
> our convention. Would you please help to handle this?
> Thanks!
> yours, Kevin Zhou
>
> On Wed, Apr 29, 2009 at 11:03 AM, <ndbeyer@apache.org> wrote:
>
>> Author: ndbeyer
>> Date: Wed Apr 29 03:03:00 2009
>> New Revision: 769633
>>
>> URL: http://svn.apache.org/viewvc?rev=769633&view=rev
>> Log:
>> Fix MemoryNotificationInfo.from; add test class from attachment on
>> HARMONY-6149 - [classlib][lang-management]
>> java.lang.management.MemoryNotificationInfo.from(CompositeData cd) should
>> throw IllegalArgumentException if cd doesn't represent a
>> MemoryNotificationInfo object
>>
>> Added:
>>
>>  harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/HARMONY6149Test.java
>> Modified:
>>
>>  harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java
>>
>> Modified:
>> harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java
>> URL:
>> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java?rev=769633&r1=769632&r2=769633&view=diff
>>
>> ==============================================================================
>> ---
>> harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java
>> (original)
>> +++
>> harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/java/lang/management/MemoryNotificationInfo.java
>> Wed Apr 29 03:03:00 2009
>> @@ -45,10 +45,23 @@
>>         if (cd == null) {
>>             return null;
>>         }
>> -        String poolName = (String) cd.get("poolName");
>> -        MemoryUsage usage = MemoryUsage.from((CompositeData)
>> cd.get("usage"));
>> -        long count = ((Long) cd.get("count")).longValue();
>> -        return new MemoryNotificationInfo(poolName, usage, count);
>> +
>> +        final Object poolName = cd.get("poolName");
>> +        if (!(poolName instanceof String)) {
>> +            throw new IllegalArgumentException("'poolName' attribute is
>> null or not a String");
>> +        }
>> +
>> +        final Object usageObj = cd.get("usage");
>> +        if (!(usageObj instanceof CompositeData)) {
>> +            throw new IllegalArgumentException("'usage' attribute is null
>> or not a CompositeData");
>> +        }
>> +        final MemoryUsage usage = MemoryUsage.from((CompositeData)
>> usageObj);
>> +
>> +        final Object count = cd.get("count");
>> +        if (!(count instanceof Long)) {
>> +            throw new IllegalArgumentException("'count' attribute is
>> null");
>> +        }
>> +        return new MemoryNotificationInfo((String)poolName, usage,
>> ((Long)count).longValue());
>>     }
>>
>>     private final String poolName;
>>
>> Added:
>> harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/HARMONY6149Test.java
>> URL:
>> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/HARMONY6149Test.java?rev=769633&view=auto
>>
>> ==============================================================================
>> ---
>> harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/HARMONY6149Test.java
>> (added)
>> +++
>> harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/org/apache/harmony/lang/management/tests/java/lang/management/HARMONY6149Test.java
>> Wed Apr 29 03:03:00 2009
>> @@ -0,0 +1,186 @@
>> +/*
>> + * 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.harmony.lang.management.tests.java.lang.management;
>> +
>> +import java.lang.management.MemoryNotificationInfo;
>> +import java.lang.management.MemoryUsage;
>> +
>> +import javax.management.openmbean.CompositeData;
>> +import javax.management.openmbean.CompositeDataSupport;
>> +import javax.management.openmbean.CompositeType;
>> +import javax.management.openmbean.OpenType;
>> +import javax.management.openmbean.SimpleType;
>> +
>> +import junit.framework.TestCase;
>> +
>> +import org.apache.harmony.lang.management.ManagementUtils;
>> +
>> +public class HARMONY6149Test extends TestCase {
>> +
>> +    private static final String CLASS_NAME = MemoryNotificationInfo.class
>> +            .getName();
>> +
>> +    private static final CompositeType memoryUsageCompositeType =
>> ManagementUtils
>> +            .getMemoryUsageCompositeType();
>> +
>> +    private CompositeData memoryCompositeData;
>> +
>> +    protected void setUp() {
>> +        memoryCompositeData = ManagementUtils
>> +                .toMemoryUsageCompositeData(new MemoryUsage(1, 2, 3, 4));
>> +    }
>> +
>> +    protected CompositeType getData(String[] typeNames, OpenType[]
>> typeTypes)
>> +            throws Exception {
>> +        return new CompositeType(CLASS_NAME, CLASS_NAME, typeNames,
>> typeNames,
>> +                typeTypes);
>> +    }
>> +
>> +    public void test_from_scenario1() throws Exception {
>> +        String[] names = { "poolName", "usage", "count" };
>> +        Object[] values = { null, null, null };
>> +        OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
>> +                SimpleType.LONG };
>> +        CompositeType compositeType = getData(names, types);
>> +        CompositeData data = new CompositeDataSupport(compositeType,
>> names,
>> +                values);
>> +        try {
>> +            MemoryNotificationInfo.from(data);
>> +            fail("should throw IllegalArgumentException");
>> +        } catch (IllegalArgumentException e) {
>> +            // Expected
>> +        }
>> +    }
>> +
>> +    public void test_from_scenario5() throws Exception {
>> +        String[] names = { "poolName", "usage", "count" };
>> +        Object[] values = { new Long(1), memoryCompositeData, new Long(42)
>> };
>> +        OpenType[] types = { SimpleType.LONG, memoryUsageCompositeType,
>> +                SimpleType.LONG };
>> +
>> +        CompositeType compositeType = getData(names, types);
>> +        CompositeData data = new CompositeDataSupport(compositeType,
>> names,
>> +                values);
>> +        try {
>> +            MemoryNotificationInfo.from(data);
>> +            fail("should throw IllegalArgumentException");
>> +        } catch (IllegalArgumentException e) {
>> +            // Expected
>> +        }
>> +    }
>> +
>> +    public void test_from_scenario6() throws Exception {
>> +        String[] names = { "poolName", "usage", "count" };
>> +        Object[] values = { "TestPoolName", new Long(1), new Long(42) };
>> +        OpenType[] types = { SimpleType.STRING, SimpleType.LONG,
>> +                SimpleType.LONG };
>> +
>> +        CompositeType compositeType = getData(names, types);
>> +        CompositeData data = new CompositeDataSupport(compositeType,
>> names,
>> +                values);
>> +        try {
>> +            MemoryNotificationInfo.from(data);
>> +            fail("should throw IllegalArgumentException");
>> +        } catch (IllegalArgumentException e) {
>> +            // Expected
>> +        }
>> +    }
>> +
>> +    public void test_from_scenario7() throws Exception {
>> +        String[] names = { "poolName", "usage", "count" };
>> +        Object[] values = { "TestPoolName", memoryCompositeData, "42" };
>> +        OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
>> +                SimpleType.STRING };
>> +
>> +        CompositeType compositeType = getData(names, types);
>> +        CompositeData data = new CompositeDataSupport(compositeType,
>> names,
>> +                values);
>> +        try {
>> +            MemoryNotificationInfo.from(data);
>> +            fail("should throw IllegalArgumentException");
>> +        } catch (IllegalArgumentException e) {
>> +            // Expected
>> +        }
>> +    }
>> +
>> +    public void test_from_scenario8() throws Exception {
>> +        String[] names = { "poolName" };
>> +        Object[] values = { "TestPoolName" };
>> +        OpenType[] types = { SimpleType.STRING };
>> +
>> +        CompositeType compositeType = getData(names, types);
>> +        CompositeData data = new CompositeDataSupport(compositeType,
>> names,
>> +                values);
>> +        try {
>> +            MemoryNotificationInfo.from(data);
>> +            fail("should throw IllegalArgumentException");
>> +        } catch (IllegalArgumentException e) {
>> +            // Expected
>> +        }
>> +    }
>> +
>> +    public void test_from_scenario9() throws Exception {
>> +        String[] names = { "usage" };
>> +        Object[] values = { memoryCompositeData };
>> +        OpenType[] types = { memoryUsageCompositeType };
>> +
>> +        CompositeType compositeType = getData(names, types);
>> +        CompositeData data = new CompositeDataSupport(compositeType,
>> names,
>> +                values);
>> +        try {
>> +            MemoryNotificationInfo.from(data);
>> +            fail("should throw IllegalArgumentException");
>> +        } catch (IllegalArgumentException e) {
>> +            // Expected
>> +        }
>> +    }
>> +
>> +    public void test_from_scenario10() throws Exception {
>> +        String[] names = { "count" };
>> +        Object[] values = { new Long(42) };
>> +        OpenType[] types = { SimpleType.LONG };
>> +
>> +        CompositeType compositeType = getData(names, types);
>> +        CompositeData data = new CompositeDataSupport(compositeType,
>> names,
>> +                values);
>> +        try {
>> +            MemoryNotificationInfo.from(data);
>> +            fail("should throw IllegalArgumentException");
>> +        } catch (IllegalArgumentException e) {
>> +            // Expected
>> +        }
>> +    }
>> +
>> +    public void test_from_scenario11() throws Exception {
>> +        String[] names = { "notPoolName", "usage", "count" };
>> +        Object[] values = { "TestNotPoolName", memoryCompositeData,
>> +                new Long(42) };
>> +        OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
>> +                SimpleType.LONG };
>> +
>> +        CompositeType compositeType = getData(names, types);
>> +        CompositeData data = new CompositeDataSupport(compositeType,
>> names,
>> +                values);
>> +        try {
>> +            MemoryNotificationInfo.from(data);
>> +            fail("should throw IllegalArgumentException");
>> +        } catch (IllegalArgumentException e) {
>> +            // Expected
>> +        }
>> +    }
>> +}
>>
>>
>>
>

Mime
View raw message