cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jburwell <>
Subject [GitHub] cloudstack pull request #1884: CLOUDSTACK-9699: Add global setting for enabl...
Date Fri, 06 Jan 2017 22:48:27 GMT
Github user jburwell commented on a diff in the pull request:
    --- Diff: api/test/org/apache/cloudstack/api/command/test/
    @@ -0,0 +1,80 @@
    +// 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
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +package org.apache.cloudstack.api.command.test;
    +import junit.framework.Assert;
    +import junit.framework.TestCase;
    +import org.apache.cloudstack.api.ResponseGenerator;
    +import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
    +import org.apache.cloudstack.api.command.user.config.ListCapabilitiesCmd;
    +import org.apache.cloudstack.api.response.CapabilitiesResponse;
    +import org.apache.cloudstack.api.response.ConfigurationResponse;
    +import org.apache.cloudstack.api.response.ListResponse;
    +import org.apache.cloudstack.config.Configuration;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.mockito.Mockito;
    +import java.util.ArrayList;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +public class ListCapabilitiesCmdTest extends TestCase {
    +    private ListCapabilitiesCmd listCapabilitiesCmd;
    +    private ManagementService mgr;
    +    private ResponseGenerator responseGenerator;
    +    @Override
    +    @Before
    +    public void setUp() {
    +        responseGenerator = Mockito.mock(ResponseGenerator.class);
    +        mgr = Mockito.mock(ManagementService.class);
    +        listCapabilitiesCmd = new ListCapabilitiesCmd();
    +    }
    +    @Test
    +    public void testCreateSuccess() {
    +        listCapabilitiesCmd._mgr = mgr;
    +        listCapabilitiesCmd._responseGenerator = responseGenerator;
    +        Map<String, Object> result = new HashMap<String, Object>();
    +        try {
    +            Mockito.when(mgr.listCapabilities(listCapabilitiesCmd)).thenReturn(result);
    +        } catch (Exception e) {
    +  "Received exception when success expected " + e.getMessage());
    +        }
    --- End diff --
    Why not perform lines 58-67 in in `setUp`?  Not only would this approach focus this method
on the test operations, but remove the need for unnecessary class-level attributes.
    Also, catching exceptions is not required because JUnit will automatically fail when exceptions
are thrown.  If there are checked exceptions, add them to the `throws` of the test method
to keep test methods as succinct as possible.

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