*/
package org.sonar.server.ui;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.List;
-
import org.junit.Test;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.web.View;
import org.sonar.api.web.Widget;
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class ViewsTest {
private static FakeResourceViewer FAKE_TAB = new FakeResourceViewer();
private static final View[] VIEWS = {FAKE_PAGE, FAKE_TAB, FAKE_WIDGET};
@Test
- public void getPageById() {
+ public void should_get_page_by_id() {
final Views views = new Views(VIEWS);
- assertThat(views.getPage("fake-page").getTarget(), is(FakePage.class));
- assertThat(views.getPage("fake-widget"), nullValue());
- assertThat(views.getPage("foo"), nullValue());
- assertThat(views.getPage("fake-resourceviewer").getTarget(), is(FakeResourceViewer.class));
+ assertThat(views.getPage("fake-page").getTarget().getClass()).isEqualTo(FakePage.class);
+ assertThat(views.getPage("fake-widget")).isNull();
+ assertThat(views.getPage("foo")).isNull();
+ assertThat(views.getPage("fake-resourceviewer").getTarget().getClass()).isEqualTo(FakeResourceViewer.class);
}
@Test
- public void getPagesBySection() {
+ public void should_get_pages_by_section() {
final Views views = new Views(VIEWS);
List<ViewProxy<Page>> pages = views.getPages(NavigationSection.RESOURCE);
- assertThat(pages.size(), is(1));
- assertThat(pages.get(0).getTarget(), is(FakePage.class));
+ assertThat(pages.size()).isEqualTo(1);
+ assertThat(pages.get(0).getTarget().getClass()).isEqualTo(FakePage.class);
pages = views.getPages(NavigationSection.CONFIGURATION);
- assertThat(pages.size(), is(0));
+ assertThat(pages.size()).isEqualTo(0);
}
@Test
- public void getResourceViewers() {
+ public void should_get_resource_viewers() {
final Views views = new Views(VIEWS);
List resourceViewers = views.getPages(NavigationSection.RESOURCE_TAB);
- assertThat(resourceViewers.size(), is(1 + 4 /* default */));
- assertThat(resourceViewers.contains(new ViewProxy<FakeResourceViewer>(FAKE_TAB)), is(true));
+ assertThat(resourceViewers.size()).isEqualTo(1 + 4 /* default */);
+ assertThat(resourceViewers.contains(new ViewProxy<FakeResourceViewer>(FAKE_TAB))).isEqualTo(true);
}
@Test
- public void getWidgets() {
+ public void should_get_widgets() {
final Views views = new Views(VIEWS);
List<ViewProxy<Widget>> widgets = views.getWidgets(null, null, null, null);
- assertThat(widgets.size(), is(1));
- assertThat(widgets.get(0).getTarget(), is(FakeWidget.class));
+ assertThat(widgets.size()).isEqualTo(1);
+ assertThat(widgets.get(0).getTarget().getClass()).isEqualTo(FakeWidget.class);
}
@Test
- public void sortViewsByTitle() {
+ public void should_sort_views_by_title() {
final Views views = new Views(new View[] {new FakeWidget("ccc", "ccc"), new FakeWidget("aaa", "aaa"), new FakeWidget("bbb", "bbb")});
List<ViewProxy<Widget>> widgets = views.getWidgets(null, null, null, null);
- assertThat(widgets.size(), is(3));
- assertThat(widgets.get(0).getId(), is("aaa"));
- assertThat(widgets.get(1).getId(), is("bbb"));
- assertThat(widgets.get(2).getId(), is("ccc"));
+ assertThat(widgets.size()).isEqualTo(3);
+ assertThat(widgets.get(0).getId()).isEqualTo("aaa");
+ assertThat(widgets.get(1).getId()).isEqualTo("bbb");
+ assertThat(widgets.get(2).getId()).isEqualTo("ccc");
}
@Test
- public void prefixTitleByNumberToDisplayFirst() {
+ public void should_prefix_title_by_number_to_display_first() {
final Views views = new Views(new View[] {new FakeWidget("other", "Other"), new FakeWidget("1id", "1widget"), new FakeWidget("2id", "2widget")});
List<ViewProxy<Widget>> widgets = views.getWidgets(null, null, null, null);
- assertThat(widgets.size(), is(3));
- assertThat(widgets.get(0).getId(), is("1id"));
- assertThat(widgets.get(1).getId(), is("2id"));
- assertThat(widgets.get(2).getId(), is("other"));
+ assertThat(widgets.size()).isEqualTo(3);
+ assertThat(widgets.get(0).getId()).isEqualTo("1id");
+ assertThat(widgets.get(1).getId()).isEqualTo("2id");
+ assertThat(widgets.get(2).getId()).isEqualTo("other");
}
@Test
- public void acceptNavigationSection() {
+ public void should_accept_navigation_section() {
ViewProxy proxy = mock(ViewProxy.class);
when(proxy.getSections()).thenReturn(new String[] {NavigationSection.RESOURCE});
when(proxy.isWidget()).thenReturn(false);
- assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE), is(true));
- assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME), is(false));
- assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION), is(false));
- assertThat(Views.acceptNavigationSection(proxy, null), is(true));
+ assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE)).isEqualTo(true);
+ assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME)).isEqualTo(false);
+ assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION)).isEqualTo(false);
+ assertThat(Views.acceptNavigationSection(proxy, NavigationSection.PROJECT_CONFIGURATION)).isEqualTo(false);
+ assertThat(Views.acceptNavigationSection(proxy, null)).isEqualTo(true);
}
@Test
- public void acceptAvailableMeasures() {
+ public void should_accept_available_measures() {
ViewProxy proxy = mock(ViewProxy.class);
when(proxy.acceptsAvailableMeasures(new String[] {"lines"})).thenReturn(true);
when(proxy.acceptsAvailableMeasures(new String[] {"ncloc"})).thenReturn(false);
- assertThat(Views.acceptAvailableMeasures(proxy, null), is(true));
- assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"lines"}), is(true));
- assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"ncloc"}), is(false));
+ assertThat(Views.acceptAvailableMeasures(proxy, null)).isEqualTo(true);
+ assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"lines"})).isEqualTo(true);
+ assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"ncloc"})).isEqualTo(false);
- assertThat(Views.accept(proxy, null, null, null, null, null), is(true));
- assertThat(Views.accept(proxy, null, null, null, null, new String[] {"lines"}), is(true));
- assertThat(Views.accept(proxy, null, null, null, null, new String[] {"ncloc"}), is(false));
+ assertThat(Views.accept(proxy, null, null, null, null, null)).isEqualTo(true);
+ assertThat(Views.accept(proxy, null, null, null, null, new String[] {"lines"})).isEqualTo(true);
+ assertThat(Views.accept(proxy, null, null, null, null, new String[] {"ncloc"})).isEqualTo(false);
}
@Test
- public void doNotCheckNavigationSectionOnWidgets() {
+ public void should_not_check_navigation_section_on_widgets() {
ViewProxy proxy = mock(ViewProxy.class);
when(proxy.isWidget()).thenReturn(true);
- assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE), is(true));
- assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME), is(true));
- assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION), is(true));
- assertThat(Views.acceptNavigationSection(proxy, null), is(true));
+ assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE)).isEqualTo(true);
+ assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME)).isEqualTo(true);
+ assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION)).isEqualTo(true);
+ assertThat(Views.acceptNavigationSection(proxy, NavigationSection.PROJECT_CONFIGURATION)).isEqualTo(true);
+ assertThat(Views.acceptNavigationSection(proxy, null)).isEqualTo(true);
}
@Test
- public void checkResourceLanguage() {
+ public void should_check_resource_language() {
ViewProxy proxy = mock(ViewProxy.class);
- assertThat(Views.acceptResourceLanguage(proxy, Java.KEY), is(true));
+ assertThat(Views.acceptResourceLanguage(proxy, Java.KEY)).isEqualTo(true);
when(proxy.getResourceLanguages()).thenReturn(new String[] {"foo"});
- assertThat(Views.acceptResourceLanguage(proxy, Java.KEY), is(false));
- assertThat(Views.acceptResourceLanguage(proxy, "foo"), is(true));
+ assertThat(Views.acceptResourceLanguage(proxy, Java.KEY)).isEqualTo(false);
+ assertThat(Views.acceptResourceLanguage(proxy, "foo")).isEqualTo(true);
}
@Test
- public void checkResourceScope() {
+ public void should_check_resource_scope() {
ViewProxy proxy = mock(ViewProxy.class);
- assertThat(Views.acceptResourceScope(proxy, Scopes.FILE), is(true));
+ assertThat(Views.acceptResourceScope(proxy, Scopes.FILE)).isEqualTo(true);
when(proxy.getResourceScopes()).thenReturn(new String[] {Scopes.PROJECT, Scopes.FILE});
- assertThat(Views.acceptResourceScope(proxy, Scopes.FILE), is(true));
- assertThat(Views.acceptResourceScope(proxy, Scopes.DIRECTORY), is(false));
+ assertThat(Views.acceptResourceScope(proxy, Scopes.FILE)).isEqualTo(true);
+ assertThat(Views.acceptResourceScope(proxy, Scopes.DIRECTORY)).isEqualTo(false);
}
@Test
- public void checkResourceQualifier() {
+ public void should_check_resource_qualifier() {
ViewProxy proxy = mock(ViewProxy.class);
- assertThat(Views.acceptResourceQualifier(proxy, Scopes.FILE), is(true));
+ assertThat(Views.acceptResourceQualifier(proxy, Scopes.FILE)).isEqualTo(true);
when(proxy.getResourceQualifiers()).thenReturn(new String[] {Qualifiers.CLASS, Qualifiers.FILE});
- assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.FILE), is(true));
- assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.PACKAGE), is(false));
+ assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.FILE)).isEqualTo(true);
+ assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.PACKAGE)).isEqualTo(false);
}
}