Skip to content

Commit

Permalink
Display "Other Libraries" label for non-App Engine libraries group (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh authored Dec 10, 2019
1 parent d01a8d0 commit 431c2fc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2019 Google Inc.
*
* Licensed 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 com.google.cloud.tools.eclipse.appengine.newproject;

import static org.junit.Assert.assertEquals;

import com.google.cloud.tools.eclipse.appengine.libraries.ui.CloudLibrariesSelectionPage;
import com.google.cloud.tools.eclipse.test.util.ui.CompositeUtil;
import com.google.cloud.tools.eclipse.test.util.ui.ShellTestResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.junit.Rule;
import org.junit.Test;

public class AppEngineProjectWizardTest {

@Rule public ShellTestResource shellResource = new ShellTestResource();

@Test
public void testLibrariesSelectionPage_appEngineLibrariesGroup() {
verifySupportedLibrariesGroupLabel("appengine", "App Engine Standard Libraries");
}

@Test
public void testLibrariesSelectionPage_nonAppEngineLibrariesGroup() {
verifySupportedLibrariesGroupLabel("some libraries group", "Other Libraries");
}

private void verifySupportedLibrariesGroupLabel(
String supportedLibrariesGroup, String expectedLabel) {
AppEngineWizardPage wizardPage = new AppEngineWizardPage() {
@Override
public void setHelp(Composite container) {}

@Override
protected String getSupportedLibrariesGroup() {
return supportedLibrariesGroup;
}
};

AppEngineProjectWizard wizard = new AppEngineProjectWizard(wizardPage) {
@Override
public CreateAppEngineWtpProject getAppEngineProjectCreationOperation(
AppEngineProjectConfig config, IAdaptable uiInfoAdapter) {
return null;
}
};

CloudLibrariesSelectionPage librariesPage =
(CloudLibrariesSelectionPage) wizard.getPage("cloudPlatformLibrariesPage");
librariesPage.createControl(shellResource.getShell());

Group group = CompositeUtil.findControl((Composite) librariesPage.getControl(), Group.class);
assertEquals(expectedLabel, group.getText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ public abstract class AppEngineProjectWizard extends Wizard implements INewWizar

public AppEngineProjectWizard(AppEngineWizardPage appEngineWizardPage) {
appEnginePage = Preconditions.checkNotNull(appEngineWizardPage);

Map<String, String> groups = new LinkedHashMap<>();
groups.put(appEngineWizardPage.getSupportedLibrariesGroup(),
Messages.getString("appengine-title")); //$NON-NLS-1$

String supportedLibrariesGroup = appEngineWizardPage.getSupportedLibrariesGroup();
if (CloudLibraries.APP_ENGINE_STANDARD_GROUP.equals(supportedLibrariesGroup)) {
groups.put(supportedLibrariesGroup, Messages.getString("appengine-title")); //$NON-NLS-1$
} else {
groups.put(supportedLibrariesGroup, Messages.getString("non-appengine-title")); //$NON-NLS-1$
}
groups.put(CloudLibraries.CLIENT_APIS_GROUP,
Messages.getString("clientapis-title")); //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CompositeUtil {

@SuppressWarnings("unchecked")
public static <T> T findControl(Composite composite, final Class<T> type) {
return (T) findControl(composite, control -> type.isInstance(control));
return (T) findControl(composite, type::isInstance);
}

public static Button findButton(Composite composite, final String text) {
Expand Down

0 comments on commit 431c2fc

Please sign in to comment.