Commit 55812c74 authored by Florine Boudin's avatar Florine Boudin
Browse files

BS-11264 Add tests, and modified getElements and getChildren to return

empty table instead of null.
parent 803b691e
......@@ -17,6 +17,7 @@
package org.bonitasoft.studio.common.repository.ui.viewer;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.assertj.core.api.Assertions;
......@@ -44,12 +45,24 @@ public class RepositoryTreeContentProviderTest {
Assertions.assertThat(children).contains(repoFileStore);
}
@Test
public void testGetChildrenReturnEmptyListIfNotARepositoryStore() {
final Object[] children = new RepositoryTreeContentProvider().getChildren(new Object());
Assertions.assertThat(children).isNotNull();
Assertions.assertThat(children).isEmpty();
}
@Test
public void testGetParent() {
Mockito.doReturn(repoStore).when(repoFileStore).getParentStore();
Assertions.assertThat(new RepositoryTreeContentProvider().getParent(repoFileStore)).isEqualTo(repoStore);
}
@Test
public void testGetParentReturnNullIfNotARepositoryFileStore() {
Assertions.assertThat(new RepositoryTreeContentProvider().getParent(new Object())).isEqualTo(null);
}
@Test
public void testHasChildren() {
Mockito.doReturn(Collections.emptyList()).when(repoStore).getChildren();
......@@ -59,4 +72,25 @@ public class RepositoryTreeContentProviderTest {
Assertions.assertThat(new RepositoryTreeContentProvider().hasChildren(repoStore)).isTrue();
}
@Test
public void testHasChildrenReturnFalseIfNotARepositoryFileStore() {
Assertions.assertThat(new RepositoryTreeContentProvider().hasChildren(new Object())).isFalse();
}
@Test
public void testGetElementsReturnATable() {
final Collection<Object> collec = Collections.emptyList();
final Object[] elements = new RepositoryTreeContentProvider().getElements(collec);
Assertions.assertThat(elements).isInstanceOf(Object[].class);
}
@Test
public void testGetElementsReturnEmptyListIfNotACollection() {
final Object[] elements = new RepositoryTreeContentProvider().getElements(new Object());
Assertions.assertThat(elements).isInstanceOf(Object[].class);
Assertions.assertThat(elements).isNotNull();
Assertions.assertThat(elements).isEmpty();
}
}
......@@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.repository.ui.viewer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
......@@ -28,30 +30,30 @@ public class RepositoryTreeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang
* .Object)
*/
@Override
public Object[] getChildren(Object parentElement) {
public Object[] getChildren(final Object parentElement) {
if (parentElement instanceof IRepositoryStore) {
List<IRepositoryFileStore> children = ((IRepositoryStore) parentElement).getChildren();
final List<IRepositoryFileStore> children = ((IRepositoryStore) parentElement).getChildren();
return children.toArray();
}
return null;
return new Object[]{};
}
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang
* .Object)
*/
@Override
public Object getParent(Object element) {
public Object getParent(final Object element) {
if (element instanceof IRepositoryFileStore){
return ((IRepositoryFileStore) element).getParentStore();
}
......@@ -60,13 +62,13 @@ public class RepositoryTreeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang
* .Object)
*/
@Override
public boolean hasChildren(Object element) {
public boolean hasChildren(final Object element) {
if (element instanceof IRepositoryStore) {
return !((IRepositoryStore) element).getChildren().isEmpty();
}
......@@ -75,22 +77,22 @@ public class RepositoryTreeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.jface.viewers.IStructuredContentProvider#getElements(
* java.lang.Object)
*/
@Override
public Object[] getElements(Object element) {
public Object[] getElements(final Object element) {
if (element instanceof Collection<?>) {
return ((Collection<?>) element).toArray() ;
}
return null;
return new Object[]{};
}
/*
* (non-Javadoc)
*
*
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
@Override
......@@ -99,13 +101,13 @@ public class RepositoryTreeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
*
*
* @see
* org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
* .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment