package net.pterodactylus.fcp.plugin;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Wrapper around a web-of-trust identity.
*
/** The identity’s request URI. */
private final String requestUri;
+ private final Set<String> contexts = new HashSet<>();
+
/**
* Creates a new identity.
*
* @param requestUri
* The request URI of the identity
*/
- public Identity(String identifier, String nickname, String requestUri) {
+ public Identity(String identifier, String nickname, String requestUri, Collection<String> contexts) {
this.identifier = identifier;
this.nickname = nickname;
this.requestUri = requestUri;
+ this.contexts.addAll(contexts);
}
/**
return requestUri;
}
+ public Set<String> getContexts() {
+ return Collections.unmodifiableSet(contexts);
+ }
+
/**
* {@inheritDoc}
*/
package net.pterodactylus.fcp.plugin;
+import java.util.Collection;
+import java.util.StringJoiner;
+
/**
* Wrapper around a web-of-trust own identity.
*
* @param insertUri
* The insert URI of the identity
*/
- public OwnIdentity(String identifier, String nickname, String requestUri, String insertUri) {
- super(identifier, nickname, requestUri);
+ public OwnIdentity(String identifier, String nickname, String requestUri, String insertUri, Collection<String> contexts) {
+ super(identifier, nickname, requestUri, contexts);
this.insertUri = insertUri;
}
return insertUri;
}
+ @Override
+ public String toString() {
+ return new StringJoiner(", ", OwnIdentity.class.getSimpleName() + "[", "]")
+ .add("identifier='" + getIdentifier() + "'")
+ .add("nickname='" + getNickname() + "'")
+ .add("requestUri='" + getRequestUri() + "'")
+ .add("insertUri='" + insertUri + "'")
+ .add("contexts='" + getContexts() + "'")
+ .toString();
+ }
+
}
import net.pterodactylus.fcp.highlevel.FcpClient;
import net.pterodactylus.fcp.highlevel.FcpException;
+import static java.util.Collections.emptySet;
+
/**
* Simplifies handling of the web-of-trust plugin.
*
String identifier = replies.get("ID");
String newRequestUri = replies.get("RequestURI");
String newInsertUri = replies.get("InsertURI");
- return new OwnIdentity(identifier, nickname, newRequestUri, newInsertUri);
+ return new OwnIdentity(identifier, nickname, newRequestUri, newInsertUri, emptySet());
}
/**
String nickname = replies.get("Nickname" + identityIndex);
String requestUri = replies.get("RequestURI" + identityIndex);
String insertUri = replies.get("InsertURI" + identityIndex);
- ownIdentities.add(new OwnIdentity(identity, nickname, requestUri, insertUri));
+ ownIdentities.add(new OwnIdentity(identity, nickname, requestUri, insertUri, emptySet()));
}
return ownIdentities;
}
}
String identifier = replies.get("ID");
String nickname = replies.get("Nickname");
- return new Identity(identifier, nickname, requestUri);
+ return new Identity(identifier, nickname, requestUri, emptySet());
}
/**
String identifier = replies.get("Identity" + identityIndex);
String nickname = replies.get("Nickname" + identityIndex);
String requestUri = replies.get("RequestURI" + identityIndex);
- identities.add(new Identity(identifier, nickname, requestUri));
+ identities.add(new Identity(identifier, nickname, requestUri, emptySet()));
}
return identities;
}
String requestUri = replies.get("RequestURI" + identityIndex);
byte trust = Byte.parseByte(replies.get("Value" + identityIndex));
String comment = replies.get("Comment" + identityIndex);
- identityTrusts.put(new Identity(identifier, nickname, requestUri), new IdentityTrust(trust, comment));
+ identityTrusts.put(new Identity(identifier, nickname, requestUri, emptySet()), new IdentityTrust(trust, comment));
}
return identityTrusts;
}
String requestUri = replies.get("RequestURI" + identityIndex);
byte trust = Byte.parseByte(replies.get("Value" + identityIndex));
String comment = replies.get("Comment" + identityIndex);
- identityTrusts.put(new Identity(identifier, nickname, requestUri), new IdentityTrust(trust, comment));
+ identityTrusts.put(new Identity(identifier, nickname, requestUri, emptySet()), new IdentityTrust(trust, comment));
}
return identityTrusts;
}
package net.pterodactylus.fcp.test;
+import net.pterodactylus.fcp.plugin.Identity;
import net.pterodactylus.fcp.plugin.OwnIdentity;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
+import java.util.Set;
+
public class IdentityMatchers {
public static Matcher<OwnIdentity> isOwnIdentity(Matcher<? super String> identifier, Matcher<? super String> nickname, Matcher<? super String> requestUri, Matcher<? super String> insertUri) {
};
}
+ public static Matcher<Identity> hasContexts(Matcher<? super Set<? super String>> contextsMatcher) {
+ return new TypeSafeDiagnosingMatcher<Identity>() {
+ @Override
+ protected boolean matchesSafely(Identity identity, Description mismatchDescription) {
+ if (!contextsMatcher.matches(identity.getContexts())) {
+ contextsMatcher.describeMismatch(identity.getContexts(), mismatchDescription);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("has contexts ").appendValue(contextsMatcher);
+ }
+ };
+ }
+
}