Use default implementation to keep compatibility

This commit is contained in:
René Pfeuffer
2020-07-01 17:42:30 +02:00
parent 63692d497a
commit a0d9bacd80
7 changed files with 11 additions and 59 deletions

View File

@@ -45,5 +45,7 @@ public interface NamespaceStrategy {
*
* @return namespace can be changed
*/
boolean canBeChanged();
default boolean canBeChanged() {
return false;
}
}

View File

@@ -50,9 +50,4 @@ public class CurrentYearNamespaceStrategy implements NamespaceStrategy {
public String createNamespace(Repository repository) {
return String.valueOf(Year.now(clock).getValue());
}
@Override
public boolean canBeChanged() {
return false;
}
}

View File

@@ -32,9 +32,4 @@ public class RepositoryTypeNamespaceStrategy implements NamespaceStrategy {
public String createNamespace(Repository repository) {
return repository.getType();
}
@Override
public boolean canBeChanged() {
return false;
}
}

View File

@@ -34,9 +34,4 @@ public class UsernameNamespaceStrategy implements NamespaceStrategy {
public String createNamespace(Repository repository) {
return SecurityUtils.getSubject().getPrincipal().toString();
}
@Override
public boolean canBeChanged() {
return false;
}
}

View File

@@ -80,11 +80,6 @@ class NamespaceStrategyResourceTest {
public String createNamespace(Repository repository) {
return "awesome";
}
@Override
public boolean canBeChanged() {
return false;
}
}
private static class SuperNamespaceStrategy implements NamespaceStrategy {
@@ -92,11 +87,6 @@ class NamespaceStrategyResourceTest {
public String createNamespace(Repository repository) {
return "super";
}
@Override
public boolean canBeChanged() {
return false;
}
}
private static class MegaNamespaceStrategy implements NamespaceStrategy {
@@ -104,10 +94,5 @@ class NamespaceStrategyResourceTest {
public String createNamespace(Repository repository) {
return "mega";
}
@Override
public boolean canBeChanged() {
return false;
}
}
}

View File

@@ -66,17 +66,12 @@ class NamespaceStrategyProviderTest {
return new LinkedHashSet<>(Arrays.asList(new Trillian(), new Zaphod(), new Arthur()));
}
private static class Trillian implements NamespaceStrategy {
private static class Trillian implements NamespaceStrategy{
@Override
public String createNamespace(Repository repository) {
return "trillian";
}
@Override
public boolean canBeChanged() {
return false;
}
}
private static class Zaphod implements NamespaceStrategy {
@@ -85,11 +80,6 @@ class NamespaceStrategyProviderTest {
public String createNamespace(Repository repository) {
return "zaphod";
}
@Override
public boolean canBeChanged() {
return false;
}
}
private static class Arthur implements NamespaceStrategy {
@@ -98,11 +88,6 @@ class NamespaceStrategyProviderTest {
public String createNamespace(Repository repository) {
return "arthur";
}
@Override
public boolean canBeChanged() {
return false;
}
}
}

View File

@@ -30,7 +30,7 @@ import sonia.scm.ScmConstraintViolationException;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.*;
class NamespaceStrategyValidatorTest {
@@ -52,11 +52,6 @@ class NamespaceStrategyValidatorTest {
public String createNamespace(Repository repository) {
return null;
}
@Override
public boolean canBeChanged() {
return false;
}
}
}