-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Johannes Schneider <johannes.schneider@bosch.io>
- Loading branch information
Showing
12 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...l/placeholders/src/main/java/org/eclipse/ditto/model/placeholders/FeaturePlaceholder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (c) 2020 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.model.placeholders; | ||
|
||
/** | ||
* A {@link Placeholder} that requires a {@code String} (a valid Feature ID) to resolve it's placeholders. | ||
* | ||
* @since 1.5.0 | ||
*/ | ||
public interface FeaturePlaceholder extends Placeholder<String> { | ||
} |
67 changes: 67 additions & 0 deletions
67
...lders/src/main/java/org/eclipse/ditto/model/placeholders/ImmutableFeaturePlaceholder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2020 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.model.placeholders; | ||
|
||
import static org.eclipse.ditto.model.base.common.ConditionChecker.argumentNotEmpty; | ||
import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
/** | ||
* Placeholder implementation that replaces {@code feature:id}. The input value is a String and must be a valid Feature | ||
* ID. | ||
* | ||
* @since 1.5.0 | ||
*/ | ||
@Immutable | ||
final class ImmutableFeaturePlaceholder implements FeaturePlaceholder { | ||
|
||
private static final String ID_PLACEHOLDER = "id"; | ||
|
||
private static final List<String> SUPPORTED = Collections.singletonList(ID_PLACEHOLDER); | ||
|
||
/** | ||
* Singleton instance of the {@code ImmutableFeaturePlaceholder}. | ||
*/ | ||
static final ImmutableFeaturePlaceholder INSTANCE = new ImmutableFeaturePlaceholder(); | ||
|
||
@Override | ||
public Optional<String> resolve(final String featureId, final String placeholder) { | ||
checkNotNull(featureId, "featureId"); | ||
argumentNotEmpty(placeholder, "placeholder"); | ||
if (ID_PLACEHOLDER.equals(placeholder)) { | ||
return Optional.of(featureId); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public String getPrefix() { | ||
return "feature"; | ||
} | ||
|
||
@Override | ||
public List<String> getSupportedNames() { | ||
return SUPPORTED; | ||
} | ||
|
||
@Override | ||
public boolean supports(final String name) { | ||
return SUPPORTED.contains(name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...s/src/test/java/org/eclipse/ditto/model/placeholders/ImmutableFeaturePlaceholderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2020 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.model.placeholders; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.mutabilitydetector.unittesting.MutabilityAssert; | ||
import org.mutabilitydetector.unittesting.MutabilityMatchers; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
import nl.jqno.equalsverifier.Warning; | ||
|
||
/** | ||
* Tests {@link ImmutableFeaturePlaceholder}. | ||
*/ | ||
public final class ImmutableFeaturePlaceholderTest { | ||
|
||
private static final String FEATURE_ID = "FluxCapacitor"; | ||
private static final FeaturePlaceholder UNDER_TEST = ImmutableFeaturePlaceholder.INSTANCE; | ||
|
||
@Test | ||
public void assertImmutability() { | ||
MutabilityAssert.assertInstancesOf(ImmutableFeaturePlaceholder.class, MutabilityMatchers.areImmutable()); | ||
} | ||
|
||
@Test | ||
public void testHashCodeAndEquals() { | ||
EqualsVerifier.forClass(ImmutableFeaturePlaceholder.class) | ||
.suppress(Warning.INHERITED_DIRECTLY_FROM_OBJECT) | ||
.usingGetClass() | ||
.verify(); | ||
} | ||
|
||
@Test | ||
public void testReplaceFeatureId() { | ||
assertThat(UNDER_TEST.resolve(FEATURE_ID, "id")).contains(FEATURE_ID); | ||
} | ||
|
||
@Test | ||
public void testUnknownPlaceholderReturnsEmpty() { | ||
assertThat(UNDER_TEST.resolve(FEATURE_ID, "feature_id")).isEmpty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters