mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 02:31:14 +01:00
Merge base branch into feature
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.ModelObject;
|
||||
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
import javax.ws.rs.core.Request;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AbstractManagerResourceTest {
|
||||
|
||||
@Mock
|
||||
private Manager<Simple, Exception> manager;
|
||||
@Mock
|
||||
private Request request;
|
||||
@Captor
|
||||
private ArgumentCaptor<Comparator<Simple>> comparatorCaptor;
|
||||
|
||||
private AbstractManagerResource<Simple, Exception> abstractManagerResource;
|
||||
|
||||
@Before
|
||||
public void captureComparator() {
|
||||
when(manager.getAll(comparatorCaptor.capture(), eq(0), eq(1))).thenReturn(emptyList());
|
||||
abstractManagerResource = new SimpleManagerResource();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAcceptDefaultSortByParameter() {
|
||||
abstractManagerResource.getAll(request, 0, 1, null, true);
|
||||
|
||||
Comparator<Simple> comparator = comparatorCaptor.getValue();
|
||||
assertTrue(comparator.compare(new Simple("1", null), new Simple("2", null)) > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAcceptValidSortByParameter() {
|
||||
abstractManagerResource.getAll(request, 0, 1, "data", true);
|
||||
|
||||
Comparator<Simple> comparator = comparatorCaptor.getValue();
|
||||
assertTrue(comparator.compare(new Simple("", "1"), new Simple("", "2")) > 0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldFailForIllegalSortByParameter() {
|
||||
abstractManagerResource.getAll(request, 0, 1, "x", true);
|
||||
}
|
||||
|
||||
|
||||
private class SimpleManagerResource extends AbstractManagerResource<Simple, Exception> {
|
||||
|
||||
{
|
||||
disableCache = true;
|
||||
}
|
||||
|
||||
private SimpleManagerResource() {
|
||||
super(AbstractManagerResourceTest.this.manager, Simple.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GenericEntity<Collection<Simple>> createGenericEntity(Collection<Simple> items) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getId(Simple item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPathPart() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Simple implements ModelObject {
|
||||
|
||||
private String id;
|
||||
private String data;
|
||||
|
||||
Simple(String id, String data) {
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getLastModified() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import org.mockito.Mock;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -47,7 +46,7 @@ public class UserDtoToUserMapperTest {
|
||||
UserDto dto = new UserDto();
|
||||
dto.setName("abc");
|
||||
dto.setCreationDate(Instant.now());
|
||||
dto.setLastModified(Optional.empty());
|
||||
dto.setLastModified(null);
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,6 @@ public class UserToUserDtoMapperTest {
|
||||
UserDto userDto = mapper.map(user);
|
||||
|
||||
assertEquals(expectedCreationDate, userDto.getCreationDate());
|
||||
assertEquals(expectedModificationDate, userDto.getLastModified().get());
|
||||
assertEquals(expectedModificationDate, userDto.getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user