@@ -74,4 +74,10 @@ public interface InternalProperties { | |||
* @throws IllegalArgumentException if {@code propertyKey} is {@code null} or empty | |||
*/ | |||
void write(String propertyKey, @Nullable String value); | |||
/** | |||
* Delete the specified property. | |||
* | |||
*/ | |||
void delete(String propertyKey); | |||
} |
@@ -59,6 +59,15 @@ public class InternalPropertiesImpl implements InternalProperties { | |||
} | |||
} | |||
@Override | |||
public void delete(String propertyKey) { | |||
checkPropertyKey(propertyKey); | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
dbClient.internalPropertiesDao().delete(dbSession, propertyKey); | |||
dbSession.commit(); | |||
} | |||
} | |||
private static void checkPropertyKey(@Nullable String propertyKey) { | |||
checkArgument(propertyKey != null && !propertyKey.isEmpty(), "property key can't be null nor empty"); | |||
} |
@@ -44,6 +44,12 @@ public class MapInternalProperties implements InternalProperties { | |||
values.put(propertyKey, value); | |||
} | |||
@Override | |||
public void delete(String propertyKey) { | |||
checkPropertyKey(propertyKey); | |||
values.remove(propertyKey); | |||
} | |||
private static void checkPropertyKey(@Nullable String propertyKey) { | |||
checkArgument(propertyKey != null && !propertyKey.isEmpty(), "property key can't be null nor empty"); | |||
} |
@@ -103,6 +103,13 @@ public class InternalPropertiesImplTest { | |||
verify(dbSession).commit(); | |||
} | |||
@Test | |||
public void delete_shouldCallDaoAndDeleteProperty() { | |||
underTest.delete(SOME_KEY); | |||
verify(internalPropertiesDao).delete(dbSession, SOME_KEY); | |||
verify(dbSession).commit(); | |||
} | |||
private void expectKeyNullOrEmptyIAE(ThrowingCallable callback) { | |||
assertThatThrownBy(callback) | |||
.isInstanceOf(IllegalArgumentException.class) |