Replace model object exception with generic ones and migrate guice

This commit is contained in:
René Pfeuffer
2018-08-21 07:53:33 +02:00
parent bb9a0657a5
commit a0f74e3329
227 changed files with 1380 additions and 3549 deletions

View File

@@ -33,21 +33,21 @@
package sonia.scm;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import sonia.scm.util.MockUtil;
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
*
* @param <T>
* @param <E>
*/
public abstract class ManagerTestBase<T extends ModelObject, E extends Exception>
public abstract class ManagerTestBase<T extends ModelObject>
{
@Rule
@@ -55,7 +55,7 @@ public abstract class ManagerTestBase<T extends ModelObject, E extends Exception
protected SCMContextProvider contextProvider;
protected Manager<T, E> manager;
protected Manager<T> manager;
@Before
public void setUp() throws IOException {
@@ -75,6 +75,6 @@ public abstract class ManagerTestBase<T extends ModelObject, E extends Exception
*
* @return
*/
protected abstract Manager<T, E> createManager();
protected abstract Manager<T> createManager();
}

View File

@@ -34,6 +34,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.Sets;
import sonia.scm.AlreadyExistsException;
import sonia.scm.io.DefaultFileSystem;
import sonia.scm.store.ConfigurationStoreFactory;
@@ -70,10 +71,10 @@ public class DummyRepositoryHandler
@Override
protected void create(Repository repository, File directory) throws RepositoryException {
protected void create(Repository repository, File directory) throws AlreadyExistsException {
String key = repository.getNamespace() + "/" + repository.getName();
if (existingRepoNames.contains(key)) {
throw new RepositoryAlreadyExistsException("Repo exists");
throw new AlreadyExistsException();
} else {
existingRepoNames.add(key);
}

View File

@@ -35,6 +35,7 @@ package sonia.scm.repository;
import org.junit.Test;
import sonia.scm.AbstractTestBase;
import sonia.scm.AlreadyExistsException;
import sonia.scm.store.ConfigurationStoreFactory;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import sonia.scm.util.IOUtil;
@@ -60,12 +61,12 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
ConfigurationStoreFactory factory, File directory);
@Test
public void testCreate() throws RepositoryException {
public void testCreate() throws AlreadyExistsException {
createRepository();
}
@Test
public void testCreateResourcePath() throws RepositoryException {
public void testCreateResourcePath() throws AlreadyExistsException {
Repository repository = createRepository();
String path = handler.createResourcePath(repository);
@@ -75,7 +76,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
}
@Test
public void testDelete() throws RepositoryException {
public void testDelete() throws Exception {
Repository repository = createRepository();
handler.delete(repository);
@@ -100,7 +101,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
}
}
private Repository createRepository() throws RepositoryException {
private Repository createRepository() throws AlreadyExistsException {
Repository repository = RepositoryTestData.createHeartOfGold();
handler.create(repository);

View File

@@ -34,8 +34,8 @@ package sonia.scm.repository.client.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import sonia.scm.repository.Person;
/**
@@ -105,7 +105,7 @@ public final class CommitRequest
public String toString()
{
//J-
return Objects.toStringHelper(this)
return MoreObjects.toStringHelper(this)
.add("author", author)
.add("message", message)
.toString();

View File

@@ -34,8 +34,8 @@ package sonia.scm.repository.client.spi;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
/**
*
* @author Sebastian Sdorra
@@ -103,7 +103,7 @@ public final class TagRequest
public String toString()
{
//J-
return Objects.toStringHelper(this)
return MoreObjects.toStringHelper(this)
.add("revision", revision)
.add("name", name)
.toString();

View File

@@ -37,46 +37,33 @@ package sonia.scm.user;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.junit.Test;
import sonia.scm.AlreadyExistsException;
import sonia.scm.ConcurrentModificationException;
import sonia.scm.Manager;
import sonia.scm.ManagerTestBase;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import sonia.scm.NotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
/**
*
* @author Sebastian Sdorra
*/
public abstract class UserManagerTestBase
extends ManagerTestBase<User, UserException>
{
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
//~--- JDK imports ------------------------------------------------------------
public abstract class UserManagerTestBase extends ManagerTestBase<User> {
/** Field description */
public static final int THREAD_COUNT = 10;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test
public void testCreate() throws UserException, IOException
{
public void testCreate() throws AlreadyExistsException {
User zaphod = UserTestData.createZaphod();
manager.create(zaphod);
@@ -87,16 +74,8 @@ public abstract class UserManagerTestBase
assertUserEquals(zaphod, otherUser);
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test(expected = UserAlreadyExistsException.class)
public void testCreateExisting() throws UserException, IOException
{
@Test(expected = AlreadyExistsException.class)
public void testCreateExisting() throws AlreadyExistsException {
User zaphod = UserTestData.createZaphod();
manager.create(zaphod);
@@ -107,16 +86,8 @@ public abstract class UserManagerTestBase
manager.create(sameUser);
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test
public void testDelete() throws UserException, IOException
{
public void testDelete() throws Exception {
User zaphod = UserTestData.createZaphod();
manager.create(zaphod);
@@ -125,29 +96,13 @@ public abstract class UserManagerTestBase
assertNull(manager.get("zaphod"));
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test(expected = UserNotFoundException.class)
public void testDeleteNotFound() throws UserException, IOException
{
@Test(expected = NotFoundException.class)
public void testDeleteNotFound() throws Exception {
manager.delete(UserTestData.createDent());
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test
public void testGet() throws UserException, IOException
{
public void testGet() throws AlreadyExistsException {
User zaphod = UserTestData.createZaphod();
manager.create(zaphod);
@@ -160,16 +115,8 @@ public abstract class UserManagerTestBase
assertEquals("Zaphod Beeblebrox", zaphod.getDisplayName());
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test
public void testGetAll() throws UserException, IOException
{
public void testGetAll() throws AlreadyExistsException {
User zaphod = UserTestData.createZaphod();
manager.create(zaphod);
@@ -233,16 +180,8 @@ public abstract class UserManagerTestBase
assertEquals(reference.getDisplayName(), "Tricia McMillan");
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test
public void testModify() throws UserException, IOException
{
public void testModify() throws AlreadyExistsException, NotFoundException, ConcurrentModificationException {
User zaphod = UserTestData.createZaphod();
manager.create(zaphod);
@@ -256,31 +195,13 @@ public abstract class UserManagerTestBase
assertEquals(otherUser.getDisplayName(), "Tricia McMillan");
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test(expected = UserException.class)
public void testModifyNotExisting() throws UserException, IOException
{
@Test(expected = NotFoundException.class)
public void testModifyNotExisting() throws NotFoundException, ConcurrentModificationException {
manager.modify(UserTestData.createZaphod());
}
/**
* Method description
*
*
* @throws IOException
* @throws InterruptedException
* @throws UserException
*/
@Test
public void testMultiThreaded()
throws UserException, IOException, InterruptedException
{
public void testMultiThreaded() throws InterruptedException {
int initialSize = manager.getAll().size();
List<MultiThreadTester> testers = new ArrayList<MultiThreadTester>();
@@ -316,16 +237,8 @@ public abstract class UserManagerTestBase
assertTrue((initialSize + THREAD_COUNT) == manager.getAll().size());
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test
public void testRefresh() throws UserException, IOException
{
public void testRefresh() throws AlreadyExistsException, NotFoundException {
User zaphod = UserTestData.createZaphod();
manager.create(zaphod);
@@ -335,26 +248,11 @@ public abstract class UserManagerTestBase
assertEquals(zaphod.getDisplayName(), "Zaphod Beeblebrox");
}
/**
* Method description
*
*
* @throws IOException
* @throws UserException
*/
@Test(expected = UserNotFoundException.class)
public void testRefreshNotFound() throws UserException, IOException
{
@Test(expected = NotFoundException.class)
public void testRefreshNotFound() throws NotFoundException {
manager.refresh(UserTestData.createDent());
}
/**
* Method description
*
*
* @param user
* @param otherUser
*/
private void assertUserEquals(User user, User otherUser)
{
assertEquals(user.getName(), otherUser.getName());
@@ -363,35 +261,16 @@ public abstract class UserManagerTestBase
assertEquals(user.getPassword(), otherUser.getPassword());
}
//~--- inner classes --------------------------------------------------------
/**
* Class description
*
*
* @version Enter version here..., 2010-11-23
* @author Sebastian Sdorra
*/
private static class MultiThreadTester implements Runnable
{
/**
* Constructs ...
*
*
* @param userManager
*/
public MultiThreadTester(Manager<User, UserException> userManager)
public MultiThreadTester(Manager<User> userManager)
{
this.manager = userManager;
}
//~--- methods ------------------------------------------------------------
/**
* Method description
*
*/
@Override
public void run()
{
@@ -410,17 +289,7 @@ public abstract class UserManagerTestBase
finished = true;
}
/**
* Method description
*
*
* @return
*
* @throws IOException
* @throws UserException
*/
private User createUser() throws UserException, IOException
{
private User createUser() throws AlreadyExistsException {
String id = UUID.randomUUID().toString();
User user = new User(id, id.concat(" displayName"),
id.concat("@mail.com"));
@@ -430,18 +299,7 @@ public abstract class UserManagerTestBase
return user;
}
/**
* Method description
*
*
* @param user
*
* @throws IOException
* @throws UserException
*/
private void modifyAndDeleteUser(User user)
throws UserException, IOException
{
private void modifyAndDeleteUser(User user) throws IOException, NotFoundException, ConcurrentModificationException {
String name = user.getName();
String nd = name.concat(" new displayname");
@@ -463,6 +321,6 @@ public abstract class UserManagerTestBase
private boolean finished = false;
/** Field description */
private Manager<User, UserException> manager;
private Manager<User> manager;
}
}