Changeset 54 for events/src
- Timestamp:
- Jul 23, 2025, 10:16:55 AM (7 weeks ago)
- Location:
- events/src
- Files:
-
- 53 edited
Legend:
- Unmodified
- Added
- Removed
-
events/src/main/java/geniusweb/actions/AbstractAction.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonAutoDetect; … … 9 11 public class AbstractAction implements Action { 10 12 11 private PartyId actor;13 private @NonNull final PartyId actor; 12 14 13 15 /** 14 16 * 15 * @param id the {@link PartyId} of the party executing the action. Usually16 * the negotiation system will check that parties only use their17 * own Id when doing actions.17 * @param actor the {@link PartyId} of the party executing the action. 18 * Usually the negotiation system will check that parties only 19 * use their own Id when doing actions. 18 20 */ 19 21 @JsonCreator 20 public AbstractAction(@JsonProperty("actor") PartyId id) { 21 this.actor = id; 22 public AbstractAction(@JsonProperty("actor") @NonNull PartyId actor) { 23 if (actor == null) 24 throw new IllegalArgumentException("actor is null"); 25 this.actor = actor; 22 26 } 23 27 24 28 @Override 25 public PartyId getActor() {29 public @NonNull PartyId getActor() { 26 30 return actor; 27 31 } -
events/src/main/java/geniusweb/actions/Accept.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 14 16 15 17 /** 16 * @param idthe accepting party.18 * @param actor the accepting party. 17 19 * @param bid the bid that was offered before (usually by some other Party ) 18 20 */ 19 21 @JsonCreator 20 public Accept(@JsonProperty("actor") PartyId id,21 @JsonProperty("bid") Bid bid) {22 super( id, bid);22 public Accept(@JsonProperty("actor") @NonNull PartyId actor, 23 @JsonProperty("bid") @NonNull Bid bid) { 24 super(actor, bid); 23 25 } 24 26 25 27 @Override 26 public String toString() { 27 return "Accept[" + getActor() + "," + getBid() + "]"; 28 public @NonNull String toString() { 29 return "Accept[" + getActor().toString() + "," + getBid().toString() 30 + "]"; 28 31 } 29 32 -
events/src/main/java/geniusweb/actions/Action.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonSubTypes; … … 27 29 * @return the {@link Id} of the actor of this action. 28 30 */ 31 @NonNull 29 32 PartyId getActor(); 30 33 -
events/src/main/java/geniusweb/actions/ActionWithBid.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 7 9 8 10 /** 9 * An {@link Action} containing a bid. Note that the presen se of a bid does not11 * An {@link Action} containing a bid. Note that the presence of a bid does not 10 12 * necessarily mean that an offer was placed for this bid. 11 13 * 12 14 */ 13 15 public abstract class ActionWithBid extends AbstractAction { 14 private Bid bid;16 private @NonNull Bid bid; 15 17 16 18 @JsonCreator 17 public ActionWithBid(@JsonProperty("actor") PartyId id, 18 @JsonProperty("bid") Bid bid) { 19 super(id); 19 public ActionWithBid(@JsonProperty("actor") @NonNull PartyId actor, 20 @JsonProperty("bid") @NonNull Bid bid) { 21 super(actor); 22 if (bid == null) 23 throw new IllegalArgumentException("bid is null"); 20 24 this.bid = bid; 21 25 } … … 25 29 * @return the {@link Bid} that this action is about. 26 30 */ 27 public Bid getBid() {31 public @NonNull Bid getBid() { 28 32 return bid; 29 33 } -
events/src/main/java/geniusweb/actions/Comparison.java
r52 r54 1 1 package geniusweb.actions; 2 2 3 import java.util.ArrayList; 3 4 import java.util.List; 5 6 import org.eclipse.jdt.annotation.NonNull; 4 7 5 8 import com.fasterxml.jackson.annotation.JsonCreator; … … 16 19 public class Comparison extends ActionWithBid { 17 20 18 private List<Bid> better;19 private List<Bid> worse;21 private final @NonNull List<@NonNull Bid> better = new ArrayList<>(); 22 private final @NonNull List<@NonNull Bid> worse = new ArrayList<>(); 20 23 21 24 /** 22 * @param idthe party id that made this comparison25 * @param actor the party id that made this comparison 23 26 * @param bid the bid that is compared wiht 24 27 * @param better list of bids that are better than bid … … 26 29 */ 27 30 @JsonCreator 28 public Comparison(@JsonProperty(" id") PartyId id,29 @JsonProperty("bid") Bid bid,30 @JsonProperty("better") List<Bid> better,31 @JsonProperty("worse") List<Bid> worse) {32 super( id, bid);31 public Comparison(@JsonProperty("actor") final @NonNull PartyId actor, 32 @JsonProperty("bid") final @NonNull Bid bid, 33 @JsonProperty("better") final @NonNull List<@NonNull Bid> better, 34 @JsonProperty("worse") final @NonNull List<@NonNull Bid> worse) { 35 super(actor, bid); 33 36 if (bid == null || better == null || worse == null) 34 37 throw new IllegalArgumentException( 35 38 "bid, better and worse must not be null"); 36 this.better = better;37 this.worse = worse;39 this.better.addAll(better); 40 this.worse.addAll(worse); 38 41 } 39 42 … … 42 45 * 43 46 */ 44 public List<Bid> getBetter() {47 public @NonNull List<@NonNull Bid> getBetter() { 45 48 return better; 46 49 } … … 51 54 */ 52 55 53 public List<Bid> getWorse() {56 public @NonNull List<@NonNull Bid> getWorse() { 54 57 return worse; 55 58 } 56 59 57 60 @Override 58 public String toString() { 59 return "Comparison[" + getActor() + "," + getBid() + ",better=" + better 60 + ",worse=" + worse + "]"; 61 public @NonNull String toString() { 62 return "Comparison[" + getActor().toString() + "," + getBid().toString() 63 + ",better=" + better.toString() + ",worse=" + worse.toString() 64 + "]"; 61 65 } 62 66 -
events/src/main/java/geniusweb/actions/ElicitComparison.java
r52 r54 4 4 import java.util.LinkedList; 5 5 import java.util.List; 6 7 import org.eclipse.jdt.annotation.NonNull; 6 8 7 9 import com.fasterxml.jackson.annotation.JsonCreator; … … 15 17 */ 16 18 public class ElicitComparison extends ActionWithBid { 17 private final List<Bid> options = new LinkedList<>();19 private final @NonNull List<@NonNull Bid> options = new LinkedList<>(); 18 20 19 21 /** 20 * @param idthe eliciting party.22 * @param actor the eliciting party. 21 23 * @param bid the bid to compare the options with 22 * @param opt s the available options that may be chosen from. Must not be24 * @param options the available options that may be chosen from. Must not be 23 25 * null and must have at least 2 options. 24 26 */ 25 27 @JsonCreator 26 public ElicitComparison(@JsonProperty("actor") PartyId id,27 @JsonProperty("bid") Bid bid,28 @JsonProperty("options") List<Bid> opts) {29 super( id, bid);28 public ElicitComparison(@JsonProperty("actor") @NonNull PartyId actor, 29 @JsonProperty("bid") @NonNull Bid bid, 30 @JsonProperty("options") @NonNull List<@NonNull Bid> options) { 31 super(actor, bid); 30 32 if (bid == null) 31 33 throw new IllegalArgumentException( 32 34 "Bid to compare with must not be null"); 33 if (opt s == null || opts.size() < 1) {35 if (options == null || options.size() < 1) { 34 36 throw new IllegalArgumentException( 35 37 "opts must not be null and have at least 1 option"); 36 38 } 37 this.options.addAll(opt s);39 this.options.addAll(options); 38 40 } 39 41 … … 42 44 * @return the list of {@link Bid}s to compare {@link #getBid()} with 43 45 */ 44 public List<Bid> getOptions() {46 public @NonNull List<@NonNull Bid> getOptions() { 45 47 return Collections.unmodifiableList(options); 46 48 } … … 73 75 @Override 74 76 public String toString() { 75 return "ElicitComparison[" + getActor() + "," + getBid() + "," + options76 + "]";77 return "ElicitComparison[" + getActor().toString() + "," 78 + getBid().toString() + "," + options.toString() + "]"; 77 79 78 80 } -
events/src/main/java/geniusweb/actions/EndNegotiation.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 11 13 12 14 @JsonCreator 13 public EndNegotiation(@JsonProperty("actor") PartyId id) {14 super( id);15 public EndNegotiation(@JsonProperty("actor") @NonNull PartyId actor) { 16 super(actor); 15 17 } 16 18 17 19 @Override 18 public String toString() {19 return "EndNegotiation[" + getActor() + "]";20 public @NonNull String toString() { 21 return "EndNegotiation[" + getActor().toString() + "]"; 20 22 } 21 23 -
events/src/main/java/geniusweb/actions/FileLocation.java
r52 r54 5 5 import java.nio.file.Paths; 6 6 import java.util.UUID; 7 8 import org.eclipse.jdt.annotation.NonNull; 7 9 8 10 import com.fasterxml.jackson.annotation.JsonCreator; … … 27 29 public class FileLocation { 28 30 29 @JsonValue 30 private final UUID name; 31 private final @NonNull UUID name; 31 32 32 private final static String TMP = System.getProperty("java.io.tmpdir"); 33 private final static String GENIUSWEB = "geniusweb"; 34 private final static Path rootpath = Paths.get(TMP, GENIUSWEB); 35 private final static File rootfolder = rootpath.toFile(); 33 private final static @NonNull String TMP = System 34 .getProperty("java.io.tmpdir"); 35 private final static @NonNull String GENIUSWEB = "geniusweb"; 36 private final static @NonNull Path rootpath = Paths.get(TMP, GENIUSWEB); 37 private final static @NonNull File rootfolder = rootpath.toFile(); 36 38 37 39 /** … … 39 41 * bad filenames like /.. or C:) Use {@link #FileLocation()} to 40 42 * create new FileLocation. That should ensure a new UUID that 41 * does not collide with existing ones. 43 * does not collide with existing ones. If null, a random UUID 44 * is created. 42 45 */ 43 46 @JsonCreator 44 47 public FileLocation(UUID name) { 48 if (name == null) 49 name = UUID.randomUUID(); 45 50 if (!rootfolder.exists()) { 46 51 rootfolder.mkdir(); 47 System.out 48 .println("created FileLocation root dir at " + rootfolder); 52 //System.out.println("created FileLocation root dir at " + rootfolder); 49 53 } 50 54 … … 52 56 } 53 57 54 /** 55 * Creates a new "random" FileLocation. 56 */ 57 public FileLocation() { 58 this(UUID.randomUUID()); 59 } 60 61 /** 62 * @return the UUID string 63 */ 64 public String getUUIDString() { 65 return name.toString(); 58 @JsonValue 59 public UUID getUUID() { 60 return name; 66 61 } 67 62 … … 74 69 * folder inside tomcat. 75 70 */ 76 public File getFile() {71 public @NonNull File getFile() { 77 72 return Paths.get(TMP, GENIUSWEB, name.toString()).toFile(); 78 73 } 79 74 80 75 @Override 81 public String toString() {82 return "FileLocation[" + name + "]";76 public @NonNull String toString() { 77 return "FileLocation[" + name.toString() + "]"; 83 78 } 84 79 -
events/src/main/java/geniusweb/actions/LearningDone.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 5 7 6 8 /** 7 * The party that sends this action indicates that it's finished with the learning. 9 * The party that sends this action indicates that it's finished with the 10 * learning. 8 11 * 9 12 */ 10 public class LearningDone extends AbstractAction { 13 public class LearningDone extends AbstractAction { 11 14 @JsonCreator 12 public LearningDone(@JsonProperty("actor") PartyId id) {13 super( id);15 public LearningDone(@JsonProperty("actor") @NonNull PartyId actor) { 16 super(actor); 14 17 } 15 18 16 19 @Override 17 public String toString() {18 return "LearningDone[" + getActor() + "]";20 public @NonNull String toString() { 21 return "LearningDone[" + getActor().toString() + "]"; 19 22 } 20 23 } -
events/src/main/java/geniusweb/actions/Offer.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 14 16 15 17 @JsonCreator 16 public Offer(@JsonProperty("actor") PartyId id,17 @JsonProperty("bid") Bid bid) {18 super( id, bid);18 public Offer(@JsonProperty("actor") @NonNull PartyId actor, 19 @JsonProperty("bid") @NonNull Bid bid) { 20 super(actor, bid); 19 21 } 20 22 21 23 @Override 22 public String toString() { 23 return "Offer[" + getActor() + "," + getBid() + "]"; 24 public @NonNull String toString() { 25 return "Offer[" + getActor().toString() + "," + getBid().toString() 26 + "]"; 24 27 } 25 28 -
events/src/main/java/geniusweb/actions/PartyId.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonValue; … … 14 16 */ 15 17 public final class PartyId { 16 @JsonValue 17 private final String name; 18 private final @NonNull String name; 18 19 19 20 /** … … 22 23 * letters, digits or _. 23 24 */ 24 public PartyId( String name) {25 public PartyId(@NonNull String name) { 25 26 if (name == null || !name.matches("[a-zA-Z]\\w*")) { 26 27 throw new IllegalArgumentException("name '" + name … … 30 31 } 31 32 32 public String getName() { 33 @JsonValue 34 public @NonNull String getName() { 33 35 return name; 34 36 } 35 37 36 38 @Override 37 public String toString() {39 public @NonNull String toString() { 38 40 return name; 39 41 } -
events/src/main/java/geniusweb/actions/Vote.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 11 13 */ 12 14 public class Vote extends ActionWithBid { 13 private final Integer minPower;14 private final Integer maxPower;15 private final @NonNull Integer minPower; 16 private final @NonNull Integer maxPower; 15 17 16 18 /** … … 26 28 */ 27 29 @JsonCreator 28 public Vote(@JsonProperty("actor") PartyId actor,29 @JsonProperty("bid") Bid bid,30 @JsonProperty("minPower") Integer minPower,31 @JsonProperty("maxPower") Integer maxPower) {30 public Vote(@JsonProperty("actor") @NonNull PartyId actor, 31 @JsonProperty("bid") @NonNull Bid bid, 32 @JsonProperty("minPower") @NonNull Integer minPower, 33 @JsonProperty("maxPower") @NonNull Integer maxPower) { 32 34 super(actor, bid); 33 35 this.minPower = minPower; … … 45 47 * valid. 46 48 */ 47 public Integer getMinPower() {49 public @NonNull Integer getMinPower() { 48 50 return minPower; 49 51 } … … 55 57 */ 56 58 57 public Integer getMaxPower() {59 public @NonNull Integer getMaxPower() { 58 60 return maxPower; 59 61 } 60 62 61 63 @Override 62 public String toString() {63 return "Vote[" + getActor() + "," + getBid() + "," + minPower+ ","64 + m axPower+ "]";64 public @NonNull String toString() { 65 return "Vote[" + getActor().toString() + "," + getBid().toString() + "," 66 + minPower.toString() + "," + maxPower.toString() + "]"; 65 67 } 66 68 -
events/src/main/java/geniusweb/actions/VoteWithValue.java
r52 r54 1 1 package geniusweb.actions; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 11 13 */ 12 14 public class VoteWithValue extends ActionWithBid { 13 private final Integer minPower;14 private final Integer maxPower;15 private final Integer value;15 private final @NonNull Integer minPower; 16 private final @NonNull Integer maxPower; 17 private final @NonNull Integer value; 16 18 17 19 /** 18 * @param idthe {@link PartyId} that does the action20 * @param actor the {@link PartyId} that does the action 19 21 * @param bid the bid that is voted on 20 22 * @param minPower the minimum power this bid must get in order for the vote … … 31 33 */ 32 34 @JsonCreator 33 public VoteWithValue(@JsonProperty("actor") PartyId id, 34 @JsonProperty("bid") Bid bid, 35 @JsonProperty("minPower") Integer minPower, 36 @JsonProperty("maxPower") Integer maxPower, 37 @JsonProperty("value") Integer value) { 38 super(id, bid); 39 this.minPower = minPower; 40 this.maxPower = maxPower; 41 this.value = value; 35 public VoteWithValue(@JsonProperty("actor") @NonNull PartyId actor, 36 @JsonProperty("bid") @NonNull Bid bid, 37 @JsonProperty("minPower") @NonNull Integer minPower, 38 @JsonProperty("maxPower") @NonNull Integer maxPower, 39 @JsonProperty("value") @NonNull Integer value) { 40 super(actor, bid); 42 41 if (value < 1 || value > 100) 43 42 throw new IllegalArgumentException( … … 48 47 "Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower"); 49 48 } 49 this.minPower = minPower; 50 this.maxPower = maxPower; 51 this.value = value; 52 50 53 } 51 54 … … 55 58 * valid. 56 59 */ 57 public Integer getMinPower() {60 public @NonNull Integer getMinPower() { 58 61 return minPower; 59 62 } … … 64 67 * valid. 65 68 */ 66 public Integer getMaxPower() {69 public @NonNull Integer getMaxPower() { 67 70 return maxPower; 68 71 } … … 74 77 * 75 78 */ 76 public Integer getValue() {79 public @NonNull Integer getValue() { 77 80 return value; 78 81 } 79 82 80 83 @Override 81 public String toString() { 82 return "VoteWithValue[" + getActor() + "," + getBid() + "," + minPower 83 + "," + maxPower + "," + value + "]"; 84 public @NonNull String toString() { 85 return "VoteWithValue[" + getActor().toString() + "," 86 + getBid().toString() + "," + minPower.toString() + "," 87 + maxPower.toString() + "," + value.toString() + "]"; 84 88 } 85 89 -
events/src/main/java/geniusweb/actions/Votes.java
r52 r54 6 6 import java.util.List; 7 7 import java.util.Set; 8 9 import org.eclipse.jdt.annotation.NonNull; 8 10 9 11 import com.fasterxml.jackson.annotation.JsonCreator; … … 17 19 */ 18 20 public class Votes extends AbstractAction { 19 private final Set<Vote> votes;21 private final @NonNull Set<@NonNull Vote> votes; 20 22 21 23 /** … … 28 30 */ 29 31 @JsonCreator 30 public Votes(@JsonProperty("actor") PartyId actor,31 @JsonProperty("votes") Set<Vote> votes) {32 public Votes(@JsonProperty("actor") @NonNull PartyId actor, 33 @JsonProperty("votes") @NonNull Set<@NonNull Vote> votes) { 32 34 super(actor); 33 35 this.votes = new HashSet<>(votes); … … 35 37 throw new NullPointerException("votes must be not null"); 36 38 37 List<Bid> votedBids = new LinkedList<>();38 for ( Vote vote : votes) {39 final @NonNull List<@NonNull Bid> votedBids = new LinkedList<>(); 40 for (final @NonNull Vote vote : votes) { 39 41 if (!vote.getActor().equals(actor)) 40 42 throw new IllegalArgumentException("All votes must come from " 41 + actor + " but found " + vote);43 + actor.toString() + " but found " + vote.toString()); 42 44 43 Bid bid = vote.getBid();45 final @NonNull Bid bid = vote.getBid(); 44 46 if (votedBids.contains(bid)) 45 47 throw new IllegalArgumentException( 46 "Votes contains multiple Vote's for " + bid );48 "Votes contains multiple Vote's for " + bid.toString()); 47 49 votedBids.add(bid); 48 50 } … … 58 60 * @return true iff this extends the otherVotes. 59 61 */ 60 public boolean isExtending( Votes otherVotes) {62 public boolean isExtending(@NonNull Votes otherVotes) { 61 63 if (!otherVotes.getActor().equals(getActor())) 62 64 return false; 63 for ( Vote vote : otherVotes.getVotes()) {64 Vote myvote = getVote(vote.getBid());65 for (final @NonNull Vote vote : otherVotes.getVotes()) { 66 final @NonNull Vote myvote = getVote(vote.getBid()); 65 67 if (myvote == null || myvote.getMinPower() > vote.getMinPower() 66 68 || myvote.getMaxPower() < vote.getMaxPower()) … … 76 78 */ 77 79 public Vote getVote(Bid bid) { 78 for ( Vote vote : votes) {80 for (final @NonNull Vote vote : votes) { 79 81 if (vote.getBid().equals(bid)) 80 82 return vote; … … 83 85 } 84 86 85 public Set<Vote> getVotes() {87 public @NonNull Set<@NonNull Vote> getVotes() { 86 88 return Collections.unmodifiableSet(votes); 87 89 } … … 113 115 114 116 @Override 115 public String toString() {116 return "Votes[" + getActor() + "," + votes+ "]";117 public @NonNull String toString() { 118 return "Votes[" + getActor().toString() + "," + votes.toString() + "]"; 117 119 } 118 120 } -
events/src/main/java/geniusweb/actions/VotesWithValue.java
r52 r54 2 2 3 3 import java.util.Collections; 4 import java.util.HashSet; 4 5 import java.util.Map; 5 6 import java.util.Map.Entry; … … 7 8 import java.util.Set; 8 9 import java.util.stream.Collectors; 10 11 import org.eclipse.jdt.annotation.NonNull; 9 12 10 13 import com.fasterxml.jackson.annotation.JsonCreator; … … 18 21 */ 19 22 public class VotesWithValue extends AbstractAction { 20 private final Set<VoteWithValue> votes;23 private final @NonNull Set<@NonNull VoteWithValue> votes = new HashSet<>(); 21 24 22 25 /** 23 26 * 24 * @param idparty id27 * @param actor party id 25 28 * @param votes the {@link Vote}s that the party can agree on, if the 26 29 * condition of the Vote holds. Every {@link Vote#getActor()} … … 28 31 */ 29 32 @JsonCreator 30 public VotesWithValue(@JsonProperty("actor") PartyId id, 31 @JsonProperty("votes") Set<VoteWithValue> votes) { 32 super(id); 33 this.votes = votes; 33 public VotesWithValue(@JsonProperty("actor") @NonNull PartyId actor, 34 @JsonProperty("votes") @NonNull Set<@NonNull VoteWithValue> votes) { 35 super(actor); 34 36 if (votes == null) 35 37 throw new NullPointerException("votes must be not null"); 36 for ( VoteWithValue vote : votes) {37 if (!vote.getActor().equals( id)) {38 for (final @NonNull VoteWithValue vote : votes) { 39 if (!vote.getActor().equals(actor)) { 38 40 throw new IllegalArgumentException("All votes must come from " 39 + id + " but found " + vote);41 + actor.toString() + " but found " + vote.toString()); 40 42 } 41 43 } 44 /*#PY 45 * if sum( [ v.getValue() for v in votes] ) != 100: 46 * raise ValueError("Sum of the placed votes must be 100") 47 */ 42 48 if (votes.stream().map(v -> v.getValue()).reduce(0, 43 49 Integer::sum) != 100) … … 45 51 "Sum of the placed votes must be 100"); 46 52 // check for duplicate Vote's, possibly with different powers 47 Map<Bid, Long> counts = votes.stream().map(vote -> vote.getBid()) 48 .collect(Collectors.groupingBy(bid -> bid, 49 Collectors.counting())); 53 /*#PY 54 * from collections import Counter 55 * counts = Counter( [ vote.getBid() for vote in votes ] ) 56 */ 57 final @NonNull Map<@NonNull Bid, @NonNull Long> counts = votes.stream() 58 .map(vote -> vote.getBid()).collect(Collectors 59 .groupingBy(bid -> bid, Collectors.counting())); 60 /*#PY 61 * from typing import Optional 62 * nonunique:Optional[Bid] = next( iter([(bid,cnt) for (bid,cnt) in counts.items() if cnt>1]), None) 63 */ 50 64 Optional<Entry<Bid, Long>> nonunique = counts.entrySet().stream() 51 65 .filter(entry -> entry.getValue() > 1).findAny(); … … 53 67 throw new IllegalArgumentException( 54 68 "Votes contains multiple Vote's for " 55 + nonunique.get().getKey()); 69 + nonunique.get().getKey().toString()); 70 this.votes.addAll(votes); 56 71 } 57 72 … … 65 80 * @return true iff this extends the otherVotes. 66 81 */ 67 public boolean isExtending( VotesWithValue otherVotes) {82 public boolean isExtending(@NonNull VotesWithValue otherVotes) { 68 83 if (!otherVotes.getActor().equals(getActor())) 69 84 return false; 70 for ( VoteWithValue vote : otherVotes.getVotes()) {71 VoteWithValue myvote = getVote(vote.getBid());85 for (final @NonNull VoteWithValue vote : otherVotes.getVotes()) { 86 final @NonNull VoteWithValue myvote = getVote(vote.getBid()); 72 87 if (myvote == null || myvote.getMinPower() > vote.getMinPower() 73 88 || myvote.getMaxPower() < vote.getMaxPower()) … … 82 97 * @return myvote for bid, or null if no vote for that bid; 83 98 */ 84 public VoteWithValue getVote( Bid bid) {85 for ( VoteWithValue vote : votes) {99 public VoteWithValue getVote(@NonNull Bid bid) { 100 for (final @NonNull VoteWithValue vote : votes) { 86 101 if (vote.getBid().equals(bid)) 87 102 return vote; … … 90 105 } 91 106 92 public Set<VoteWithValue> getVotes() {107 public @NonNull Set<@NonNull VoteWithValue> getVotes() { 93 108 return Collections.unmodifiableSet(votes); 94 109 } … … 120 135 121 136 @Override 122 public String toString() { 123 return "VotesWithValue[" + getActor() + "," + votes + "]"; 137 public @NonNull String toString() { 138 return "VotesWithValue[" + getActor().toString() + "," 139 + votes.toString() + "]"; 124 140 } 125 141 } -
events/src/main/java/geniusweb/events/AbstractEvent.java
r52 r54 1 1 package geniusweb.events; 2 3 import org.eclipse.jdt.annotation.NonNull; 4 5 import com.fasterxml.jackson.annotation.JsonCreator; 6 import com.fasterxml.jackson.annotation.JsonProperty; 2 7 3 8 public abstract class AbstractEvent implements NegotiationEvent { 4 9 5 private final Long time; 10 private final @NonNull Long time; 11 12 /** 13 * @param now the current time to use. see 14 * {@link System#currentTimeMillis()}. If null, the 15 * {@link System#currentTimeMillis()} is used. 16 */ 17 @JsonCreator 18 public AbstractEvent(@JsonProperty("time") @NonNull Long time) { 19 if (time == null) 20 time = System.currentTimeMillis(); 21 if (time < 0) 22 throw new IllegalArgumentException( 23 "time must be non-null and positive"); 24 this.time = time; 25 } 6 26 7 27 @Override 8 public Long getTime() {28 public @NonNull Long getTime() { 9 29 return time; 10 30 } 11 31 12 public AbstractEvent() {13 this.time = System.currentTimeMillis();14 }15 16 /**17 * @param now the current time to use. see {@link System#currentTimeMillis()}.18 */19 public AbstractEvent(Long now) {20 if (now == null || now < 0) {21 throw new IllegalArgumentException("time must be non-null and positive");22 }23 this.time = now;24 }25 26 32 @Override 27 public String toString() {28 return this.getClass().getSimpleName() + "[" + time + "]";33 public @NonNull String toString() { 34 return this.getClass().getSimpleName() + "[" + time.toString() + "]"; 29 35 } 30 36 -
events/src/main/java/geniusweb/events/ActionEvent.java
r52 r54 1 1 package geniusweb.events; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 12 14 public class ActionEvent extends AbstractEvent { 13 15 14 private final Action action;16 private final @NonNull Action action; 15 17 16 18 /** … … 21 23 */ 22 24 @JsonCreator 23 public ActionEvent(@JsonProperty("action") Action action,24 @JsonProperty("time") Long time) {25 public ActionEvent(@JsonProperty("action") @NonNull Action action, 26 @JsonProperty("time") @NonNull Long time) { 25 27 super(time); 26 if (action == null) {28 if (action == null) 27 29 throw new IllegalArgumentException("Action must not be null"); 28 }29 30 this.action = action; 30 31 } … … 34 35 * @return action done by some party in the system. 35 36 */ 36 public Action getAction() {37 public @NonNull Action getAction() { 37 38 return action; 38 39 } 39 40 40 41 @Override 41 public String toString() {42 return this.getClass().getSimpleName() + "[" + getTime() + "," + action43 + " ]";42 public @NonNull String toString() { 43 return this.getClass().getSimpleName() + "[" + getTime().toString() 44 + "," + action.toString() + "]"; 44 45 } 45 46 -
events/src/main/java/geniusweb/events/CurrentState.java
r52 r54 1 1 package geniusweb.events; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 /** … … 20 22 */ 21 23 public abstract class CurrentState extends ProtocolEvent { 22 public CurrentState() {23 }24 24 25 public CurrentState( Long now) {25 public CurrentState(@NonNull Long now) { 26 26 super(now); 27 27 } -
events/src/main/java/geniusweb/events/NegotiationEvent.java
r52 r54 1 1 package geniusweb.events; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonAutoDetect; … … 33 35 * accuracy. 34 36 */ 37 @NonNull 35 38 Long getTime(); 36 39 -
events/src/main/java/geniusweb/events/ProtocolEvent.java
r52 r54 1 1 package geniusweb.events; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 /** … … 5 7 */ 6 8 public abstract class ProtocolEvent extends AbstractEvent { 7 public ProtocolEvent() {8 9 9 } 10 11 public ProtocolEvent(Long now) { 10 public ProtocolEvent(@NonNull Long now) { 12 11 super(now); 13 12 } -
events/src/main/java/geniusweb/events/SessionStarted.java
r52 r54 2 2 3 3 import java.util.List; 4 5 import org.eclipse.jdt.annotation.NonNull; 4 6 5 7 import com.fasterxml.jackson.annotation.JsonCreator; … … 9 11 10 12 public class SessionStarted extends ProtocolEvent { 11 private Long sessionNumber;12 private List<PartyId> parties;13 private @NonNull Long sessionNumber; 14 private @NonNull List<@NonNull PartyId> parties; 13 15 14 16 @JsonCreator 15 public SessionStarted(@JsonProperty("sessionNumber") Long sessionnr, 16 @JsonProperty("parties") List<PartyId> parties, 17 public SessionStarted( 18 @JsonProperty("sessionNumber") @NonNull Long sessionNumber, 19 @JsonProperty("parties") @NonNull List<@NonNull PartyId> parties, 17 20 @JsonProperty("time") Long time) { 18 21 super(time); 19 this.sessionNumber = session nr;22 this.sessionNumber = sessionNumber; 20 23 this.parties = parties; 21 24 } 22 25 23 public List<PartyId> getParties() {26 public @NonNull List<@NonNull PartyId> getParties() { 24 27 return parties; 25 28 } 26 29 27 public Long getSessionNumber() {30 public @NonNull Long getSessionNumber() { 28 31 return sessionNumber; 29 32 } … … 62 65 63 66 @Override 64 public String toString() {65 return "SessionStarted[" + sessionNumber + "," + parties+ ","66 + getTime() + "]";67 public @NonNull String toString() { 68 return "SessionStarted[" + sessionNumber.toString() + "," 69 + parties.toString() + "," + getTime().toString() + "]"; 67 70 } 68 71 -
events/src/main/java/geniusweb/events/TournamentStarted.java
r52 r54 1 1 package geniusweb.events; 2 2 3 import org.eclipse.jdt.annotation.NonNull; 4 5 import com.fasterxml.jackson.annotation.JsonCreator; 6 import com.fasterxml.jackson.annotation.JsonProperty; 7 3 8 public class TournamentStarted extends ProtocolEvent { 4 private Long numberOfSessions; 5 6 @SuppressWarnings("unused") // deserialization 7 private TournamentStarted() { 8 numberOfSessions = null; 9 } 9 private final @NonNull Long numberOfSessions; 10 10 11 11 /** 12 12 * 13 13 * @param numberOfSessions the total number of sessions in the tournament 14 * @param time the current timestamp. Null is current time. 14 15 */ 15 public TournamentStarted(Long numberOfSessions) { 16 @JsonCreator 17 public TournamentStarted( 18 @JsonProperty("numberOfSessions") @NonNull Long numberOfSessions, 19 @JsonProperty("time") Long time) { 20 super(time); 16 21 this.numberOfSessions = numberOfSessions; 17 22 } 18 23 19 /** 20 * 21 * @param numberOfSessions the total number of sessions in the tournament 22 * @param now the current timestamp 23 */ 24 public TournamentStarted(Long numberOfSessions, Long now) { 25 super(now); 26 this.numberOfSessions = numberOfSessions; 27 } 28 29 public Long getNumberOfSessions() { 24 public @NonNull Long getNumberOfSessions() { 30 25 return numberOfSessions; 31 26 } 32 27 33 28 @Override 34 public String toString() { 35 return "TournamentStarted[" + getTime() + "," + numberOfSessions + "]"; 29 public @NonNull String toString() { 30 return "TournamentStarted[" + getTime().toString() + "," 31 + numberOfSessions.toString() + "]"; 36 32 } 37 33 -
events/src/main/java/geniusweb/inform/ActionDone.java
r52 r54 1 1 package geniusweb.inform; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 11 13 public class ActionDone implements Inform { 12 14 13 private final Action action;15 private final @NonNull Action action; 14 16 15 17 @JsonCreator 16 public ActionDone(@JsonProperty("action") Action action) { 18 public ActionDone(@JsonProperty("action") @NonNull Action action) { 19 if (action == null) 20 throw new IllegalArgumentException("action must not be null"); 17 21 this.action = action; 18 22 } 19 23 20 public Action getAction() {24 public @NonNull Action getAction() { 21 25 return action; 22 26 } 23 27 24 28 @Override 25 public String toString() {26 return "ActionDone[" + action + "]";29 public @NonNull String toString() { 30 return "ActionDone[" + action.toString() + "]"; 27 31 } 28 32 -
events/src/main/java/geniusweb/inform/Agreements.java
r52 r54 6 6 import java.util.Set; 7 7 import java.util.stream.Collectors; 8 9 import org.eclipse.jdt.annotation.NonNull; 8 10 9 11 import com.fasterxml.jackson.annotation.JsonAutoDetect; … … 22 24 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) 23 25 public class Agreements { 24 @JsonValue 25 private final Map<PartyId, Bid> agreements; 26 private final @NonNull Map<@NonNull PartyId, @NonNull Bid> agreements = new HashMap<>(); 26 27 27 public Agreements() { 28 this.agreements = Collections.emptyMap(); 29 } 30 28 /** 29 * This constructor also replaces the overloaded empty constructor. Use this 30 * constructor with empty map to create non-arg Agreements. 31 * 32 * @param agreements set of partyid-bid pairs. with the bids that each party 33 * agreed on. 34 */ 31 35 @JsonCreator 32 public Agreements(Map<PartyId, Bid> agrees) { 33 this.agreements = agrees; 36 public Agreements(@NonNull Map<@NonNull PartyId, @NonNull Bid> agreements) { 37 if (agreements == null) 38 throw new NullPointerException("agrees must not be null"); 39 this.agreements.putAll(agreements); 34 40 } 35 41 36 42 /** 43 * This replaces the overloaded constructor with same arguments 44 * 37 45 * @param bid a bid that all parties agreed on 38 46 * @param parties the {@link PartyId}s of the agreeing parties 39 47 */ 40 public Agreements(Bid bid, Set<PartyId> parties) { 41 this(parties.stream() 48 public static Agreements create(@NonNull Bid bid, 49 @NonNull Set<PartyId> parties) { 50 //#PY return Agreements( { pid:bid for pid in parties } ) 51 return new Agreements(parties.stream() 42 52 .collect(Collectors.toMap(pid -> pid, pid -> bid))); 43 53 } … … 49 59 * agreement. 50 60 */ 51 public Agreements with(Agreements other) {52 Map<PartyId, Bid> newagrees = new HashMap<>(agreements);53 for ( PartyId pid : other.agreements.keySet()) {61 public @NonNull Agreements with(@NonNull Agreements other) { 62 final @NonNull Map<PartyId, Bid> newagrees = new HashMap<>(agreements); 63 for (final @NonNull PartyId pid : other.agreements.keySet()) { 54 64 if (newagrees.containsKey(pid)) 55 65 throw new IllegalArgumentException( 56 "party " + pid + " already has agreement");66 "party " + pid.toString() + " already has agreement"); 57 67 newagrees.put(pid, other.agreements.get(pid)); 58 68 } … … 60 70 } 61 71 72 @JsonValue 62 73 /** 74 * This replaces the previous getMap() method. 75 * 63 76 * @return actual agreemenets contained here 64 77 */ 65 public Map<PartyId, Bid> getMap() {78 public @NonNull Map<@NonNull PartyId, @NonNull Bid> getAgreements() { 66 79 return Collections.unmodifiableMap(agreements); 67 80 } 68 81 69 82 @Override 70 public String toString() {71 return "Agreements" + agreements ;83 public @NonNull String toString() { 84 return "Agreements" + agreements.toString(); 72 85 } 73 86 -
events/src/main/java/geniusweb/inform/Finished.java
r52 r54 1 1 package geniusweb.inform; 2 3 import org.eclipse.jdt.annotation.NonNull; 2 4 3 5 import com.fasterxml.jackson.annotation.JsonCreator; … … 10 12 */ 11 13 public class Finished implements Inform { 12 private final Agreements agreements;14 private final @NonNull Agreements agreements; 13 15 14 16 /** … … 18 20 */ 19 21 @JsonCreator 20 public Finished(@JsonProperty("agreements") Agreements agreements) { 22 public Finished( 23 @JsonProperty("agreements") @NonNull Agreements agreements) { 21 24 if (agreements == null) 22 25 throw new NullPointerException("Agreements can't be null"); … … 24 27 } 25 28 26 public Agreements getAgreements() {29 public @NonNull Agreements getAgreements() { 27 30 return agreements; 28 31 } … … 55 58 56 59 @Override 57 public String toString() {58 return "Finished[" + agreements + "]";60 public @NonNull String toString() { 61 return "Finished[" + agreements.toString() + "]"; 59 62 } 60 63 } -
events/src/main/java/geniusweb/inform/OptIn.java
r52 r54 4 4 import java.util.LinkedList; 5 5 import java.util.List; 6 7 import org.eclipse.jdt.annotation.NonNull; 6 8 7 9 import com.fasterxml.jackson.annotation.JsonCreator; … … 16 18 public class OptIn implements Inform { 17 19 18 private final List<Votes> votes;20 private final @NonNull List<@NonNull Votes> votes; 19 21 20 22 /** … … 22 24 */ 23 25 @JsonCreator 24 public OptIn(@JsonProperty("votes") List<Votes> votes) { 25 this.votes = votes; 26 public OptIn(@JsonProperty("votes") @NonNull List<@NonNull Votes> votes) { 27 if (votes == null) 28 throw new IllegalArgumentException("votes must be not null"); 26 29 27 List<PartyId> partyVotes = new LinkedList<>(); 28 for (Votes vote : votes) { 29 PartyId party = vote.getActor(); 30 // check for duplicate votes 31 final @NonNull List<@NonNull PartyId> partyVotes = new LinkedList<>(); 32 for (final @NonNull Votes vote : votes) { 33 final @NonNull PartyId party = vote.getActor(); 30 34 if (partyVotes.contains(party)) 31 35 throw new IllegalArgumentException( … … 33 37 partyVotes.add(party); 34 38 } 39 this.votes = votes; 35 40 } 36 41 … … 38 43 * @return list of votes that can be opted in to 39 44 */ 40 public List<Votes> getVotes() {45 public @NonNull List<@NonNull Votes> getVotes() { 41 46 return Collections.unmodifiableList(votes); 42 47 } … … 68 73 69 74 @Override 70 public String toString() {71 return "OptIn[" + votes + "]";75 public @NonNull String toString() { 76 return "OptIn[" + votes.toString() + "]"; 72 77 } 73 78 -
events/src/main/java/geniusweb/inform/OptInWithValue.java
r52 r54 7 7 import java.util.Optional; 8 8 import java.util.stream.Collectors; 9 10 import org.eclipse.jdt.annotation.NonNull; 9 11 10 12 import com.fasterxml.jackson.annotation.JsonCreator; … … 19 21 public class OptInWithValue implements Inform { 20 22 21 private final List<VotesWithValue> votes;23 private final @NonNull List<@NonNull VotesWithValue> votes; 22 24 23 25 /** … … 25 27 */ 26 28 @JsonCreator 27 public OptInWithValue( @JsonProperty("votes") List<VotesWithValue> votes) {28 this.votes = votes;29 public OptInWithValue( 30 @JsonProperty("votes") @NonNull List<@NonNull VotesWithValue> votes) { 29 31 30 Map<PartyId, Long> counts = votes.stream().map(vote -> vote.getActor()) 31 .collect(Collectors.groupingBy(actor -> actor, 32 Collectors.counting())); 33 Optional<Entry<PartyId, Long>> nonunique = counts.entrySet().stream() 34 .filter(entry -> entry.getValue() > 1).findAny(); 32 /*#PY 33 * from collections import Counter 34 * counts = Counter( [ vote.getActor() for vote in votes ] ) 35 */ 36 final @NonNull Map<@NonNull PartyId, @NonNull Long> counts = votes 37 .stream().map(vote -> vote.getActor()).collect(Collectors 38 .groupingBy(actor -> actor, Collectors.counting())); 39 /*#PY 40 * from typing import Optional, Tuple 41 * nonunique:Optional[Tuple] = next( iter([(pid,cnt) for (pid,cnt) in counts.items() if cnt>1]), None) 42 */ 43 final @NonNull Optional<Entry<PartyId, Long>> nonunique = counts 44 .entrySet().stream().filter(entry -> entry.getValue() > 1) 45 .findAny(); 35 46 if (nonunique.isPresent()) 36 47 throw new IllegalArgumentException( 37 48 "OptIn contains multiple Votes for party " 38 49 + nonunique.get().getKey()); 39 50 this.votes = votes; 40 51 } 41 52 … … 43 54 * @return list of votes that can be opted in to 44 55 */ 45 public List<VotesWithValue> getVotes() {56 public @NonNull List<@NonNull VotesWithValue> getVotes() { 46 57 return Collections.unmodifiableList(votes); 47 58 } … … 73 84 74 85 @Override 75 public String toString() {76 return "OptInWithValue[" + votes + "]";86 public @NonNull String toString() { 87 return "OptInWithValue[" + votes.toString() + "]"; 77 88 } 78 89 -
events/src/main/java/geniusweb/inform/Settings.java
r52 r54 3 3 import java.util.HashMap; 4 4 import java.util.Map; 5 6 import org.eclipse.jdt.annotation.NonNull; 5 7 6 8 import com.fasterxml.jackson.annotation.JsonCreator; … … 19 21 */ 20 22 public class Settings implements Inform { 21 private ProfileRef profile;22 private ProtocolRef protocol;23 private Progress progress;24 private PartyId id;25 private Parameters parameters;23 private @NonNull ProfileRef profile; 24 private @NonNull ProtocolRef protocol; 25 private @NonNull Progress progress; 26 private @NonNull PartyId id; 27 private @NonNull Parameters parameters; 26 28 27 29 /** … … 39 41 */ 40 42 @JsonCreator 41 public Settings(@JsonProperty("id") PartyId id,42 @JsonProperty("profile") ProfileRef profile,43 @JsonProperty("protocol") ProtocolRef protocol,44 @JsonProperty("progress") Progress progress,45 @JsonProperty("parameters") Parameters parameters) {43 public Settings(@JsonProperty("id") @NonNull PartyId id, 44 @JsonProperty("profile") @NonNull ProfileRef profile, 45 @JsonProperty("protocol") @NonNull ProtocolRef protocol, 46 @JsonProperty("progress") @NonNull Progress progress, 47 @JsonProperty("parameters") @NonNull Parameters parameters) { 46 48 if (profile == null || protocol == null || progress == null 47 || parameters == null ) {49 || parameters == null || id == null) { 48 50 throw new IllegalArgumentException( 49 " party, profile, protocol, parameters and progress must be not null.");51 "id, party, profile, protocol, parameters and progress must be not null."); 50 52 } 51 53 this.profile = profile; … … 60 62 * @return the profile used for this party in this session 61 63 */ 62 public ProfileRef getProfile() {64 public @NonNull ProfileRef getProfile() { 63 65 return profile; 64 66 } 65 67 66 public ProtocolRef getProtocol() {68 public @NonNull ProtocolRef getProtocol() { 67 69 return protocol; 68 70 } … … 72 74 * @return the {@link Progress} object used for this session 73 75 */ 74 public Progress getProgress() {76 public @NonNull Progress getProgress() { 75 77 return progress; 76 78 } … … 79 81 * @return the party ID of this party 80 82 */ 81 public PartyId getID() {83 public @NonNull PartyId getID() { 82 84 return id; 83 85 } … … 88 90 * parameters that can be used by the party. 89 91 */ 90 public Parameters getParameters() {92 public @NonNull Parameters getParameters() { 91 93 return parameters; 92 94 } 93 95 94 96 @Override 95 public String toString() { 96 return "Settings[" + id + "," + profile + "," + protocol + "," 97 + progress + "," + parameters + "]"; 97 public @NonNull String toString() { 98 return "Settings[" + id.toString() + "," + profile.toString() + "," 99 + protocol.toString() + "," + progress.toString() + "," 100 + parameters.toString() + "]"; 98 101 } 99 102 -
events/src/main/java/geniusweb/inform/Voting.java
r52 r54 1 1 package geniusweb.inform; 2 2 3 import java.util.ArrayList; 3 4 import java.util.Collections; 5 import java.util.HashMap; 4 6 import java.util.List; 5 7 import java.util.Map; 8 9 import org.eclipse.jdt.annotation.NonNull; 6 10 7 11 import com.fasterxml.jackson.annotation.JsonCreator; … … 16 20 public class Voting implements Inform { 17 21 18 private final List<Offer> offers;19 private final Map<PartyId, Integer> powers;22 private final @NonNull List<@NonNull Offer> offers = new ArrayList<>(); 23 private final @NonNull Map<@NonNull PartyId, @NonNull Integer> powers = new HashMap<>(); 20 24 21 25 @JsonCreator 22 public Voting(@JsonProperty("offers") List<Offer> offers, 23 @JsonProperty("powers") Map<PartyId, Integer> powers) { 24 this.offers = offers; 25 this.powers = powers; 26 public Voting(@JsonProperty("offers") @NonNull List<@NonNull Offer> offers, 27 @JsonProperty("powers") @NonNull Map<@NonNull PartyId, @NonNull Integer> powers) { 28 if (offers == null || offers.contains(null)) 29 throw new IllegalArgumentException( 30 "offers must be not null and contain no null"); 31 if (powers == null || powers.containsKey(null) 32 || powers.containsValue(null)) 33 throw new IllegalArgumentException( 34 "powers must be not null and contain no null"); 35 this.offers.addAll(offers); 36 this.powers.putAll(powers); 26 37 } 27 38 … … 29 40 * @return list of offers to be voted on 30 41 */ 31 public List<Offer> getOffers() {42 public @NonNull List<@NonNull Offer> getOffers() { 32 43 return Collections.unmodifiableList(offers); 33 }34 35 @Deprecated36 public List<Offer> getBids() {37 return getOffers();38 44 } 39 45 … … 44 50 * agreement or walked away. 45 51 */ 46 public Map<PartyId,Integer> getPowers() {52 public @NonNull Map<@NonNull PartyId, @NonNull Integer> getPowers() { 47 53 return Collections.unmodifiableMap(powers); 48 54 } … … 80 86 81 87 @Override 82 public String toString() {83 return "Voting[" + offers + "," + powers+ "]";88 public @NonNull String toString() { 89 return "Voting[" + offers.toString() + "," + powers.toString() + "]"; 84 90 } 85 91 -
events/src/test/java/geniusweb/actions/AcceptTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 10 11 import java.util.Map; 11 12 12 import org. junit.Before;13 import org.eclipse.jdt.annotation.NonNull; 13 14 import org.junit.Test; 15 import org.junit.internal.runners.JUnit4ClassRunner; 16 import org.junit.runner.RunWith; 14 17 15 18 import com.fasterxml.jackson.core.JsonProcessingException; … … 22 25 import tudelft.utilities.junit.GeneralTests; 23 26 27 @RunWith(JUnit4ClassRunner.class) 24 28 public class AcceptTest extends GeneralTests<Accept> { 25 private final ObjectMapper jackson = new ObjectMapper();29 private final static @NonNull ObjectMapper jackson = new ObjectMapper(); 26 30 27 private static final PartyId id = new PartyId("party1");28 private static final PartyId id2 = new PartyId("party2");29 private final static Map<String, Value> issuevalues = new HashMap<String, Value>();30 private final static Map<String, Value> issuevaluesb = new HashMap<String, Value>();31 private static final @NonNull PartyId id = new PartyId("party1"); 32 private static final @NonNull PartyId id2 = new PartyId("party2"); 33 private final static @NonNull Map<String, Value> issuevalues = new HashMap<String, Value>(); 34 private final static @NonNull Map<String, Value> issuevaluesb = new HashMap<String, Value>(); 31 35 private static Bid bid; 32 36 private static Bid bidb; 33 private final static String ISSUE1 = "issue1";34 private final static Value VALUE1 = new DiscreteValue("value1");35 private final static String ISSUE2 = "issue2";36 private final static Value VALUE2 = new NumberValue("10");37 private final static @NonNull String ISSUE1 = "issue1"; 38 private final static @NonNull Value VALUE1 = new DiscreteValue("value1"); 39 private final static @NonNull String ISSUE2 = "issue2"; 40 private final static @NonNull Value VALUE2 = new NumberValue("10"); 37 41 // issue 2 is NUMBER and thus serializes with leading '=' 38 private final String acceptstring = "{\"Accept\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}"; 42 private final @NonNull String acceptstring = "{\"Accept\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}"; 43 44 private static final @NonNull String bidpat = "\\{((.*issue2.*10)|(.*issue1.*value1.*),?)+\\}"; 45 private static final @NonNull String bidbpat = "\\{((.*issue2.*10)|(.*issue1.*10.*),?)+\\}"; 46 47 private final @NonNull String acceptstringpat = ".*Accept.*actor.*party1.*bid.*issuevalues.*((" 48 + bidpat + "|" + bidbpat + "),?)+.*"; 39 49 40 50 private static Accept accept, accept1, accept2, acceptb; … … 59 69 @Override 60 70 public List<List<Accept>> getGeneralTestData() { 61 List<List<Accept>> list= new LinkedList<>();62 list.add(Arrays.asList(accept, accept1));63 list.add(Arrays.asList(accept2));64 list.add(Arrays.asList(acceptb));65 return list;71 final @NonNull List<@NonNull List<@NonNull Accept>> accepts = new LinkedList<>(); 72 accepts.add(Arrays.asList(accept, accept1)); 73 accepts.add(Arrays.asList(accept2)); 74 accepts.add(Arrays.asList(acceptb)); 75 return accepts; 66 76 } 67 77 68 78 @Override 69 79 public List<String> getGeneralTestStrings() { 70 return Arrays.asList("Accept.*" + id + ".*]", "Accept.*" + id2 + ".*]", 71 "Accept.*" + id + ".*]"); 72 } 73 74 @Before 75 public void before() { 76 80 return Arrays.asList("Accept.*" + id.toString() + ".*]", 81 "Accept.*" + id2.toString() + ".*]", 82 "Accept.*" + id.toString() + ".*]"); 77 83 } 78 84 79 85 @Test 80 86 public void serializeAcceptTest() throws JsonProcessingException { 81 System.out.println(jackson.writeValueAsString(accept));82 assert Equals(acceptstring, jackson.writeValueAsString(accept));87 //System.out.println(jackson.writeValueAsString(accept)); 88 assertTrue(jackson.writeValueAsString(accept).matches(acceptstringpat)); 83 89 } 84 90 85 91 @Test 86 92 public void deserializeAcceptTest() throws IOException { 87 Action act = jackson.readValue(acceptstring, Action.class); 93 final @NonNull Action act = jackson.readValue(acceptstring, 94 Action.class); 88 95 assertEquals(accept, act); 89 96 } -
events/src/test/java/geniusweb/actions/ComparisonTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 10 11 import java.util.Map; 11 12 13 import org.eclipse.jdt.annotation.NonNull; 12 14 import org.junit.Before; 13 15 import org.junit.Test; 16 import org.junit.internal.runners.JUnit4ClassRunner; 17 import org.junit.runner.RunWith; 14 18 15 19 import com.fasterxml.jackson.core.JsonProcessingException; … … 22 26 import tudelft.utilities.junit.GeneralTests; 23 27 28 @RunWith(JUnit4ClassRunner.class) 24 29 public class ComparisonTest extends GeneralTests<Comparison> { 25 private final ObjectMapper jackson = new ObjectMapper();30 private final static @NonNull ObjectMapper jackson = new ObjectMapper(); 26 31 27 private static final PartyId id = new PartyId("party1");28 private static final PartyId id2 = new PartyId("party2");29 private final static Map<String, Value> issuevalues = new HashMap<String, Value>();30 private final static Map<String, Value> issuevaluesb = new HashMap<String, Value>();32 private static final @NonNull PartyId id = new PartyId("party1"); 33 private static final @NonNull PartyId id2 = new PartyId("party2"); 34 private final static @NonNull Map<String, Value> issuevalues = new HashMap<String, Value>(); 35 private final static @NonNull Map<String, Value> issuevaluesb = new HashMap<String, Value>(); 31 36 private static Bid bid; 32 37 private static Bid bidb; 33 private final static String ISSUE1 = "issue1";34 private final static Value VALUE1 = new DiscreteValue("value1");35 private final static String ISSUE2 = "issue2";36 private final static Value VALUE2 = new NumberValue("10");38 private final static @NonNull String ISSUE1 = "issue1"; 39 private final static @NonNull Value VALUE1 = new DiscreteValue("value1"); 40 private final static @NonNull String ISSUE2 = "issue2"; 41 private final static @NonNull Value VALUE2 = new NumberValue("10"); 37 42 // issue 2 is NUMBER and thus serializes with leading '=' 38 private final String acceptstring = "{\"Comparison\":{\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"better\":[],\"worse\":[],\"actor\":\"party1\"}}"; 43 private final static @NonNull String acceptstring = "{\"Comparison\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"better\":[],\"worse\":[]}}"; 44 45 private static final @NonNull String bidpat = "\\{((.*issue2.*10)|(.*issue1.*value1.*),?)+\\}"; 46 private static final @NonNull String bidbpat = "\\{((.*issue2.*10)|(.*issue1.*10.*),?)+\\}"; 47 48 private final static @NonNull String acceptstringpat = ".*Comparison.*actor.*party1.*bid.*issuevalues.*" 49 + bidpat + ".*better.*\\[\\].*worse.*\\[\\].*"; 39 50 40 51 private static Comparison accept, accept1, accept2, acceptb, acceptc, … … 46 57 issuevalues.put(ISSUE2, VALUE2); 47 58 bid = new Bid(issuevalues); 48 List<Bid> better = Collections.EMPTY_LIST;49 List<Bid> worse = Collections.EMPTY_LIST;59 final @NonNull List<Bid> better = Collections.EMPTY_LIST; 60 final @NonNull List<Bid> worse = Collections.EMPTY_LIST; 50 61 accept = new Comparison(id, bid, better, worse); 51 62 accept1 = new Comparison(id, bid, better, worse); … … 59 70 acceptb = new Comparison(id, bidb, better, worse); 60 71 61 List<Bid> better1 = Arrays.asList(bid);62 List<Bid> worse1 = Arrays.asList(bidb);72 final @NonNull List<@NonNull Bid> better1 = Arrays.asList(bid); 73 final @NonNull List<@NonNull Bid> worse1 = Arrays.asList(bidb); 63 74 acceptc = new Comparison(id, bidb, better1, worse); 64 75 acceptd = new Comparison(id, bidb, better, worse1); … … 76 87 public List<String> getGeneralTestStrings() { 77 88 return Arrays.asList( 78 "Comparison.*Bid.*issue2=10.*issue1=\"value1\".*better=\\[\\].*worse=\\[\\].*", 79 "Comparison.*party2.*Bid.*issue2=10.*issue1=\"value1\".*better=\\[\\].*worse=\\[\\].*", 80 "Comparison.*party1.*Bid.*issue2=10.*issue1=10.*better=\\[\\].*worse=\\[\\].*", 81 "Comparison.*party1.*Bid.*issue2=10.*issue1=10.*better=\\[Bid.*issue2=10.*issue1=\"value1\".*\\].*worse=\\[\\].*", 82 "Comparison.*party1.*Bid.*issue2=10.*issue1=10.*better=\\[\\].*worse=\\[Bid.*issue2=10.*issue1=10.*\\].*"); 89 "Comparison.*Bid.*" + bidpat 90 + ".*better=\\[\\].*worse=\\[\\].*", 91 "Comparison.*party2.*Bid.*" + bidpat 92 + ".*better=\\[\\].*worse=\\[\\].*", 93 "Comparison.*party1.*Bid.*" + bidbpat 94 + ".*better=\\[\\].*worse=\\[\\].*", 95 "Comparison.*party1.*Bid.*" + bidbpat + ".*better=\\[Bid.*" 96 + bidpat + ".*\\].*worse=\\[\\].*", 97 "Comparison.*party1.*Bid.*" + bidbpat 98 + ".*better=\\[\\].*worse=\\[Bid.*" + bidbpat 99 + ".*\\].*"); 83 100 } 84 101 85 102 @Test 86 103 public void serializeAcceptTest() throws JsonProcessingException { 87 System.out.println(jackson.writeValueAsString(accept));88 assert Equals(acceptstring, jackson.writeValueAsString(accept));104 //System.out.println(jackson.writeValueAsString(accept)); 105 assertTrue(jackson.writeValueAsString(accept).matches(acceptstringpat)); 89 106 } 90 107 91 108 @Test 92 109 public void deserializeAcceptTest() throws IOException { 93 Action act = jackson.readValue(acceptstring, Action.class); 110 final @NonNull Action act = jackson.readValue(acceptstring, 111 Action.class); 94 112 assertEquals(accept, act); 95 113 } -
events/src/test/java/geniusweb/actions/ElicitComparisonTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 9 10 import java.util.Map; 10 11 12 import org.eclipse.jdt.annotation.NonNull; 11 13 import org.junit.Before; 12 14 import org.junit.Test; 15 import org.junit.internal.runners.JUnit4ClassRunner; 16 import org.junit.runner.RunWith; 13 17 14 18 import com.fasterxml.jackson.core.JsonProcessingException; … … 21 25 import tudelft.utilities.junit.GeneralTests; 22 26 27 @RunWith(JUnit4ClassRunner.class) 23 28 public class ElicitComparisonTest extends GeneralTests<ElicitComparison> { 24 29 private final ObjectMapper jackson = new ObjectMapper(); 25 30 26 private static final PartyId id = new PartyId("party1");27 private static final PartyId id2 = new PartyId("party2");28 private final static Map<String, Value> issuevalues = new HashMap<String, Value>();29 private final static Map<String, Value> issuevaluesb = new HashMap<String, Value>();31 private static final @NonNull PartyId id = new PartyId("party1"); 32 private static final @NonNull PartyId id2 = new PartyId("party2"); 33 private final static @NonNull Map<String, Value> issuevalues = new HashMap<String, Value>(); 34 private final static @NonNull Map<String, Value> issuevaluesb = new HashMap<String, Value>(); 30 35 private static Bid bid; 31 36 private static Bid bidb; 32 private final static String ISSUE1 = "issue1";33 private final static Value VALUE1 = new DiscreteValue("value1");34 private final static String ISSUE2 = "issue2";35 private final static Value VALUE2 = new NumberValue("10");37 private final static @NonNull String ISSUE1 = "issue1"; 38 private final static @NonNull Value VALUE1 = new DiscreteValue("value1"); 39 private final static @NonNull String ISSUE2 = "issue2"; 40 private final static @NonNull Value VALUE2 = new NumberValue("10"); 36 41 // issue 2 is NUMBER and thus serializes with leading '=' 37 private final String acceptstring = "{\"ElicitComparison\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"options\":[{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}]}}"; 42 private final static @NonNull String acceptstring = "{\"ElicitComparison\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"options\":[{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}]}}"; 43 44 private final static @NonNull String acceptstringpat = "\\{\"ElicitComparison\":\\{\"actor\":\"party1\",\"bid\":\\{\"issuevalues\":\\{(((\"issue2\":10)|(\"issue1\":\"value1\")),?)+\\}\\},\"options\":\\[\\{\"issuevalues\":\\{(((\"issue2\":10)|(\"issue1\":\"value1\")),?)+\\}\\}\\]\\}\\}"; 38 45 39 46 private static ElicitComparison accept1, accept1a, accept2, accept3, … … 49 56 bidb = new Bid(issuevaluesb); 50 57 51 List<Bid> opts = Arrays.asList(bid);52 List<Bid> opts2 = Arrays.asList(bidb);58 final @NonNull List<Bid> opts = Arrays.asList(bid); 59 final @NonNull List<Bid> opts2 = Arrays.asList(bidb); 53 60 54 61 accept1 = new ElicitComparison(id, bid, opts); … … 66 73 } 67 74 75 private final static @NonNull String bidpat = "Bid\\{.*(((.*issue1.*value1.*)|(.*issue2.*10)),?)+\\}"; 76 private final static @NonNull String bidbpat = "Bid\\{.*issue1.*10.*\\}"; 77 68 78 @Override 69 79 public List<String> getGeneralTestStrings() { 70 80 return Arrays.asList( 71 "ElicitComparison.*party1.*Bid.*10.*value1.*\\[.*Bid.*10.*value1.*\\].*", 72 "ElicitComparison.*party2.*Bid.*10.*value1.*\\[.*Bid.*10.*value1.*\\].*", 73 "ElicitComparison.*party1.*Bid.*10.*\\[.*Bid.*10.*value1.*\\].*", 74 "ElicitComparison.*party1.*Bid.*10.*value1.*\\[.*Bid.*10.*\\].*"); 81 "ElicitComparison\\[.*party1.*" + bidpat + ".*\\[" + bidpat 82 + "\\]\\]", 83 "ElicitComparison\\[.*party2.*" + bidpat + ".*\\[" + bidpat 84 + "\\]\\]", 85 "ElicitComparison\\[.*party1.*" + bidbpat + ".*\\[" + bidpat 86 + "\\]\\]", 87 "ElicitComparison\\[.*party1.*" + bidpat + ".*\\[" + bidbpat 88 + "\\]\\]" 89 90 ); 75 91 } 76 92 77 93 @Test 78 94 public void serializeAcceptTest() throws JsonProcessingException { 79 System.out.println(jackson.writeValueAsString(accept1)); 80 assertEquals(acceptstring, jackson.writeValueAsString(accept1)); 95 //System.out.println(jackson.writeValueAsString(accept1)); 96 assertTrue( 97 jackson.writeValueAsString(accept1).matches(acceptstringpat)); 81 98 } 82 99 83 100 @Test 84 101 public void deserializeAcceptTest() throws IOException { 85 Action act = jackson.readValue(acceptstring, Action.class); 102 final @NonNull Action act = jackson.readValue(acceptstring, 103 Action.class); 86 104 assertEquals(accept1, act); 87 105 } -
events/src/test/java/geniusweb/actions/EndNegoTest.java
r52 r54 8 8 9 9 import org.junit.Test; 10 import org.junit.internal.runners.JUnit4ClassRunner; 11 import org.junit.runner.RunWith; 10 12 11 13 import com.fasterxml.jackson.core.JsonProcessingException; … … 14 16 import tudelft.utilities.junit.GeneralTests; 15 17 18 @RunWith(JUnit4ClassRunner.class) 16 19 public class EndNegoTest extends GeneralTests<EndNegotiation> { 17 20 private final ObjectMapper jackson = new ObjectMapper(); … … 34 37 @Override 35 38 public List<String> getGeneralTestStrings() { 36 return Arrays.asList("EndNegotiation\\[.*" + id + ".*\\]",37 "EndNegotiation\\[.*" + idb + ".*\\]");39 return Arrays.asList("EndNegotiation\\[.*" + id.toString() + ".*\\]", 40 "EndNegotiation\\[.*" + idb.toString() + ".*\\]"); 38 41 } 39 42 40 43 @Test 41 44 public void serializeEndNegoTest() throws JsonProcessingException { 42 System.out.println(jackson.writeValueAsString(endnego));45 //System.out.println(jackson.writeValueAsString(endnego)); 43 46 assertEquals(endnegostring, jackson.writeValueAsString(endnego)); 44 47 } -
events/src/test/java/geniusweb/actions/FileLocationTest.java
r52 r54 10 10 11 11 import org.junit.Test; 12 import org.junit.internal.runners.JUnit4ClassRunner; 13 import org.junit.runner.RunWith; 12 14 13 15 import com.fasterxml.jackson.core.JsonParseException; … … 16 18 import com.fasterxml.jackson.databind.ObjectMapper; 17 19 20 @RunWith(JUnit4ClassRunner.class) 18 21 public class FileLocationTest { 19 22 private final ObjectMapper jackson = new ObjectMapper(); 20 private FileLocation fileloc = new FileLocation( );21 private String filelocstr = "\"" + fileloc.getUUID String() + "\"";23 private FileLocation fileloc = new FileLocation(null); 24 private String filelocstr = "\"" + fileloc.getUUID().toString() + "\""; 22 25 23 26 private String uuidstr = "b871e65c-e7fe-4664-b607-cb31898cc3ac"; … … 36 39 @Test 37 40 public void serializeTest() throws JsonProcessingException { 38 System.out.println(jackson.writeValueAsString(fileloc));41 //System.out.println(jackson.writeValueAsString(fileloc)); 39 42 assertEquals(filelocstr, jackson.writeValueAsString(fileloc)); 40 43 } … … 48 51 @Test(expected = JsonParseException.class) 49 52 public void deserializeTestInjectinon() 50 throws JsonP arseException, JsonMappingException, IOException {53 throws JsonProcessingException, JsonMappingException, IOException { 51 54 jackson.readValue("bla/../..", FileLocation.class); 52 55 } -
events/src/test/java/geniusweb/actions/LearningDoneTest.java
r52 r54 8 8 9 9 import org.junit.Test; 10 import org.junit.internal.runners.JUnit4ClassRunner; 11 import org.junit.runner.RunWith; 10 12 11 13 import com.fasterxml.jackson.core.JsonProcessingException; … … 14 16 import tudelft.utilities.junit.GeneralTests; 15 17 18 @RunWith(JUnit4ClassRunner.class) 16 19 public class LearningDoneTest extends GeneralTests<LearningDone> { 17 20 private final ObjectMapper jackson = new ObjectMapper(); … … 28 31 @Override 29 32 public List<List<LearningDone>> getGeneralTestData() { 30 return Arrays.asList(Arrays.asList(done, done1), 31 Arrays.asList(done2)); 33 return Arrays.asList(Arrays.asList(done, done1), Arrays.asList(done2)); 32 34 } 33 35 34 36 @Override 35 37 public List<String> getGeneralTestStrings() { 36 return Arrays.asList("LearningDone\\[.*" + id + ".*\\]",37 "LearningDone\\[.*" + idb + ".*\\]");38 return Arrays.asList("LearningDone\\[.*" + id.toString() + ".*\\]", 39 "LearningDone\\[.*" + idb.toString() + ".*\\]"); 38 40 } 39 41 40 42 @Test 41 43 public void serializeEndNegoTest() throws JsonProcessingException { 42 System.out.println(jackson.writeValueAsString(done));44 //System.out.println(jackson.writeValueAsString(done)); 43 45 assertEquals(endnegostring, jackson.writeValueAsString(done)); 44 46 } -
events/src/test/java/geniusweb/actions/OfferTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 9 10 import java.util.Map; 10 11 12 import org.eclipse.jdt.annotation.NonNull; 11 13 import org.junit.Test; 14 import org.junit.internal.runners.JUnit4ClassRunner; 15 import org.junit.runner.RunWith; 12 16 13 17 import com.fasterxml.jackson.core.JsonProcessingException; … … 20 24 import tudelft.utilities.junit.GeneralTests; 21 25 26 @RunWith(JUnit4ClassRunner.class) 22 27 public class OfferTest extends GeneralTests<Offer> { 23 private final ObjectMapper jackson = new ObjectMapper();28 private final @NonNull ObjectMapper jackson = new ObjectMapper(); 24 29 25 private static final PartyId id = new PartyId("party1");26 private static final Map<String, Value> issuevalues = new HashMap<String, Value>();27 private static final Map<String, Value> issuevaluesb = new HashMap<String, Value>();30 private static final @NonNull PartyId id = new PartyId("party1"); 31 private static final @NonNull Map<String, Value> issuevalues = new HashMap<String, Value>(); 32 private static final @NonNull Map<String, Value> issuevaluesb = new HashMap<String, Value>(); 28 33 private static Bid bid; 29 34 private static Bid bidb; 30 private static final String ISSUE1 = "issue1";31 private static final Value VALUE1 = new DiscreteValue("value1");32 private static final String ISSUE2 = "issue2";33 private static final Value VALUE2 = new NumberValue("10");34 private static final String acceptstring = "{\"Offer\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}";35 private static final @NonNull String ISSUE1 = "issue1"; 36 private static final @NonNull Value VALUE1 = new DiscreteValue("value1"); 37 private static final @NonNull String ISSUE2 = "issue2"; 38 private static final @NonNull Value VALUE2 = new NumberValue("10"); 39 private static final @NonNull String acceptstring = "{\"Offer\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}}}}"; 35 40 41 private static final @NonNull String acceptstringpatt = "\\{\"Offer\":\\{\"actor\":\"party1\",\"bid\":\\{\"issuevalues\":\\{(((\"issue1\":\"value1\")|(\"issue2\":10)),?).*\\}\\}\\}\\}"; 36 42 private static Offer offer; 37 43 private static Offer offer1; … … 61 67 @Override 62 68 public List<String> getGeneralTestStrings() { 63 return Arrays.asList("Offer\\[.*" + id + ".*Bid.*\\]",64 "Offer\\[.*" + id + ".*Bid.*\\]");69 return Arrays.asList("Offer\\[.*" + id.toString() + ".*Bid.*\\]", 70 "Offer\\[.*" + id.toString() + ".*Bid.*\\]"); 65 71 } 66 72 67 73 @Test 68 74 public void serializeAcceptTest() throws JsonProcessingException { 69 System.out.println(jackson.writeValueAsString(offer));70 assert Equals(acceptstring, jackson.writeValueAsString(offer));75 //System.out.println(jackson.writeValueAsString(offer)); 76 assertTrue(jackson.writeValueAsString(offer).matches(acceptstringpatt)); 71 77 } 72 78 73 79 @Test 74 80 public void deserializeAcceptTest() throws IOException { 75 Action act = jackson.readValue(acceptstring, Action.class); 81 final @NonNull Action act = jackson.readValue(acceptstring, 82 Action.class); 76 83 assertEquals(offer, act); 77 84 } -
events/src/test/java/geniusweb/actions/PartyIdTest.java
r52 r54 7 7 8 8 import org.junit.Test; 9 import org.junit.internal.runners.JUnit4ClassRunner; 10 import org.junit.runner.RunWith; 9 11 10 12 import tudelft.utilities.junit.GeneralTests; 11 13 14 @RunWith(JUnit4ClassRunner.class) 12 15 public class PartyIdTest extends GeneralTests<PartyId> { 13 16 private final PartyId id = new PartyId("party1"); -
events/src/test/java/geniusweb/actions/PartyIdTest1.java
r52 r54 10 10 import org.junit.Before; 11 11 import org.junit.Test; 12 import org.junit.internal.runners.JUnit4ClassRunner; 13 import org.junit.runner.RunWith; 12 14 13 15 import com.fasterxml.jackson.core.JsonParseException; … … 18 20 import tudelft.utilities.junit.GeneralTests; 19 21 22 @RunWith(JUnit4ClassRunner.class) 20 23 public class PartyIdTest1 extends GeneralTests<PartyId> { 21 24 … … 51 54 @Test(expected = IllegalArgumentException.class) 52 55 public void nullTest() throws URISyntaxException { 53 new PartyId(null); 56 new PartyId(nullID()); 57 } 58 59 private String nullID() { 60 return null; 54 61 } 55 62 … … 59 66 60 67 String json = jackson.writeValueAsString(party1); 61 System.out.println(json);68 //System.out.println(json); 62 69 assertEquals(asJson, json); 63 70 } … … 68 75 ObjectMapper jackson = new ObjectMapper(); 69 76 PartyId p = jackson.readValue(asJson, PartyId.class); 70 System.out.println(p);77 //System.out.println(p); 71 78 assertEquals(party1, p); 72 79 } -
events/src/test/java/geniusweb/actions/VoteTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 9 10 import java.util.Map; 10 11 12 import org.eclipse.jdt.annotation.NonNull; 11 13 import org.junit.Before; 12 14 import org.junit.Test; 15 import org.junit.internal.runners.JUnit4ClassRunner; 16 import org.junit.runner.RunWith; 13 17 14 18 import com.fasterxml.jackson.core.JsonProcessingException; … … 21 25 import tudelft.utilities.junit.GeneralTests; 22 26 27 @RunWith(JUnit4ClassRunner.class) 23 28 public class VoteTest extends GeneralTests<Vote> { 24 29 private final ObjectMapper jackson = new ObjectMapper(); … … 36 41 // issue 2 is NUMBER and thus serializes with leading '=' 37 42 private final String votestring = "{\"Vote\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"minPower\":1,\"maxPower\":2}}"; 43 44 private static final @NonNull String bidpat = "\\{((.*issue2.*10)|(.*issue1.*value1.*),?)+\\}"; 45 private static final @NonNull String bidbpat = "\\{((.*issue2.*10)|(.*issue1.*10.*),?)+\\}"; 46 47 private final String votestringpat = ".*Vote.*actor.*party1.*bid.*issuevalues.*" 48 + bidpat + ".*minPower.*1.*maxPower.*2.*"; 38 49 39 50 private static Vote vote1, vote1a, vote2, vote3, vote4, vote5; … … 68 79 @Override 69 80 public List<String> getGeneralTestStrings() { 70 return Arrays.asList("Vote.*party1.* issue2=10.*issue1=.value1.*1.*2.*",71 "Vote.*party2.* issue2=10.*issue1=.value1.*1.*2.*",72 "Vote.*party1.* issue2=10.*issue1=10.*1.*2.*",73 "Vote.*party1.* issue2=10.*issue1=.value1.*2.*2.*",74 "Vote.*party1.* issue2=10.*issue1=.value1.*1.*3.*");81 return Arrays.asList("Vote.*party1.*" + bidpat + "*1.*2.*", 82 "Vote.*party2.*" + bidpat + ".*1.*2.*", 83 "Vote.*party1.*" + bidbpat + ".*1.*2.*", 84 "Vote.*party1.*" + bidpat + ".*2.*2.*", 85 "Vote.*party1.*" + bidpat + ".*1.*3.*"); 75 86 } 76 87 … … 82 93 @Test 83 94 public void serializeTest() throws JsonProcessingException { 84 System.out.println(jackson.writeValueAsString(vote1));85 assert Equals(votestring, jackson.writeValueAsString(vote1));95 //System.out.println(jackson.writeValueAsString(vote1)); 96 assertTrue(jackson.writeValueAsString(vote1).matches(votestringpat)); 86 97 } 87 98 -
events/src/test/java/geniusweb/actions/VoteWithValueTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 9 10 import java.util.Map; 10 11 12 import org.eclipse.jdt.annotation.NonNull; 11 13 import org.junit.Before; 12 14 import org.junit.Test; 15 import org.junit.internal.runners.JUnit4ClassRunner; 16 import org.junit.runner.RunWith; 13 17 14 18 import com.fasterxml.jackson.core.JsonProcessingException; … … 21 25 import tudelft.utilities.junit.GeneralTests; 22 26 27 @RunWith(JUnit4ClassRunner.class) 23 28 public class VoteWithValueTest extends GeneralTests<VoteWithValue> { 24 29 private final ObjectMapper jackson = new ObjectMapper(); 25 30 26 private static final PartyId id = new PartyId("party1");27 private static final PartyId id2 = new PartyId("party2");28 private final static Map<String,Value> issuevalues = new HashMap<String, Value>();29 private final static Map<String,Value> issuevaluesb = new HashMap<String, Value>();31 private static final @NonNull PartyId id = new PartyId("party1"); 32 private static final @NonNull PartyId id2 = new PartyId("party2"); 33 private final static @NonNull Map<@NonNull String, @NonNull Value> issuevalues = new HashMap<String, Value>(); 34 private final static @NonNull Map<@NonNull String, @NonNull Value> issuevaluesb = new HashMap<String, Value>(); 30 35 private static Bid bid; 31 36 private static Bid bidb; 32 private final static String ISSUE1 = "issue1";33 private final static Value VALUE1 = new DiscreteValue("value1");34 private final static String ISSUE2 = "issue2";35 private final static Value VALUE2 = new NumberValue("10");37 private final static @NonNull String ISSUE1 = "issue1"; 38 private final static @NonNull Value VALUE1 = new DiscreteValue("value1"); 39 private final static @NonNull String ISSUE2 = "issue2"; 40 private final static @NonNull Value VALUE2 = new NumberValue("10"); 36 41 // issue 2 is NUMBER and thus serializes with leading '=' 37 private final String votestring = "{\"VoteWithValue\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"minPower\":1,\"maxPower\":2,\"value\":10}}"; 42 private static final @NonNull String votestring = "{\"VoteWithValue\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"minPower\":1,\"maxPower\":2,\"value\":10}}"; 43 44 private static final @NonNull String bidpat = "\\{((.*issue2.*10)|(.*issue1.*value1.*),?)+\\}"; 45 private static final @NonNull String bidbpat = "\\{((.*issue2.*10)|(.*issue1.*10.*),?)+\\}"; 46 private static final @NonNull String votestringpat = ".*VoteWithValue.*actor.*party1.*bid.*issuevalues.*" 47 + bidpat + ".*minPower.*1.*maxPower.*2.*value.*10.*"; 38 48 39 49 private static VoteWithValue vote1, vote1a, vote2, vote3, vote4, vote5, … … 72 82 public List<String> getGeneralTestStrings() { 73 83 return Arrays.asList( 74 "VoteWithValue.*party1.* issue2=10.*issue1=.value1.*1.*2.*10.*",75 "VoteWithValue.*party2.* issue2=10.*issue1=.value1.*1.*2.*10.*",76 "VoteWithValue.*party1.* issue2=10.*issue1=10.*1.*2.*10.*",77 "VoteWithValue.*party1.* issue2=10.*issue1=.value1.*2.*2.*10.*",78 "VoteWithValue.*party1.* issue2=10.*issue1=.value1.*1.*3.*10.*",79 "VoteWithValue.*party1.* issue2=10.*issue1=.value1.*1.*2.*20.*");84 "VoteWithValue.*party1.*" + bidpat + ".*1.*2.*10.*", 85 "VoteWithValue.*party2.*" + bidpat + ".*1.*2.*10.*", 86 "VoteWithValue.*party1.*" + bidbpat + ".*1.*2.*10.*", 87 "VoteWithValue.*party1.*" + bidpat + ".*2.*2.*10.*", 88 "VoteWithValue.*party1.*" + bidpat + ".*1.*3.*10.*", 89 "VoteWithValue.*party1.*" + bidpat + ".*1.*2.*20.*"); 80 90 } 81 91 … … 87 97 @Test 88 98 public void serializeTest() throws JsonProcessingException { 89 System.out.println(jackson.writeValueAsString(vote1));90 assert Equals(votestring, jackson.writeValueAsString(vote1));99 //System.out.println(jackson.writeValueAsString(vote1)); 100 assertTrue(jackson.writeValueAsString(vote1).matches(votestringpat)); 91 101 } 92 102 93 103 @Test 94 104 public void deserializeAcceptTest() throws IOException { 95 Action act = jackson.readValue(votestring, Action.class);105 final @NonNull Action act = jackson.readValue(votestring, Action.class); 96 106 assertEquals(vote1, act); 97 107 } -
events/src/test/java/geniusweb/actions/VotesTest.java
r52 r54 11 11 import java.util.List; 12 12 13 import org.eclipse.jdt.annotation.NonNull; 13 14 import org.junit.Test; 15 import org.junit.internal.runners.JUnit4ClassRunner; 16 import org.junit.runner.RunWith; 14 17 15 18 import com.fasterxml.jackson.core.JsonProcessingException; … … 20 23 import tudelft.utilities.junit.GeneralTests; 21 24 25 @RunWith(JUnit4ClassRunner.class) 22 26 public class VotesTest extends GeneralTests<Votes> { 23 private final ObjectMapper jackson = new ObjectMapper(); 24 private final String votestring = "{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val1\"}},\"minPower\":2,\"maxPower\":9}},{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val2\"}},\"minPower\":2,\"maxPower\":9}}]}}"; 27 private final static @NonNull ObjectMapper jackson = new ObjectMapper(); 28 private final @NonNull String votestring = "{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val1\"}},\"minPower\":2,\"maxPower\":9}},{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val2\"}},\"minPower\":2,\"maxPower\":9}}]}}"; 29 private final @NonNull String votestringpat = ".*Votes.*actor.*partyA.*votes.*Vote.*actor.*partyA.*Vote.*actor.*partyA.*minPower.*2.*maxPower.*9.*"; 25 30 26 private PartyId partyA = new PartyId("partyA"); 27 private PartyId partyB = new PartyId("partyB"); 28 private Bid bid1 = new Bid("is1", new DiscreteValue("val1")), 29 bid2 = new Bid("is1", new DiscreteValue("val2")); 30 private Vote voteA1 = new Vote(partyA, bid1, 2, 9); 31 private Vote voteA2 = new Vote(partyA, bid2, 2, 9); 32 private Vote voteB1 = new Vote(partyB, bid1, 2, 9); 33 private Vote voteB2 = new Vote(partyB, bid2, 2, 9); 31 private final @NonNull PartyId partyA = new PartyId("partyA"); 32 private final @NonNull PartyId partyB = new PartyId("partyB"); 33 private final @NonNull Bid bid1 = new Bid( 34 Collections.singletonMap("is1", new DiscreteValue("val1"))), 35 bid2 = new Bid( 36 Collections.singletonMap("is1", new DiscreteValue("val2"))); 37 private final @NonNull Vote voteA1 = new Vote(partyA, bid1, 2, 9); 38 private final @NonNull Vote voteA2 = new Vote(partyA, bid2, 2, 9); 39 private final @NonNull Vote voteB1 = new Vote(partyB, bid1, 2, 9); 40 private final @NonNull Vote voteB2 = new Vote(partyB, bid2, 2, 9); 34 41 35 private Votes votes1 = new Votes(partyA,42 private final @NonNull Votes votes1 = new Votes(partyA, 36 43 new HashSet<>(Arrays.asList(voteA1, voteA2))); 37 private Votes votes1a = new Votes(partyA,44 private final @NonNull Votes votes1a = new Votes(partyA, 38 45 new HashSet<>(Arrays.asList(voteA1, voteA2))); 39 private Votes votes2 = new Votes(partyB,46 private final @NonNull Votes votes2 = new Votes(partyB, 40 47 new HashSet<>(Arrays.asList(voteB1, voteB2))); 41 48 … … 49 56 public List<String> getGeneralTestStrings() { 50 57 return Arrays.asList( 51 "Votes.* Vote.*partyA,Bid.*is1.*val1.*2.*Vote.*partyA,Bid.*is1.*val2.*2.*",52 "Votes.* Vote.*partyB,Bid.*is1.*val2.*2.*Vote.*partyB,Bid.*is1.*val1.*2.*");58 "Votes.*(((Vote.*partyA,Bid.*is1.*val1.*2)|(Vote.*partyA,Bid.*is1.*val2.*2)),?)+.*", 59 "Votes.*(((Vote.*partyB,Bid.*is1.*val2.*2)|(Vote.*partyB,Bid.*is1.*val1.*2)),?)+.*"); 53 60 } 54 61 … … 61 68 @Test 62 69 public void serializeTest() throws JsonProcessingException { 63 System.out.println(jackson.writeValueAsString(votes1));64 assert Equals(votestring, jackson.writeValueAsString(votes1));70 //System.out.println(jackson.writeValueAsString(votes1)); 71 assertTrue(jackson.writeValueAsString(votes1).matches(votestringpat)); 65 72 } 66 73 67 74 @Test 68 75 public void deserializeTest() throws IOException { 69 Action act = jackson.readValue(votestring, Action.class);76 final @NonNull Action act = jackson.readValue(votestring, Action.class); 70 77 assertEquals(votes1, act); 71 78 } … … 78 85 @Test 79 86 public void isExtendingTestExtraVote() { 80 Votes otherVotes = new Votes(partyA, Collections.singleton(voteA1)); 87 final @NonNull Votes otherVotes = new Votes(partyA, 88 Collections.singleton(voteA1)); 81 89 assertTrue(votes1.isExtending(otherVotes)); 82 90 } … … 84 92 @Test 85 93 public void isExtendingTestNoVotes() { 86 Votes otherVotes = new Votes(partyA, Collections.emptySet()); 94 final @NonNull Votes otherVotes = new Votes(partyA, 95 Collections.emptySet()); 87 96 assertTrue(votes1.isExtending(otherVotes)); 88 97 } … … 90 99 @Test 91 100 public void isExtendingTestMissing() { 92 Votes otherVotes = new Votes(partyA, Collections.singleton(voteA1)); 101 final @NonNull Votes otherVotes = new Votes(partyA, 102 Collections.singleton(voteA1)); 93 103 assertFalse(otherVotes.isExtending(votes1)); 94 104 } … … 101 111 @Test 102 112 public void isReallyExtendingVotesMin() { 103 Vote powervoteA1 = new Vote(partyA, bid1, 1, 9);104 Votes powerVotes = new Votes(partyA,113 final @NonNull Vote powervoteA1 = new Vote(partyA, bid1, 1, 9); 114 final @NonNull Votes powerVotes = new Votes(partyA, 105 115 new HashSet<>(Arrays.asList(powervoteA1, voteA2))); 106 116 assertTrue(powerVotes.isExtending(votes1)); … … 109 119 @Test 110 120 public void isReallyExtendingVotesMax() { 111 Vote powervoteA1 = new Vote(partyA, bid1, 2, 10);112 Votes powerVotes = new Votes(partyA,121 final @NonNull Vote powervoteA1 = new Vote(partyA, bid1, 2, 10); 122 final @NonNull Votes powerVotes = new Votes(partyA, 113 123 new HashSet<>(Arrays.asList(powervoteA1, voteA2))); 114 124 assertTrue(powerVotes.isExtending(votes1)); … … 117 127 @Test 118 128 public void IsNarrowingOneVoteRemoved() { 119 Votes narrowVotes = new Votes(partyA, Collections.singleton(voteA2)); 129 final @NonNull Votes narrowVotes = new Votes(partyA, 130 Collections.singleton(voteA2)); 120 131 assertFalse(narrowVotes.isExtending(votes1)); 121 132 } … … 123 134 @Test 124 135 public void isNarrowingTestMoreMinPower() { 125 Vote narrowVoteA1 = new Vote(partyA, bid1, 3, 9);126 Votes narrowVotes = new Votes(partyA,136 final @NonNull Vote narrowVoteA1 = new Vote(partyA, bid1, 3, 9); 137 final @NonNull Votes narrowVotes = new Votes(partyA, 127 138 new HashSet<>(Arrays.asList(narrowVoteA1, voteA2))); 128 139 assertFalse(narrowVotes.isExtending(votes1)); … … 141 152 @Test(expected = IllegalArgumentException.class) 142 153 public void testDuplicateBidsNotAllowed() { 143 Vote voteA1similar = new Vote(partyA, bid1, 3, 9);144 Votes votes = new Votes(partyA,154 final @NonNull Vote voteA1similar = new Vote(partyA, bid1, 3, 9); 155 final @NonNull Votes votes = new Votes(partyA, 145 156 new HashSet<>(Arrays.asList(voteA1, voteA1similar))); 146 157 } -
events/src/test/java/geniusweb/actions/VotesWithValueTest.java
r52 r54 11 11 import java.util.List; 12 12 13 import org.eclipse.jdt.annotation.NonNull; 13 14 import org.junit.Test; 15 import org.junit.internal.runners.JUnit4ClassRunner; 16 import org.junit.runner.RunWith; 14 17 15 18 import com.fasterxml.jackson.core.JsonProcessingException; … … 20 23 import tudelft.utilities.junit.GeneralTests; 21 24 25 @RunWith(JUnit4ClassRunner.class) 22 26 public class VotesWithValueTest extends GeneralTests<VotesWithValue> { 23 private final ObjectMapper jackson = new ObjectMapper(); 24 private final String votestring = "{\"VotesWithValue\":{\"actor\":\"partyA\",\"votes\":[{\"VoteWithValue\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val1\"}},\"minPower\":2,\"maxPower\":9,\"value\":30}},{\"VoteWithValue\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val2\"}},\"minPower\":2,\"maxPower\":9,\"value\":70}}]}}"; 27 private final @NonNull ObjectMapper jackson = new ObjectMapper(); 28 private final @NonNull String votestring = "{\"VotesWithValue\":{\"actor\":\"partyA\",\"votes\":[{\"VoteWithValue\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val1\"}},\"minPower\":2,\"maxPower\":9,\"value\":30}},{\"VoteWithValue\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val2\"}},\"minPower\":2,\"maxPower\":9,\"value\":70}}]}}"; 29 private final @NonNull String vote1pat = "(.*VoteWithValue.*actor.*partyA.*bid.*issuevalues.*minPower.*2.*maxPower.*9.*value.*30.*)"; 30 private final @NonNull String vote2pat = "(.*VoteWithValue.*actor.*partyA.*bid.*issuevalues.*minPower.*2.*maxPower.*9.*value.*70.*)"; 31 private final @NonNull String votestringpat = ".*VotesWithValue.*actor.*partyA.*votes.*((" 32 + vote1pat + "|" + vote2pat + "),?).*"; 25 33 26 private PartyId partyA = new PartyId("partyA"); 27 private PartyId partyB = new PartyId("partyB"); 28 private Bid bid1 = new Bid("is1", new DiscreteValue("val1")), 29 bid2 = new Bid("is1", new DiscreteValue("val2")); 30 private VoteWithValue voteA1 = new VoteWithValue(partyA, bid1, 2, 9, 30); 31 private VoteWithValue voteA2 = new VoteWithValue(partyA, bid2, 2, 9, 70); 32 private VoteWithValue voteA1_100 = new VoteWithValue(partyA, bid1, 2, 9, 33 100); 34 private VoteWithValue voteA2_100 = new VoteWithValue(partyA, bid2, 2, 9, 35 100); 36 private VoteWithValue voteB1 = new VoteWithValue(partyB, bid1, 2, 9, 40); 37 private VoteWithValue voteB2 = new VoteWithValue(partyB, bid2, 2, 9, 60); 34 private @NonNull PartyId partyA = new PartyId("partyA"); 35 private @NonNull PartyId partyB = new PartyId("partyB"); 36 private @NonNull Bid bid1 = new Bid( 37 Collections.singletonMap("is1", new DiscreteValue("val1"))), 38 bid2 = new Bid( 39 Collections.singletonMap("is1", new DiscreteValue("val2"))); 40 private @NonNull VoteWithValue voteA1 = new VoteWithValue(partyA, bid1, 2, 41 9, 30); 42 private @NonNull VoteWithValue voteA2 = new VoteWithValue(partyA, bid2, 2, 43 9, 70); 44 private @NonNull VoteWithValue voteA1_100 = new VoteWithValue(partyA, bid1, 45 2, 9, 100); 46 private @NonNull VoteWithValue voteA2_100 = new VoteWithValue(partyA, bid2, 47 2, 9, 100); 48 private @NonNull VoteWithValue voteB1 = new VoteWithValue(partyB, bid1, 2, 49 9, 40); 50 private @NonNull VoteWithValue voteB2 = new VoteWithValue(partyB, bid2, 2, 51 9, 60); 38 52 39 private VotesWithValue votes1 = new VotesWithValue(partyA,53 private @NonNull VotesWithValue votes1 = new VotesWithValue(partyA, 40 54 new HashSet<>(Arrays.asList(voteA1, voteA2))); 41 private VotesWithValue votes1a = new VotesWithValue(partyA,55 private @NonNull VotesWithValue votes1a = new VotesWithValue(partyA, 42 56 new HashSet<>(Arrays.asList(voteA1, voteA2))); 43 private VotesWithValue votes2 = new VotesWithValue(partyB,57 private @NonNull VotesWithValue votes2 = new VotesWithValue(partyB, 44 58 new HashSet<>(Arrays.asList(voteB1, voteB2))); 45 59 … … 52 66 @Override 53 67 public List<String> getGeneralTestStrings() { 54 return Arrays.asList( 55 "Votes.*Vote.*partyA,Bid.*is1.*val1.*2.*Vote.*partyA,Bid.*is1.*val2.*2.*", 56 "Votes.*Vote.*partyB,Bid.*is1.*val2.*2.*Vote.*partyB,Bid.*is1.*val1.*2.*"); 68 return Arrays.asList("VotesWithValue.*partyA.*", 69 "VotesWithValue.*partyB.*"); 57 70 } 58 71 … … 65 78 @Test 66 79 public void serializeTest() throws JsonProcessingException { 67 System.out.println(jackson.writeValueAsString(votes1));68 assert Equals(votestring, jackson.writeValueAsString(votes1));80 //System.out.println(jackson.writeValueAsString(votes1)); 81 assertTrue(jackson.writeValueAsString(votes1).matches(votestringpat)); 69 82 } 70 83 71 84 @Test 72 85 public void deserializeTest() throws IOException { 73 Action act = jackson.readValue(votestring, Action.class);86 final @NonNull Action act = jackson.readValue(votestring, Action.class); 74 87 assertEquals(votes1, act); 75 88 } … … 83 96 @Test 84 97 public void isExtendingTestExtraVote() { 85 VotesWithValue otherVotes = new VotesWithValue(partyA,98 final @NonNull VotesWithValue otherVotes = new VotesWithValue(partyA, 86 99 Collections.singleton(voteA1_100)); 87 100 assertTrue(votes1.isExtending(otherVotes)); … … 90 103 @Test 91 104 public void isExtendingTestMissing() { 92 VotesWithValue otherVotes = new VotesWithValue(partyA,105 final @NonNull VotesWithValue otherVotes = new VotesWithValue(partyA, 93 106 Collections.singleton(voteA1_100)); 94 107 assertFalse(otherVotes.isExtending(votes1)); … … 102 115 @Test 103 116 public void isReallyExtendingVotesMin() { 104 VoteWithValue powervoteA1 = new VoteWithValue(partyA, bid1, 1, 9, 30); 105 VotesWithValue powerVotes = new VotesWithValue(partyA, 117 final @NonNull VoteWithValue powervoteA1 = new VoteWithValue(partyA, 118 bid1, 1, 9, 30); 119 final @NonNull VotesWithValue powerVotes = new VotesWithValue(partyA, 106 120 new HashSet<>(Arrays.asList(powervoteA1, voteA2))); 107 121 assertTrue(powerVotes.isExtending(votes1)); … … 110 124 @Test 111 125 public void isReallyExtendingVotesMax() { 112 VoteWithValue powervoteA1 = new VoteWithValue(partyA, bid1, 2, 10, 30); 113 VotesWithValue powerVotes = new VotesWithValue(partyA, 126 final @NonNull VoteWithValue powervoteA1 = new VoteWithValue(partyA, 127 bid1, 2, 10, 30); 128 final @NonNull VotesWithValue powerVotes = new VotesWithValue(partyA, 114 129 new HashSet<>(Arrays.asList(powervoteA1, voteA2))); 115 130 assertTrue(powerVotes.isExtending(votes1)); … … 118 133 @Test 119 134 public void IsNarrowingOneVoteRemoved() { 120 VotesWithValue narrowVotes = new VotesWithValue(partyA,135 final @NonNull VotesWithValue narrowVotes = new VotesWithValue(partyA, 121 136 Collections.singleton(voteA2_100)); 122 137 assertFalse(narrowVotes.isExtending(votes1)); … … 125 140 @Test 126 141 public void isNarrowingTestMoreMinPower() { 127 VoteWithValue narrowVoteA1 = new VoteWithValue(partyA, bid1, 3, 9, 30); 128 VotesWithValue narrowVotes = new VotesWithValue(partyA, 142 final @NonNull VoteWithValue narrowVoteA1 = new VoteWithValue(partyA, 143 bid1, 3, 9, 30); 144 final @NonNull VotesWithValue narrowVotes = new VotesWithValue(partyA, 129 145 new HashSet<>(Arrays.asList(narrowVoteA1, voteA2))); 130 146 assertFalse(narrowVotes.isExtending(votes1)); -
events/src/test/java/geniusweb/events/ActionEventTest.java
r52 r54 8 8 import java.util.List; 9 9 10 import org.eclipse.jdt.annotation.NonNull; 10 11 import org.junit.Test; 12 import org.junit.internal.runners.JUnit4ClassRunner; 13 import org.junit.runner.RunWith; 11 14 12 15 import com.fasterxml.jackson.core.JsonProcessingException; … … 18 21 import tudelft.utilities.junit.GeneralTests; 19 22 23 @RunWith(JUnit4ClassRunner.class) 20 24 public class ActionEventTest extends GeneralTests<ActionEvent> { 21 private static final long NOW = 101l;22 private final ObjectMapper jackson = new ObjectMapper();23 private final String string = "{\"ActionEvent\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}},\"time\":101}}";24 private final PartyId id = new PartyId("party1");25 private final Action action = new EndNegotiation(id);26 private final ActionEvent evt = new ActionEvent(action, NOW);27 private final ActionEvent evt1 = new ActionEvent(action, NOW);28 private final ActionEvent evtb = new ActionEvent(action, NOW + 1);25 private static final @NonNull Long NOW = 101l; 26 private final @NonNull ObjectMapper jackson = new ObjectMapper(); 27 private final @NonNull String string = "{\"ActionEvent\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}},\"time\":101}}"; 28 private final @NonNull PartyId id = new PartyId("party1"); 29 private final @NonNull Action action = new EndNegotiation(id); 30 private final @NonNull ActionEvent evt = new ActionEvent(action, NOW); 31 private final @NonNull ActionEvent evt1 = new ActionEvent(action, NOW); 32 private final @NonNull ActionEvent evtb = new ActionEvent(action, NOW + 1); 29 33 30 34 @Override … … 35 39 @Override 36 40 public List<String> getGeneralTestStrings() { 37 return Arrays.asList("ActionEvent\\[.*" + NOW + ".*EndNegotiation.*\\]", 38 "ActionEvent\\[.*" + (NOW + 1) + ".*EndNegotiation.*\\]"); 41 return Arrays.asList( 42 "ActionEvent\\[.*" + NOW.toString() + ".*EndNegotiation.*\\]", 43 "ActionEvent\\[.*" + ((Long) (NOW + 1)).toString() 44 + ".*EndNegotiation.*\\]"); 39 45 } 40 46 41 47 @Test 42 48 public void smoketest() { 43 Action action = mock(EndNegotiation.class);49 final @NonNull Action action = mock(EndNegotiation.class); 44 50 ActionEvent evt = new ActionEvent(action, 0l); 45 51 } … … 47 53 @Test 48 54 public void serializeTest() throws JsonProcessingException { 49 System.out.println(jackson.writeValueAsString(evt));55 //System.out.println(jackson.writeValueAsString(evt)); 50 56 assertEquals(string, jackson.writeValueAsString(evt)); 51 57 } … … 53 59 @Test 54 60 public void deserializeTestReadActionEvent() throws IOException { 55 ActionEvent evt1 = jackson.readValue(string, ActionEvent.class); 61 final @NonNull ActionEvent evt1 = jackson.readValue(string, 62 ActionEvent.class); 56 63 // compare fields, as evt is a derived/new inner class 57 64 assertEquals(EndNegotiation.class, evt1.getAction().getClass()); … … 61 68 @Test 62 69 public void deserializeTestReadEvent() throws IOException { 63 NegotiationEvent evt1 = jackson.readValue(string,70 final @NonNull NegotiationEvent evt1 = jackson.readValue(string, 64 71 NegotiationEvent.class); 65 72 assertEquals(ActionEvent.class, evt1.getClass()); 66 ActionEvent ev1 = (ActionEvent) evt1;73 final @NonNull ActionEvent ev1 = (ActionEvent) evt1; 67 74 assertEquals(EndNegotiation.class, ev1.getAction().getClass()); 68 75 assertEquals((Long) 101l, ev1.getTime()); -
events/src/test/java/geniusweb/events/SessionStartedTest.java
r52 r54 8 8 import java.util.List; 9 9 10 import org.eclipse.jdt.annotation.NonNull; 10 11 import org.junit.Test; 11 import org.junit. experimental.theories.DataPoint;12 import org.junit. experimental.theories.DataPoints;12 import org.junit.internal.runners.JUnit4ClassRunner; 13 import org.junit.runner.RunWith; 13 14 14 15 import com.fasterxml.jackson.core.JsonProcessingException; … … 18 19 import tudelft.utilities.junit.GeneralTests; 19 20 21 @RunWith(JUnit4ClassRunner.class) 20 22 public class SessionStartedTest extends GeneralTests<SessionStarted> { 21 23 22 private final ObjectMapper jackson = new ObjectMapper();24 private final static @NonNull ObjectMapper jackson = new ObjectMapper(); 23 25 24 private static final Long SESSIONNR = 1l;25 protected static final Long NOW = (long) 101;26 protected static final Long NOW1 = NOW + 1;26 private static final @NonNull Long SESSIONNR = 1l; 27 protected static final @NonNull Long NOW = 101l; 28 protected static final @NonNull Long NOW1 = NOW + 1; 27 29 28 private static final PartyId PARTY1 = new PartyId("party1");29 private static final PartyId PARTY2 = new PartyId("party2");30 private static final @NonNull PartyId PARTY1 = new PartyId("party1"); 31 private static final @NonNull PartyId PARTY2 = new PartyId("party2"); 30 32 31 private static List<PartyId> parties = Arrays.asList(PARTY1, PARTY2); 33 private static @NonNull List<@NonNull PartyId> parties = Arrays 34 .asList(PARTY1, PARTY2); 32 35 33 private static final SessionStarted sessionStartedLater = new SessionStarted(36 private static final @NonNull SessionStarted sessionStartedLater = new SessionStarted( 34 37 SESSIONNR, parties, NOW1); 35 private static final SessionStarted othersessionStarted = new SessionStarted(38 private static final @NonNull SessionStarted othersessionStarted = new SessionStarted( 36 39 SESSIONNR + 1, parties, NOW); 37 40 38 public static SessionStarted sessionStarted = new SessionStarted(SESSIONNR,39 parties, NOW);40 private static final SessionStarted sessionStarted1 = new SessionStarted(41 public static @NonNull SessionStarted sessionStarted = new SessionStarted( 42 SESSIONNR, parties, NOW); 43 private static final @NonNull SessionStarted sessionStarted1 = new SessionStarted( 41 44 SESSIONNR, parties, NOW); 42 45 // jackson expected format. 43 private static String sessionstartedstring = "{\"SessionStarted\":{\"sessionNumber\":1,\"parties\":[\"party1\",\"party2\"],\"time\":101}}";46 private static @NonNull String sessionstartedstring = "{\"SessionStarted\":{\"sessionNumber\":1,\"parties\":[\"party1\",\"party2\"],\"time\":101}}"; 44 47 // "{\"sessionstarted\":{\"time\":101,\"sessionNumber\":1,\"parties\":[\"party1\",\"party2\"]}}"; 45 public static String expectedstring = "SessionStarted.*101.*";48 public static @NonNull String expectedstring = "SessionStarted.*101.*"; 46 49 47 50 @Override 48 51 public List<List<SessionStarted>> getGeneralTestData() { 49 List<List<SessionStarted>> list= new LinkedList<>();50 list.add(Arrays.asList(sessionStarted, sessionStarted1));51 list.add(Arrays.asList(sessionStartedLater));52 list.add(Arrays.asList(othersessionStarted));53 return list;52 final @NonNull List<@NonNull List<@NonNull SessionStarted>> data = new LinkedList<>(); 53 data.add(Arrays.asList(sessionStarted, sessionStarted1)); 54 data.add(Arrays.asList(sessionStartedLater)); 55 data.add(Arrays.asList(othersessionStarted)); 56 return data; 54 57 } 55 58 56 59 @Override 57 60 public List<String> getGeneralTestStrings() { 58 return Arrays.asList("SessionStarted.*" + SESSIONNR + ".*" + NOW + ".*", 59 "SessionStarted.*" + SESSIONNR + ".*" + NOW1 + ".*", 60 "SessionStarted.*" + (SESSIONNR + 1) + ".*" + NOW + ".*"); 61 return Arrays.asList( 62 "SessionStarted.*" + SESSIONNR.toString() + ".*" 63 + NOW.toString() + ".*", 64 "SessionStarted.*" + SESSIONNR.toString() + ".*" 65 + NOW1.toString() + ".*", 66 "SessionStarted.*" + ((Long) (SESSIONNR + 1)).toString() + ".*" 67 + NOW.toString() + ".*"); 61 68 } 62 63 @DataPoints("equal")64 public static SessionStarted[] equal() {65 return new SessionStarted[] { sessionStarted, sessionStarted1 };66 }67 68 @DataPoints("notequal")69 public static SessionStarted[] notequal() {70 return new SessionStarted[] { sessionStartedLater,71 sessionStartedLater };72 }73 74 @DataPoint("equalstring")75 69 76 70 @Test 77 71 public void serializeStartedTest() throws JsonProcessingException { 78 System.out.println(jackson.writeValueAsString(sessionStarted));72 //System.out.println(jackson.writeValueAsString(sessionStarted)); 79 73 assertEquals(sessionstartedstring, 80 74 jackson.writeValueAsString(sessionStarted)); … … 83 77 @Test 84 78 public void deserializeStartedTest() throws IOException { 85 NegotiationEvent evt = jackson.readValue(sessionstartedstring,86 NegotiationEvent.class);79 final @NonNull NegotiationEvent evt = jackson 80 .readValue(sessionstartedstring, NegotiationEvent.class); 87 81 assertEquals(SessionStarted.class, evt.getClass()); 88 SessionStarted event = (SessionStarted) evt;82 final @NonNull SessionStarted event = (SessionStarted) evt; 89 83 // compare fields, as sessionended is a derived/new inner class 90 84 assertEquals(NOW, event.getTime()); -
events/src/test/java/geniusweb/events/TournamentStartedTest.java
r52 r54 8 8 import java.util.List; 9 9 10 import org.eclipse.jdt.annotation.NonNull; 10 11 import org.junit.Test; 12 import org.junit.internal.runners.JUnit4ClassRunner; 13 import org.junit.runner.RunWith; 11 14 12 15 import com.fasterxml.jackson.core.JsonProcessingException; … … 15 18 import tudelft.utilities.junit.GeneralTests; 16 19 20 @RunWith(JUnit4ClassRunner.class) 17 21 public class TournamentStartedTest extends GeneralTests<TournamentStarted> { 18 22 19 private final ObjectMapper jackson = new ObjectMapper();23 private final static @NonNull ObjectMapper jackson = new ObjectMapper(); 20 24 21 private static final Long SESSIONNR = 1l;22 protected static final Long NOW = (long) 101;23 protected static final Long NOW1 = NOW + 1;24 private static final Long NSESSIONS = 5l;25 private static final @NonNull Long SESSIONNR = 1l; 26 protected static final @NonNull Long NOW = 101L; 27 protected static final @NonNull Long NOW1 = NOW + 1; 28 private static final @NonNull Long NSESSIONS = 5l; 25 29 26 private staticTournamentStarted tournamentStarted = new TournamentStarted(30 private final static @NonNull TournamentStarted tournamentStarted = new TournamentStarted( 27 31 NSESSIONS, NOW); 28 private staticTournamentStarted tournamentStarteda = new TournamentStarted(32 private final static @NonNull TournamentStarted tournamentStarteda = new TournamentStarted( 29 33 NSESSIONS, NOW); 30 private TournamentStarted otherTournamentStarted = new TournamentStarted(34 private final static @NonNull TournamentStarted otherTournamentStarted = new TournamentStarted( 31 35 NSESSIONS + 1, NOW); 32 private TournamentStarted tournamentStartedLater = new TournamentStarted(36 private final static @NonNull TournamentStarted tournamentStartedLater = new TournamentStarted( 33 37 NSESSIONS, NOW1); 34 38 35 private String tournamentstartedstring = "{\"TournamentStarted\":{\" time\":101,\"numberOfSessions\":5}}";39 private String tournamentstartedstring = "{\"TournamentStarted\":{\"numberOfSessions\":5,\"time\":101}}"; 36 40 37 41 @Override 38 42 public List<List<TournamentStarted>> getGeneralTestData() { 39 List<List<TournamentStarted>>list = new LinkedList<>();40 list.add(Arrays.asList(tournamentStarted, tournamentStarteda));41 list.add(Arrays.asList(otherTournamentStarted));42 list.add(Arrays.asList(tournamentStartedLater));43 return list;43 final @NonNull List<@NonNull List<@NonNull TournamentStarted>> tourlist = new LinkedList<>(); 44 tourlist.add(Arrays.asList(tournamentStarted, tournamentStarteda)); 45 tourlist.add(Arrays.asList(otherTournamentStarted)); 46 tourlist.add(Arrays.asList(tournamentStartedLater)); 47 return tourlist; 44 48 } 45 49 … … 47 51 public List<String> getGeneralTestStrings() { 48 52 return Arrays.asList( 49 "TournamentStarted\\[.*" + NOW + ".*" + NSESSIONS + ".*\\]", 50 "TournamentStarted\\[.*" + NOW + ".*" + (NSESSIONS + 1) 51 + ".*\\]", 52 "TournamentStarted\\[.*" + NOW1 + ".*" + NSESSIONS + ".*\\]"); 53 "TournamentStarted\\[.*" + NOW.toString() + ".*" 54 + NSESSIONS.toString() + ".*\\]", 55 "TournamentStarted\\[.*" + NOW.toString() + ".*" 56 + ((Long) (NSESSIONS + 1)).toString() + ".*\\]", 57 "TournamentStarted\\[.*" + NOW1.toString() + ".*" 58 + NSESSIONS.toString() + ".*\\]"); 53 59 } 54 60 … … 56 62 public void serializeTournamentStartedTest() 57 63 throws JsonProcessingException { 58 System.out.println(jackson.writeValueAsString(tournamentStarted));64 //System.out.println(jackson.writeValueAsString(tournamentStarted)); 59 65 assertEquals(tournamentstartedstring, 60 66 jackson.writeValueAsString(tournamentStarted)); … … 63 69 @Test 64 70 public void deserializeTournamentStartedTest() throws IOException { 65 NegotiationEvent evt = jackson.readValue(tournamentstartedstring,66 NegotiationEvent.class);71 final @NonNull NegotiationEvent evt = jackson 72 .readValue(tournamentstartedstring, NegotiationEvent.class); 67 73 assertEquals(TournamentStarted.class, evt.getClass()); 68 TournamentStarted event = (TournamentStarted) evt;74 final @NonNull TournamentStarted event = (TournamentStarted) evt; 69 75 // compare fields, as sessionended is a derived/new inner class 70 76 assertEquals(NSESSIONS, event.getNumberOfSessions()); 71 77 assertEquals(NOW, event.getTime()); 72 }73 74 @Test(expected = IllegalArgumentException.class)75 public void testNullTime() {76 new TournamentStarted(NSESSIONS, null);77 78 } 78 79 -
events/src/test/java/geniusweb/inform/ActionDoneTest.java
r52 r54 7 7 import java.util.List; 8 8 9 import org. junit.Before;9 import org.eclipse.jdt.annotation.NonNull; 10 10 import org.junit.Test; 11 import org.junit.internal.runners.JUnit4ClassRunner; 12 import org.junit.runner.RunWith; 11 13 12 14 import com.fasterxml.jackson.core.JsonProcessingException; … … 18 20 import tudelft.utilities.junit.GeneralTests; 19 21 22 @RunWith(JUnit4ClassRunner.class) 20 23 public class ActionDoneTest extends GeneralTests<ActionDone> { 21 private final ObjectMapper jackson = new ObjectMapper();24 private final @NonNull ObjectMapper jackson = new ObjectMapper(); 22 25 23 private static final PartyId id = new PartyId("party1");24 private static final PartyId id2 = new PartyId("party2");26 private static @NonNull final PartyId id = new PartyId("party1"); 27 private static @NonNull final PartyId id2 = new PartyId("party2"); 25 28 26 private final String actiondonestr = "{\"ActionDone\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}}}}";29 private final @NonNull String actiondonestr = "{\"ActionDone\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}}}}"; 27 30 28 private final static Action act1 = new EndNegotiation(id);29 private final static Action act2 = new EndNegotiation(id2);31 private final static @NonNull Action act1 = new EndNegotiation(id); 32 private final static @NonNull Action act2 = new EndNegotiation(id2); 30 33 31 private final static ActionDone done1 = new ActionDone(act1);32 private final static ActionDone done1a = new ActionDone(act1);33 private final static ActionDone done2 = new ActionDone(act2);34 private final static @NonNull ActionDone done1 = new ActionDone(act1); 35 private final static @NonNull ActionDone done1a = new ActionDone(act1); 36 private final static @NonNull ActionDone done2 = new ActionDone(act2); 34 37 35 38 @Override … … 45 48 } 46 49 47 @Before48 public void before() {49 50 }51 52 50 @Test 53 51 public void serializeAcceptTest() throws JsonProcessingException { 54 System.out.println(jackson.writeValueAsString(done1));52 //System.out.println(jackson.writeValueAsString(done1)); 55 53 assertEquals(actiondonestr, jackson.writeValueAsString(done1)); 56 54 } … … 58 56 @Test 59 57 public void deserializeAcceptTest() throws IOException { 60 Inform act = jackson.readValue(actiondonestr, Inform.class); 58 final @NonNull Inform act = jackson.readValue(actiondonestr, 59 Inform.class); 61 60 assertEquals(done1, act); 62 61 } -
events/src/test/java/geniusweb/inform/AgreementsTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 8 9 import java.util.HashSet; 9 10 import java.util.List; 11 import java.util.Map; 10 12 11 import org. junit.Before;13 import org.eclipse.jdt.annotation.NonNull; 12 14 import org.junit.Test; 15 import org.junit.internal.runners.JUnit4ClassRunner; 16 import org.junit.runner.RunWith; 13 17 14 18 import com.fasterxml.jackson.core.JsonProcessingException; … … 21 25 import tudelft.utilities.junit.GeneralTests; 22 26 27 @RunWith(JUnit4ClassRunner.class) 23 28 public class AgreementsTest extends GeneralTests<Agreements> { 24 private final ObjectMapper jackson = new ObjectMapper();29 private final @NonNull ObjectMapper jackson = new ObjectMapper(); 25 30 26 private static final PartyId id = new PartyId("party1");27 private static final PartyId id2 = new PartyId("party2");28 private final static Value VALUE1 = new DiscreteValue("value1");29 private static Bid bid = new Bid(31 private static final @NonNull PartyId id = new PartyId("party1"); 32 private static final @NonNull PartyId id2 = new PartyId("party2"); 33 private final static @NonNull Value VALUE1 = new DiscreteValue("value1"); 34 private static @NonNull Bid bid = new Bid( 30 35 Collections.singletonMap("issue1", VALUE1)); 31 private static Bid bid2 = new Bid(36 private static @NonNull Bid bid2 = new Bid( 32 37 Collections.singletonMap("issue2", VALUE1)); 33 38 34 private final String finishedstring = "{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}"; 39 private final @NonNull String finishedstring = "{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}"; 40 private final @NonNull String finishedstringpat = ".*party1.*issuevalues.*issue1.*value1.*"; 35 41 36 private final static Agreements agrees1 = new Agreements(42 private final static @NonNull Agreements agrees1 = new Agreements( 37 43 Collections.singletonMap(id, bid)); 38 private final static Agreements agrees1a = new Agreements(44 private final static @NonNull Agreements agrees1a = new Agreements( 39 45 Collections.singletonMap(id, bid)); 40 private final static Agreements agrees2 = new Agreements(46 private final static @NonNull Agreements agrees2 = new Agreements( 41 47 Collections.singletonMap(id2, bid)); 42 private final static Agreements agrees3 = new Agreements(48 private final static @NonNull Agreements agrees3 = new Agreements( 43 49 Collections.singletonMap(id, bid2)); 44 50 … … 56 62 } 57 63 58 @Before59 public void before() {60 61 }62 63 64 @Test 64 65 public void serializeAcceptTest() throws JsonProcessingException { 65 System.out.println(jackson.writeValueAsString(agrees1)); 66 assertEquals(finishedstring, jackson.writeValueAsString(agrees1)); 66 //System.out.println(jackson.writeValueAsString(agrees1)); 67 assertTrue( 68 jackson.writeValueAsString(agrees1).matches(finishedstringpat)); 67 69 } 68 70 69 71 @Test 70 72 public void deserializeAcceptTest() throws IOException { 71 Agreements act = jackson.readValue(finishedstring, Agreements.class); 73 final @NonNull Agreements act = jackson.readValue(finishedstring, 74 Agreements.class); 72 75 assertEquals(agrees1, act); 73 76 } 74 77 75 @SuppressWarnings("unused") 76 @Test 78 @Test(expected = NullPointerException.class) 77 79 public void testNull() { 78 new Agreements( );80 new Agreements((Map<@NonNull PartyId, @NonNull Bid>) getNull()); 79 81 } 80 82 … … 87 89 public void testWith() { 88 90 Agreements agrees = agrees1.with(agrees2); 89 assertEquals(bid, agrees.get Map().get(id));90 assertEquals(bid, agrees.get Map().get(id2));91 assertEquals(bid, agrees.getAgreements().get(id)); 92 assertEquals(bid, agrees.getAgreements().get(id2)); 91 93 } 92 94 93 95 @Test 94 96 public void testBidConstructor() { 95 Agreements agrees = new Agreements(bid,97 Agreements agrees = Agreements.create(bid, 96 98 new HashSet<PartyId>(Arrays.asList(id, id2))); 97 assertEquals(bid, agrees.get Map().get(id));98 assertEquals(bid, agrees.get Map().get(id2));99 assertEquals(bid, agrees.getAgreements().get(id)); 100 assertEquals(bid, agrees.getAgreements().get(id2)); 99 101 } 102 103 private Object getNull() { 104 return null; 105 } 106 100 107 } -
events/src/test/java/geniusweb/inform/FinishedTest.java
r52 r54 8 8 import java.util.List; 9 9 10 import org.eclipse.jdt.annotation.NonNull; 10 11 import org.junit.Before; 11 12 import org.junit.Test; 13 import org.junit.internal.runners.JUnit4ClassRunner; 14 import org.junit.runner.RunWith; 12 15 13 16 import com.fasterxml.jackson.core.JsonProcessingException; … … 20 23 import tudelft.utilities.junit.GeneralTests; 21 24 25 @RunWith(JUnit4ClassRunner.class) 22 26 public class FinishedTest extends GeneralTests<Finished> { 23 private final ObjectMapper jackson = new ObjectMapper();27 private final @NonNull ObjectMapper jackson = new ObjectMapper(); 24 28 25 private static final PartyId id = new PartyId("party1");26 private static final PartyId id2 = new PartyId("party2");27 private final static Value VALUE1 = new DiscreteValue("value1");28 private static Bid bid = new Bid(29 private static final @NonNull PartyId id = new PartyId("party1"); 30 private static final @NonNull PartyId id2 = new PartyId("party2"); 31 private final static @NonNull Value VALUE1 = new DiscreteValue("value1"); 32 private static @NonNull Bid bid = new Bid( 29 33 Collections.singletonMap("issue1", VALUE1)); 30 34 31 private final String finishedstring = "{\"Finished\":{\"agreements\":{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}}}";35 private final @NonNull String finishedstring = "{\"Finished\":{\"agreements\":{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}}}"; 32 36 33 private final static Agreements agrees1 = new Agreements(37 private final static @NonNull Agreements agrees1 = new Agreements( 34 38 Collections.singletonMap(id, bid)); 35 private final static Agreements agrees2 = new Agreements(39 private final static @NonNull Agreements agrees2 = new Agreements( 36 40 Collections.singletonMap(id2, bid)); 37 41 38 private final static Finished finished1 = new Finished(agrees1);39 private final static Finished finished1a = new Finished(agrees1);40 private final static Finished finished2 = new Finished(agrees2);42 private final static @NonNull Finished finished1 = new Finished(agrees1); 43 private final static @NonNull Finished finished1a = new Finished(agrees1); 44 private final static @NonNull Finished finished2 = new Finished(agrees2); 41 45 42 46 @Override … … 59 63 @Test 60 64 public void serializeAcceptTest() throws JsonProcessingException { 61 System.out.println(jackson.writeValueAsString(finished1));65 //System.out.println(jackson.writeValueAsString(finished1)); 62 66 assertEquals(finishedstring, jackson.writeValueAsString(finished1)); 63 67 } … … 65 69 @Test 66 70 public void deserializeAcceptTest() throws IOException { 67 Inform act = jackson.readValue(finishedstring, Inform.class); 71 final @NonNull Inform act = jackson.readValue(finishedstring, 72 Inform.class); 68 73 assertEquals(finished1, act); 69 74 } … … 71 76 @Test(expected = NullPointerException.class) 72 77 public void testNull() { 73 new Finished(null); 78 new Finished(nullFinish()); 79 } 80 81 private Agreements nullFinish() { 82 return null; 74 83 } 75 84 -
events/src/test/java/geniusweb/inform/OptInTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 9 10 import java.util.List; 10 11 12 import org.eclipse.jdt.annotation.NonNull; 11 13 import org.junit.Test; 14 import org.junit.internal.runners.JUnit4ClassRunner; 15 import org.junit.runner.RunWith; 12 16 13 17 import com.fasterxml.jackson.core.JsonParseException; … … 23 27 import tudelft.utilities.junit.GeneralTests; 24 28 29 @RunWith(JUnit4ClassRunner.class) 25 30 public class OptInTest extends GeneralTests<OptIn> { 31 private static final @NonNull ObjectMapper jackson = new ObjectMapper(); 26 32 27 private Bid bid1 = new Bid("iss", new DiscreteValue("val1")); 28 private Bid bid2 = new Bid("iss", new DiscreteValue("val2")); 29 private PartyId partyA = new PartyId("partyA"); 30 private PartyId partyB = new PartyId("partyB"); 33 private final static @NonNull Bid bid1 = new Bid( 34 Collections.singletonMap("iss", new DiscreteValue("val1"))); 35 private final static @NonNull Bid bid2 = new Bid( 36 Collections.singletonMap("iss", new DiscreteValue("val2"))); 37 private final static @NonNull PartyId partyA = new PartyId("partyA"); 38 private final static @NonNull PartyId partyB = new PartyId("partyB"); 31 39 32 private final Vote voteA1 = new Vote(partyA, bid1, 2, 9);33 private final Vote voteB1 = new Vote(partyB, bid1, 2, 9);34 private final Vote voteB2 = new Vote(partyB, bid2, 2, 9);40 private final static @NonNull Vote voteA1 = new Vote(partyA, bid1, 2, 9); 41 private final static @NonNull Vote voteB1 = new Vote(partyB, bid1, 2, 9); 42 private final static @NonNull Vote voteB2 = new Vote(partyB, bid2, 2, 9); 35 43 36 private Votes votesA = new Votes(partyA, Collections.singleton(voteA1)); 37 private Votes votesB = new Votes(partyB, 44 private final static @NonNull Votes votesA = new Votes(partyA, 45 Collections.singleton(voteA1)); 46 private final static @NonNull Votes votesB = new Votes(partyB, 38 47 new HashSet<>(Arrays.asList(voteB1, voteB2))); 39 48 40 private final OptIn optIn1 = new OptIn(Arrays.asList(votesA, votesB)); 41 private final OptIn optIn1a = new OptIn(Arrays.asList(votesA, votesB)); 42 private final OptIn optIn2 = new OptIn(Arrays.asList(votesA)); 49 private final static @NonNull OptIn optIn1 = new OptIn( 50 Arrays.asList(votesA, votesB)); 51 private final static @NonNull OptIn optIn1a = new OptIn( 52 Arrays.asList(votesA, votesB)); 53 private final static @NonNull OptIn optIn2 = new OptIn( 54 Arrays.asList(votesA)); 43 55 44 private String asJson = "{\"OptIn\":{\"votes\":[{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9}}]}},{\"Votes\":{\"actor\":\"partyB\",\"votes\":[{\"Vote\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val2\"}},\"minPower\":2,\"maxPower\":9}},{\"Vote\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9}}]}}]}}"; 56 private final static @NonNull String asJson = "{\"OptIn\":{\"votes\":[{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9}}]}},{\"Votes\":{\"actor\":\"partyB\",\"votes\":[{\"Vote\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val2\"}},\"minPower\":2,\"maxPower\":9}},{\"Vote\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9}}]}}]}}"; 57 private final static @NonNull String asJsonpat = ".*OptIn.*votes.*Votes.*actor.*partyA.*votes.*" 58 + "Vote.*actor.*partyA.*bid.*issuevalues.*iss.*val1.*minPower.*maxPower.*9.*" 59 + "Votes.*actor.*partyB.*votes" 60 + "((.*Vote.*actor.*partyB.*bid.*issuevalues.*iss.*val2.*minPower.*2.*maxPower.*9.*)|" 61 + "(.*Vote.*actor.*partyB.*bid.*issuevalues.*iss.*val1.*minPower.*2.*maxPower.*9.*))+.*"; 45 62 46 63 @Override … … 53 70 public List<String> getGeneralTestStrings() { 54 71 return Arrays.asList( 55 "OptIn.*Votes.*Vote.*partyA.*iss.*val1.*2.*Votes .*Vote.*partyB.*iss.*val2.*.*2.*Vote.*partyB.*iss.*val1.*2.*",72 "OptIn.*Votes.*Vote.*partyA.*iss.*val1.*2.*Votes((.*Vote.*partyB.*iss.*val2.*.*2)|(.*Vote.*partyB.*iss.*val1.*2))+.*", 56 73 "OptIn.*Votes.*Vote.*partyA.*iss.*val.*2.*"); 57 74 } … … 59 76 @Test 60 77 public void testSerialize() throws JsonProcessingException { 61 ObjectMapper jackson = new ObjectMapper();62 78 63 String json= jackson.writeValueAsString(optIn1);64 System.out.println(json);65 assert Equals(asJson, json);79 final @NonNull String jsonstr = jackson.writeValueAsString(optIn1); 80 //System.out.println(json); 81 assertTrue(jsonstr.matches(asJsonpat)); 66 82 } 67 83 … … 69 85 public void testDeserialize() 70 86 throws JsonParseException, JsonMappingException, IOException { 71 ObjectMapper jackson = new ObjectMapper(); 72 Inform p = jackson.readValue(asJson, Inform.class); 73 System.out.println(p); 87 final @NonNull Inform p = jackson.readValue(asJson, Inform.class); 88 //System.out.println(p); 74 89 assertEquals(optIn1, p); 75 90 } -
events/src/test/java/geniusweb/inform/OptInWithValueTest.java
r52 r54 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 4 5 5 6 import java.io.IOException; … … 9 10 import java.util.List; 10 11 12 import org.eclipse.jdt.annotation.NonNull; 11 13 import org.junit.Test; 14 import org.junit.internal.runners.JUnit4ClassRunner; 15 import org.junit.runner.RunWith; 12 16 13 17 import com.fasterxml.jackson.core.JsonParseException; … … 23 27 import tudelft.utilities.junit.GeneralTests; 24 28 29 @RunWith(JUnit4ClassRunner.class) 25 30 public class OptInWithValueTest extends GeneralTests<OptInWithValue> { 31 private static final @NonNull ObjectMapper jackson = new ObjectMapper(); 26 32 27 private Bid bid1 = new Bid("iss", new DiscreteValue("val1")); 28 private Bid bid2 = new Bid("iss", new DiscreteValue("val2")); 29 private PartyId partyA = new PartyId("partyA"); 30 private PartyId partyB = new PartyId("partyB"); 33 private static final @NonNull Bid bid1 = new Bid( 34 Collections.singletonMap("iss", new DiscreteValue("val1"))); 35 private static final @NonNull Bid bid2 = new Bid( 36 Collections.singletonMap("iss", new DiscreteValue("val2"))); 37 private static final @NonNull PartyId partyA = new PartyId("partyA"); 38 private static final @NonNull PartyId partyB = new PartyId("partyB"); 31 39 32 private final VoteWithValue voteA1 = new VoteWithValue(partyA, bid1, 2, 9,33 100);34 private final VoteWithValue voteB1 = new VoteWithValue(partyB, bid1, 2, 9,35 60);36 private final VoteWithValue voteB2 = new VoteWithValue(partyB, bid2, 2, 9,37 40);40 private static final @NonNull VoteWithValue voteA1 = new VoteWithValue( 41 partyA, bid1, 2, 9, 100); 42 private static final @NonNull VoteWithValue voteB1 = new VoteWithValue( 43 partyB, bid1, 2, 9, 60); 44 private static final @NonNull VoteWithValue voteB2 = new VoteWithValue( 45 partyB, bid2, 2, 9, 40); 38 46 39 private VotesWithValue votesA = new VotesWithValue(partyA,40 Collections.singleton(voteA1));41 private VotesWithValue votesB = new VotesWithValue(partyB,42 new HashSet<>(Arrays.asList(voteB1, voteB2)));47 private static final @NonNull VotesWithValue votesA = new VotesWithValue( 48 partyA, Collections.singleton(voteA1)); 49 private static final @NonNull VotesWithValue votesB = new VotesWithValue( 50 partyB, new HashSet<>(Arrays.asList(voteB1, voteB2))); 43 51 44 private final OptInWithValue optIn1 = new OptInWithValue(52 private static final @NonNull OptInWithValue optIn1 = new OptInWithValue( 45 53 Arrays.asList(votesA, votesB)); 46 private final OptInWithValue optIn1a = new OptInWithValue(54 private static final @NonNull OptInWithValue optIn1a = new OptInWithValue( 47 55 Arrays.asList(votesA, votesB)); 48 private final OptInWithValue optIn2 = new OptInWithValue(56 private static final @NonNull OptInWithValue optIn2 = new OptInWithValue( 49 57 Arrays.asList(votesA)); 50 58 51 private String asJson = "{\"OptInWithValue\":{\"votes\":[{\"VotesWithValue\":{\"actor\":\"partyA\",\"votes\":[{\"VoteWithValue\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9,\"value\":100}}]}},{\"VotesWithValue\":{\"actor\":\"partyB\",\"votes\":[{\"VoteWithValue\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9,\"value\":60}},{\"VoteWithValue\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val2\"}},\"minPower\":2,\"maxPower\":9,\"value\":40}}]}}]}}"; 59 private static final @NonNull String asJson = "{\"OptInWithValue\":{\"votes\":[{\"VotesWithValue\":{\"actor\":\"partyA\",\"votes\":[{\"VoteWithValue\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9,\"value\":100}}]}},{\"VotesWithValue\":{\"actor\":\"partyB\",\"votes\":[{\"VoteWithValue\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}},\"minPower\":2,\"maxPower\":9,\"value\":60}},{\"VoteWithValue\":{\"actor\":\"partyB\",\"bid\":{\"issuevalues\":{\"iss\":\"val2\"}},\"minPower\":2,\"maxPower\":9,\"value\":40}}]}}]}}"; 60 private static final @NonNull String asJsonpat = ".*OptInWithValue.*votes.*VotesWithValue.*actor.*partyA.*" 61 + "votes.*" 62 + "VoteWithValue.*actor.*partyA.*bid.*issuevalues.*iss.*val1.*minPower.*2.*maxPower.*9.*value.*100.*" 63 + "VotesWithValue.*actor.*partyB.*votes.*" 64 + "((.*VoteWithValue.*actor.*partyB.*bid.*issuevalues.*iss.*val1.*minPower.*2.*maxPower.*9.*value.*60)|" 65 + "(.*VoteWithValue.*actor.*partyB.*bid.*issuevalues.*iss.*val2.*minPower.*2.*maxPower.*9.*value.*40))+.*"; 52 66 53 67 @Override … … 60 74 public List<String> getGeneralTestStrings() { 61 75 return Arrays.asList( 62 "OptInWithValue.*VotesWithValue.*partyA.*VoteWithValue.*partyA.*iss.*val1.*2.*VotesWithValue.*partyB.*VoteWithValue.*partyB.*iss.*val1.*.*2.*VoteWithValue.*partyB.*iss.*val2.*2.*", 76 "OptInWithValue.*VotesWithValue.*partyA.*VoteWithValue.*partyA.*iss.*val1.*2.*VotesWithValue.*partyB" 77 + "((.*VoteWithValue.*partyB.*iss.*val1.*.*2)|(.*VoteWithValue.*partyB.*iss.*val2.*2))+.*", 63 78 "OptIn.*Votes.*Vote.*partyA.*iss.*val.*2.*"); 64 79 } … … 66 81 @Test 67 82 public void testSerialize() throws JsonProcessingException { 68 ObjectMapper jackson = new ObjectMapper();69 83 70 String json= jackson.writeValueAsString(optIn1);71 System.out.println(json);72 assert Equals(asJson, json);84 final @NonNull String jsonstr = jackson.writeValueAsString(optIn1); 85 //System.out.println(json); 86 assertTrue(jsonstr.matches(asJsonpat)); 73 87 } 74 88 … … 76 90 public void testDeserialize() 77 91 throws JsonParseException, JsonMappingException, IOException { 78 ObjectMapper jackson = new ObjectMapper(); 79 Inform p = jackson.readValue(asJson, Inform.class); 80 System.out.println(p); 92 final @NonNull Inform p = jackson.readValue(asJson, Inform.class); 93 //System.out.println(p); 81 94 assertEquals(optIn1, p); 82 95 } -
events/src/test/java/geniusweb/inform/SettingsTest.java
r52 r54 7 7 import java.net.URISyntaxException; 8 8 import java.util.Arrays; 9 import java.util.Collections; 9 10 import java.util.Date; 10 11 import java.util.HashMap; … … 12 13 import java.util.Map; 13 14 15 import org.eclipse.jdt.annotation.NonNull; 14 16 import org.junit.Before; 15 17 import org.junit.Test; 18 import org.junit.internal.runners.JUnit4ClassRunner; 19 import org.junit.runner.RunWith; 16 20 17 21 import com.fasterxml.jackson.core.JsonParseException; … … 28 32 import tudelft.utilities.junit.GeneralTests; 29 33 34 @RunWith(JUnit4ClassRunner.class) 30 35 public class SettingsTest extends GeneralTests<Settings> { 31 36 32 private PartyId id = new PartyId("party1");33 private PartyId id2 = new PartyId("party2");37 private final @NonNull PartyId id = new PartyId("party1"); 38 private final @NonNull PartyId id2 = new PartyId("party2"); 34 39 35 private final String asJson = "{\"Settings\":"40 private final @NonNull String asJson = "{\"Settings\":" 36 41 + "{\"id\":\"party1\",\"profile\":\"ws:profile1\"," 37 42 + "\"protocol\":\"ws:localhost/protocol1\"," 38 43 + "\"progress\":{\"ProgressRounds\":{\"duration\":10,\"currentRound\":0,\"endtime\":999}}," 39 44 + "\"parameters\":{}}}"; 45 private final @NonNull Date date = new Date(999); 46 private final static @NonNull ObjectMapper jackson = new ObjectMapper(); 40 47 41 48 private Settings negoinfo1, negoinfo1a; 42 49 private Settings negoinfo2, negoinfo3, negoinfo4, negoinfo5; 43 private final Date date = new Date(999);44 private final static ObjectMapper jackson = new ObjectMapper();45 50 46 51 @Before … … 48 53 JsonMappingException, IOException { 49 54 // we can't mock because we want to test the serializer 50 ProfileRef profile1 = new ProfileRef(new URI("ws:profile1")); 55 final @NonNull ProfileRef profile1 = new ProfileRef( 56 new URI("ws:profile1")); 51 57 // jackson.readValue(serialized, Profile.class); 52 58 53 ProtocolRef protocol1 = new ProtocolRef(59 final @NonNull ProtocolRef protocol1 = new ProtocolRef( 54 60 new URI("ws:localhost/protocol1")); 55 ProtocolRef protocol1a = new ProtocolRef(61 final @NonNull ProtocolRef protocol1a = new ProtocolRef( 56 62 new URI("ws:localhost/protocol1")); 57 ProtocolRef protocol2 = new ProtocolRef(63 final @NonNull ProtocolRef protocol2 = new ProtocolRef( 58 64 new URI("ws:localhost/protocol2")); 59 ProgressRounds progress1 = new ProgressRounds(10, 0, date); 60 ProgressRounds progress1a = new ProgressRounds(10, 0, date); 61 ProgressRounds progress2 = new ProgressRounds(12, 0, date); 65 final @NonNull ProgressRounds progress1 = new ProgressRounds(10, 0, 66 date); 67 final @NonNull ProgressRounds progress1a = new ProgressRounds(10, 0, 68 date); 69 final @NonNull ProgressRounds progress2 = new ProgressRounds(12, 0, 70 date); 62 71 63 Parameters settings1 = new Parameters(); 64 Parameters settings2 = new Parameters().with("a", 1); 72 final @NonNull Parameters settings1 = new Parameters( 73 Collections.emptyMap()); 74 final @NonNull Parameters settings2 = settings1.with("a", 1); 65 75 66 76 negoinfo1 = new Settings(id, profile1, protocol1, progress1, settings1); … … 98 108 @Test(expected = IllegalArgumentException.class) 99 109 public void nullTest() throws URISyntaxException { 100 new PartyRef( (URI) null);110 new PartyRef(nullUri()); 101 111 } 102 112 … … 104 114 public void testSerialize() throws JsonProcessingException { 105 115 106 String json= jackson.writeValueAsString(negoinfo1);107 System.out.println(json);108 assertEquals(asJson, json );116 final @NonNull String jsonobj = jackson.writeValueAsString(negoinfo1); 117 //System.out.println(json); 118 assertEquals(asJson, jsonobj); 109 119 } 110 120 … … 112 122 public void testDeserialize() 113 123 throws JsonParseException, JsonMappingException, IOException { 114 Settings p = (Settings) jackson.readValue(asJson, Inform.class); 115 System.out.println(p); 124 final @NonNull Settings p = (Settings) jackson.readValue(asJson, 125 Inform.class); 126 //System.out.println(p); 116 127 assertEquals(negoinfo1, p); 117 128 } … … 120 131 public void testGeneralDict() 121 132 throws JsonParseException, JsonMappingException, IOException { 122 Map val = jackson.readValue("{\"a\":0.3,\"b\":{\"x\":3},\"c\":[1,2,3]}", 123 HashMap.class); 124 System.out.println(val); 133 final @NonNull Map val = jackson.readValue( 134 "{\"a\":0.3,\"b\":{\"x\":3},\"c\":[1,2,3]}", HashMap.class); 135 //System.out.println(val); 136 } 137 138 private URI nullUri() { 139 return null; 125 140 } 126 141 -
events/src/test/java/geniusweb/inform/VotingTest.java
r52 r54 9 9 import java.util.Map; 10 10 11 import org.eclipse.jdt.annotation.NonNull; 11 12 import org.junit.Test; 13 import org.junit.internal.runners.JUnit4ClassRunner; 14 import org.junit.runner.RunWith; 12 15 13 16 import com.fasterxml.jackson.core.JsonParseException; … … 22 25 import tudelft.utilities.junit.GeneralTests; 23 26 27 @RunWith(JUnit4ClassRunner.class) 24 28 public class VotingTest extends GeneralTests<Voting> { 29 private final @NonNull ObjectMapper jackson = new ObjectMapper(); 25 30 26 private PartyId party1 = new PartyId("party1"); 27 private Bid bid1 = new Bid("iss", new DiscreteValue("val1")); 28 private Bid bid2 = new Bid("iss", new DiscreteValue("val2")); 31 private final @NonNull PartyId party1 = new PartyId("party1"); 32 private final @NonNull Bid bid1 = new Bid( 33 Collections.singletonMap("iss", new DiscreteValue("val1"))); 34 private final @NonNull Bid bid2 = new Bid( 35 Collections.singletonMap("iss", new DiscreteValue("val2"))); 29 36 30 private Map<PartyId, Integer> powers1 = Collections.singletonMap(party1, 2); 31 private Map<PartyId, Integer> powers2 = Collections.singletonMap(party1, 3); 37 private final @NonNull Map<@NonNull PartyId, @NonNull Integer> powers1 = Collections 38 .singletonMap(party1, 2); 39 private final @NonNull Map<@NonNull PartyId, @NonNull Integer> powers2 = Collections 40 .singletonMap(party1, 3); 32 41 33 private final Voting voting1 = new Voting(42 private final @NonNull Voting voting1 = new Voting( 34 43 Arrays.asList(new Offer(party1, bid1)), powers1); 35 private final Voting voting1a = new Voting(44 private final @NonNull Voting voting1a = new Voting( 36 45 Arrays.asList(new Offer(party1, bid1)), powers1); 37 private final Voting voting2 = new Voting(46 private final @NonNull Voting voting2 = new Voting( 38 47 Arrays.asList(new Offer(party1, bid2)), powers1); 39 private final Voting voting3 = new Voting(48 private final @NonNull Voting voting3 = new Voting( 40 49 Arrays.asList(new Offer(party1, bid1)), powers2); 41 50 … … 57 66 @Test 58 67 public void testSerialize() throws JsonProcessingException { 59 ObjectMapper jackson = new ObjectMapper();60 68 61 String json= jackson.writeValueAsString(voting1);62 System.out.println(json);63 assertEquals(asJson, json );69 final @NonNull String jsonstr = jackson.writeValueAsString(voting1); 70 //System.out.println(json); 71 assertEquals(asJson, jsonstr); 64 72 } 65 73 … … 67 75 public void testDeserialize() 68 76 throws JsonParseException, JsonMappingException, IOException { 69 ObjectMapper jackson = new ObjectMapper(); 70 Inform p = jackson.readValue(asJson, Inform.class); 71 System.out.println(p); 77 final @NonNull Inform p = jackson.readValue(asJson, Inform.class); 78 //System.out.println(p); 72 79 assertEquals(voting1, p); 73 80 } -
events/src/test/java/geniusweb/inform/YourTurnTest.java
r52 r54 4 4 5 5 import java.io.IOException; 6 import java.net.URISyntaxException;7 6 import java.util.Arrays; 8 7 import java.util.List; 9 8 10 import org. junit.Before;9 import org.eclipse.jdt.annotation.NonNull; 11 10 import org.junit.Test; 11 import org.junit.internal.runners.JUnit4ClassRunner; 12 import org.junit.runner.RunWith; 12 13 13 14 import com.fasterxml.jackson.core.JsonParseException; … … 18 19 import tudelft.utilities.junit.GeneralTests; 19 20 21 class YourTurnAlt extends YourTurn { 22 @Override 23 public int hashCode() { 24 return 2; 25 } 26 } 27 28 @RunWith(JUnit4ClassRunner.class) 20 29 public class YourTurnTest extends GeneralTests<YourTurn> { 30 private final static @NonNull ObjectMapper jackson = new ObjectMapper(); 21 31 22 private YourTurn yourturn1, yourturn1b; 32 private final @NonNull YourTurn yourturn1 = new YourTurn(), 33 yourturn1b = new YourTurn(); 23 34 24 private String asJson = "{\"YourTurn\":{}}";35 private final static @NonNull String asJson = "{\"YourTurn\":{}}"; 25 36 26 private YourTurn yourturnb; 27 28 @Before 29 public void before() throws URISyntaxException { 30 31 yourturn1 = new YourTurn(); 32 yourturn1b = new YourTurn(); 33 yourturnb = new YourTurn() { 34 @Override 35 public int hashCode() { 36 return 2; 37 } 38 }; 39 } 37 private final @NonNull YourTurn yourturnb = new YourTurnAlt(); 40 38 41 39 @Override … … 52 50 @Test 53 51 public void testSerialize() throws JsonProcessingException { 54 ObjectMapper jackson = new ObjectMapper();55 52 56 String json= jackson.writeValueAsString(yourturn1);57 System.out.println(json);58 assertEquals(asJson, json );53 final @NonNull String jsonstr = jackson.writeValueAsString(yourturn1); 54 //System.out.println(json); 55 assertEquals(asJson, jsonstr); 59 56 } 60 57 … … 62 59 public void testDeserialize() 63 60 throws JsonParseException, JsonMappingException, IOException { 64 ObjectMapper jackson = new ObjectMapper();65 YourTurn p = (YourTurn) jackson.readValue(asJson,Inform.class);66 System.out.println(p);61 final @NonNull YourTurn p = (YourTurn) jackson.readValue(asJson, 62 Inform.class); 63 //System.out.println(p); 67 64 assertEquals(yourturn1, p); 68 65 }
Note:
See TracChangeset
for help on using the changeset viewer.