Browse Source

Added unit tests

pull/7/head
Adrian Gonzalez 12 years ago
parent
commit
44c2892964
  1. 6
      pom.xml
  2. 1
      src/main/java/com/englishtown/stash/hook/DefaultSettingsReflectionHelper.java
  3. 11
      src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java
  4. 40
      src/test/java/com/englishtown/stash/hook/DefaultSettingsReflectionHelperTest.java

6
pom.xml

@ -26,6 +26,7 @@
<packaging>atlassian-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<stash.version>2.3.1</stash.version>
<stash.data.version>2.3.1</stash.data.version>
<amps.version>4.1.7</amps.version>
@ -100,6 +101,11 @@
<version>${common-lang.version}</version>
</dependency>
<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.stash</groupId>
<artifactId>stash-service-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>

1
src/main/java/com/englishtown/stash/hook/DefaultSettingsReflectionHelper.java

@ -3,7 +3,6 @@ package com.englishtown.stash.hook;
import com.atlassian.stash.setting.Settings;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
/**

11
src/main/java/com/englishtown/stash/hook/MirrorRepositoryHook.java

@ -18,7 +18,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
@ -28,7 +27,7 @@ import java.util.concurrent.TimeUnit;
public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, RepositorySettingsValidator {
static class MirrorSettings {
protected static class MirrorSettings {
String mirrorRepoUrl;
String username;
String password;
@ -147,7 +146,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
}
}
URI getAuthenticatedUrl(String mirrorRepoUrl, String username, String password) throws URISyntaxException {
protected URI getAuthenticatedUrl(String mirrorRepoUrl, String username, String password) throws URISyntaxException {
URI uri = URI.create(mirrorRepoUrl);
String userInfo = username + ":" + password;
@ -197,7 +196,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
}
List<MirrorSettings> getMirrorSettings(Settings settings) {
protected List<MirrorSettings> getMirrorSettings(Settings settings) {
List<MirrorSettings> results = new ArrayList<MirrorSettings>();
Map<String, Object> allSettings = settings.asMap();
@ -221,7 +220,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
return results;
}
boolean validate(MirrorSettings ms, Settings settings, SettingsValidationErrors errors) {
protected boolean validate(MirrorSettings ms, Settings settings, SettingsValidationErrors errors) {
boolean result = true;
@ -258,7 +257,7 @@ public class MirrorRepositoryHook implements AsyncPostReceiveRepositoryHook, Rep
return result;
}
void updateSettings(List<MirrorSettings> mirrorSettings, Settings settings) {
protected void updateSettings(List<MirrorSettings> mirrorSettings, Settings settings) {
Map<String, Object> values = new HashMap<String, Object>();

40
src/test/java/com/englishtown/stash/hook/DefaultSettingsReflectionHelperTest.java

@ -0,0 +1,40 @@
package com.englishtown.stash.hook;
import com.atlassian.stash.internal.setting.MapSettingsBuilder;
import com.atlassian.stash.setting.Settings;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/**
* Created with IntelliJ IDEA.
* User: adriangonzalez
* Date: 5/13/13
* Time: 3:54 PM
* To change this template use File | Settings | File Templates.
*/
public class DefaultSettingsReflectionHelperTest {
@Test
public void testSet() throws Exception {
DefaultSettingsReflectionHelper helper = new DefaultSettingsReflectionHelper();
MapSettingsBuilder builder = new MapSettingsBuilder();
Map<String, Object> values = new HashMap<String, Object>();
builder.add("old", "old");
values.put("new", "new");
Settings settings = builder.build();
helper.set(values, settings);
assertNull(settings.getString("old"));
assertEquals("new", settings.getString("new"));
}
}
Loading…
Cancel
Save