Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement #84: Avoid configuration data output via Configuration.toString() #87

Merged
merged 4 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.UUID;

import net.obvj.confectory.ConfigurationSourceException;
import net.obvj.confectory.mapper.Mapper;
Expand All @@ -32,6 +33,7 @@
*/
public class StringSource<T> extends AbstractSource<T> implements Source<T>
{
private final String uuid;
/**
* Builds a new configuration source from the specified string.
*
Expand All @@ -40,6 +42,7 @@ public class StringSource<T> extends AbstractSource<T> implements Source<T>
public StringSource(String source)
{
super(Objects.requireNonNull(source, "The source string must not be null"));
uuid = UUID.randomUUID().toString();
}

@Override
Expand All @@ -56,4 +59,10 @@ public T load(Mapper<T> mapper)
}
}

@Override
public String toString()
{
return new StringBuilder().append(getClass().getSimpleName()).append("(").append(uuid).append(")")
Copy link
Owner Author

@oswaldobapvicjr oswaldobapvicjr Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated code from the AbstractSource class, except for the UUID variable.
To avoid this code duplication, consider adding a new toString(String) method in the parent class that accepts either the UUID (here) or the parameter (parent).

.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ void equalsAndHashCode_notSimilarObjectsPlacedInAHashSet_differentObject()
void toString_validString()
{
assertThat(CONFIG_NS1_STRING_1.toString().replaceAll("\"", ""),
containsAll("namespace:" + NAMESPACE1, "source:" + SOURCE_STRING1, "precedence:1"));
containsAll("namespace:" + NAMESPACE1, "source:StringSource", "precedence:1"));

assertThat(CONFIG_NS1_STRING_1B.toString().replaceAll("\"", ""),
containsAll("namespace:" + NAMESPACE1, "source:" + SOURCE_STRING1, "precedence:2"));
containsAll("namespace:" + NAMESPACE1, "source:StringSource", "precedence:2"));
}

@Test
Expand Down