Changeset 54 for events/src


Ignore:
Timestamp:
Jul 23, 2025, 10:16:55 AM (7 weeks ago)
Author:
ruud
Message:

Modifications for automatic java to python conversion. Overloaded methods now have different names.

Location:
events/src
Files:
53 edited

Legend:

Unmodified
Added
Removed
  • events/src/main/java/geniusweb/actions/AbstractAction.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonAutoDetect;
     
    911public class AbstractAction implements Action {
    1012
    11         private PartyId actor;
     13        private @NonNull final PartyId actor;
    1214
    1315        /**
    1416         *
    15          * @param id the {@link PartyId} of the party executing the action. Usually
    16          *           the negotiation system will check that parties only use their
    17          *           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.
    1820         */
    1921        @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;
    2226        }
    2327
    2428        @Override
    25         public PartyId getActor() {
     29        public @NonNull PartyId getActor() {
    2630                return actor;
    2731        }
  • events/src/main/java/geniusweb/actions/Accept.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    1416
    1517        /**
    16          * @param id  the accepting party.
     18         * @param actor  the accepting party.
    1719         * @param bid the bid that was offered before (usually by some other Party )
    1820         */
    1921        @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);
    2325        }
    2426
    2527        @Override
    26         public String toString() {
    27                 return "Accept[" + getActor() + "," + getBid() + "]";
     28        public @NonNull String toString() {
     29                return "Accept[" + getActor().toString() + "," + getBid().toString()
     30                                + "]";
    2831        }
    2932
  • events/src/main/java/geniusweb/actions/Action.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonSubTypes;
     
    2729         * @return the {@link Id} of the actor of this action.
    2830         */
     31        @NonNull
    2932        PartyId getActor();
    3033
  • events/src/main/java/geniusweb/actions/ActionWithBid.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    79
    810/**
    9  * An {@link Action} containing a bid. Note that the presense of a bid does not
     11 * An {@link Action} containing a bid. Note that the presence of a bid does not
    1012 * necessarily mean that an offer was placed for this bid.
    1113 *
    1214 */
    1315public abstract class ActionWithBid extends AbstractAction {
    14         private Bid bid;
     16        private @NonNull Bid bid;
    1517
    1618        @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");
    2024                this.bid = bid;
    2125        }
     
    2529         * @return the {@link Bid} that this action is about.
    2630         */
    27         public Bid getBid() {
     31        public @NonNull Bid getBid() {
    2832                return bid;
    2933        }
  • events/src/main/java/geniusweb/actions/Comparison.java

    r52 r54  
    11package geniusweb.actions;
    22
     3import java.util.ArrayList;
    34import java.util.List;
     5
     6import org.eclipse.jdt.annotation.NonNull;
    47
    58import com.fasterxml.jackson.annotation.JsonCreator;
     
    1619public class Comparison extends ActionWithBid {
    1720
    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<>();
    2023
    2124        /**
    22          * @param id     the party id that made this comparison
     25         * @param actor  the party id that made this comparison
    2326         * @param bid    the bid that is compared wiht
    2427         * @param better list of bids that are better than bid
     
    2629         */
    2730        @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);
    3336                if (bid == null || better == null || worse == null)
    3437                        throw new IllegalArgumentException(
    3538                                        "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);
    3841        }
    3942
     
    4245         *
    4346         */
    44         public List<Bid> getBetter() {
     47        public @NonNull List<@NonNull Bid> getBetter() {
    4548                return better;
    4649        }
     
    5154         */
    5255
    53         public List<Bid> getWorse() {
     56        public @NonNull List<@NonNull Bid> getWorse() {
    5457                return worse;
    5558        }
    5659
    5760        @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                                + "]";
    6165        }
    6266
  • events/src/main/java/geniusweb/actions/ElicitComparison.java

    r52 r54  
    44import java.util.LinkedList;
    55import java.util.List;
     6
     7import org.eclipse.jdt.annotation.NonNull;
    68
    79import com.fasterxml.jackson.annotation.JsonCreator;
     
    1517 */
    1618public class ElicitComparison extends ActionWithBid {
    17         private final List<Bid> options = new LinkedList<>();
     19        private final @NonNull List<@NonNull Bid> options = new LinkedList<>();
    1820
    1921        /**
    20          * @param id   the eliciting party.
     22         * @param actor   the eliciting party.
    2123         * @param bid  the bid to compare the options with
    22          * @param opts the available options that may be chosen from. Must not be
     24         * @param options the available options that may be chosen from. Must not be
    2325         *             null and must have at least 2 options.
    2426         */
    2527        @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);
    3032                if (bid == null)
    3133                        throw new IllegalArgumentException(
    3234                                        "Bid to compare with must not be null");
    33                 if (opts == null || opts.size() < 1) {
     35                if (options == null || options.size() < 1) {
    3436                        throw new IllegalArgumentException(
    3537                                        "opts must not be null and have at least 1 option");
    3638                }
    37                 this.options.addAll(opts);
     39                this.options.addAll(options);
    3840        }
    3941
     
    4244         * @return the list of {@link Bid}s to compare {@link #getBid()} with
    4345         */
    44         public List<Bid> getOptions() {
     46        public @NonNull List<@NonNull Bid> getOptions() {
    4547                return Collections.unmodifiableList(options);
    4648        }
     
    7375        @Override
    7476        public String toString() {
    75                 return "ElicitComparison[" + getActor() + "," + getBid() + "," + options
    76                                 + "]";
     77                return "ElicitComparison[" + getActor().toString() + ","
     78                                + getBid().toString() + "," + options.toString() + "]";
    7779
    7880        }
  • events/src/main/java/geniusweb/actions/EndNegotiation.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    1113
    1214        @JsonCreator
    13         public EndNegotiation(@JsonProperty("actor") PartyId id) {
    14                 super(id);
     15        public EndNegotiation(@JsonProperty("actor") @NonNull PartyId actor) {
     16                super(actor);
    1517        }
    1618
    1719        @Override
    18         public String toString() {
    19                 return "EndNegotiation[" + getActor() + "]";
     20        public @NonNull String toString() {
     21                return "EndNegotiation[" + getActor().toString() + "]";
    2022        }
    2123
  • events/src/main/java/geniusweb/actions/FileLocation.java

    r52 r54  
    55import java.nio.file.Paths;
    66import java.util.UUID;
     7
     8import org.eclipse.jdt.annotation.NonNull;
    79
    810import com.fasterxml.jackson.annotation.JsonCreator;
     
    2729public class FileLocation {
    2830
    29         @JsonValue
    30         private final UUID name;
     31        private final @NonNull UUID name;
    3132
    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();
    3638
    3739        /**
     
    3941         *             bad filenames like /.. or C:) Use {@link #FileLocation()} to
    4042         *             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.
    4245         */
    4346        @JsonCreator
    4447        public FileLocation(UUID name) {
     48                if (name == null)
     49                        name = UUID.randomUUID();
    4550                if (!rootfolder.exists()) {
    4651                        rootfolder.mkdir();
    47                         System.out
    48                                         .println("created FileLocation root dir at " + rootfolder);
     52                        //System.out.println("created FileLocation root dir at " + rootfolder);
    4953                }
    5054
     
    5256        }
    5357
    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;
    6661        }
    6762
     
    7469         *         folder inside tomcat.
    7570         */
    76         public File getFile() {
     71        public @NonNull File getFile() {
    7772                return Paths.get(TMP, GENIUSWEB, name.toString()).toFile();
    7873        }
    7974
    8075        @Override
    81         public String toString() {
    82                 return "FileLocation[" + name + "]";
     76        public @NonNull String toString() {
     77                return "FileLocation[" + name.toString() + "]";
    8378        }
    8479
  • events/src/main/java/geniusweb/actions/LearningDone.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    57
    68/**
    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.
    811 *
    912 */
    10 public class LearningDone extends AbstractAction { 
     13public class LearningDone extends AbstractAction {
    1114        @JsonCreator
    12         public LearningDone(@JsonProperty("actor") PartyId id) {
    13                 super(id);
     15        public LearningDone(@JsonProperty("actor") @NonNull PartyId actor) {
     16                super(actor);
    1417        }
    1518
    1619        @Override
    17         public String toString() {
    18                 return "LearningDone[" + getActor() + "]";
     20        public @NonNull String toString() {
     21                return "LearningDone[" + getActor().toString() + "]";
    1922        }
    2023}
  • events/src/main/java/geniusweb/actions/Offer.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    1416
    1517        @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);
    1921        }
    2022
    2123        @Override
    22         public String toString() {
    23                 return "Offer[" + getActor() + "," + getBid() + "]";
     24        public @NonNull String toString() {
     25                return "Offer[" + getActor().toString() + "," + getBid().toString()
     26                                + "]";
    2427        }
    2528
  • events/src/main/java/geniusweb/actions/PartyId.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonValue;
     
    1416 */
    1517public final class PartyId {
    16         @JsonValue
    17         private final String name;
     18        private final @NonNull String name;
    1819
    1920        /**
     
    2223         *             letters, digits or _.
    2324         */
    24         public PartyId(String name) {
     25        public PartyId(@NonNull String name) {
    2526                if (name == null || !name.matches("[a-zA-Z]\\w*")) {
    2627                        throw new IllegalArgumentException("name '" + name
     
    3031        }
    3132
    32         public String getName() {
     33        @JsonValue
     34        public @NonNull String getName() {
    3335                return name;
    3436        }
    3537
    3638        @Override
    37         public String toString() {
     39        public @NonNull String toString() {
    3840                return name;
    3941        }
  • events/src/main/java/geniusweb/actions/Vote.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    1113 */
    1214public 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;
    1517
    1618        /**
     
    2628         */
    2729        @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) {
    3234                super(actor, bid);
    3335                this.minPower = minPower;
     
    4547         *         valid.
    4648         */
    47         public Integer getMinPower() {
     49        public @NonNull Integer getMinPower() {
    4850                return minPower;
    4951        }
     
    5557         */
    5658
    57         public Integer getMaxPower() {
     59        public @NonNull Integer getMaxPower() {
    5860                return maxPower;
    5961        }
    6062
    6163        @Override
    62         public String toString() {
    63                 return "Vote[" + getActor() + "," + getBid() + "," + minPower + ","
    64                                 + maxPower + "]";
     64        public @NonNull String toString() {
     65                return "Vote[" + getActor().toString() + "," + getBid().toString() + ","
     66                                + minPower.toString() + "," + maxPower.toString() + "]";
    6567        }
    6668
  • events/src/main/java/geniusweb/actions/VoteWithValue.java

    r52 r54  
    11package geniusweb.actions;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    1113 */
    1214public 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;
    1618
    1719        /**
    18          * @param id       the {@link PartyId} that does the action
     20         * @param actor       the {@link PartyId} that does the action
    1921         * @param bid      the bid that is voted on
    2022         * @param minPower the minimum power this bid must get in order for the vote
     
    3133         */
    3234        @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);
    4241                if (value < 1 || value > 100)
    4342                        throw new IllegalArgumentException(
     
    4847                                        "Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower");
    4948                }
     49                this.minPower = minPower;
     50                this.maxPower = maxPower;
     51                this.value = value;
     52
    5053        }
    5154
     
    5558         *         valid.
    5659         */
    57         public Integer getMinPower() {
     60        public @NonNull Integer getMinPower() {
    5861                return minPower;
    5962        }
     
    6467         *         valid.
    6568         */
    66         public Integer getMaxPower() {
     69        public @NonNull Integer getMaxPower() {
    6770                return maxPower;
    6871        }
     
    7477         *
    7578         */
    76         public Integer getValue() {
     79        public @NonNull Integer getValue() {
    7780                return value;
    7881        }
    7982
    8083        @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() + "]";
    8488        }
    8589
  • events/src/main/java/geniusweb/actions/Votes.java

    r52 r54  
    66import java.util.List;
    77import java.util.Set;
     8
     9import org.eclipse.jdt.annotation.NonNull;
    810
    911import com.fasterxml.jackson.annotation.JsonCreator;
     
    1719 */
    1820public class Votes extends AbstractAction {
    19         private final Set<Vote> votes;
     21        private final @NonNull Set<@NonNull Vote> votes;
    2022
    2123        /**
     
    2830         */
    2931        @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) {
    3234                super(actor);
    3335                this.votes = new HashSet<>(votes);
     
    3537                        throw new NullPointerException("votes must be not null");
    3638
    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) {
    3941                        if (!vote.getActor().equals(actor))
    4042                                throw new IllegalArgumentException("All votes must come from "
    41                                                 + actor + " but found " + vote);
     43                                                + actor.toString() + " but found " + vote.toString());
    4244
    43                         Bid bid = vote.getBid();
     45                        final @NonNull Bid bid = vote.getBid();
    4446                        if (votedBids.contains(bid))
    4547                                throw new IllegalArgumentException(
    46                                                 "Votes contains multiple Vote's for " + bid);
     48                                                "Votes contains multiple Vote's for " + bid.toString());
    4749                        votedBids.add(bid);
    4850                }
     
    5860         * @return true iff this extends the otherVotes.
    5961         */
    60         public boolean isExtending(Votes otherVotes) {
     62        public boolean isExtending(@NonNull Votes otherVotes) {
    6163                if (!otherVotes.getActor().equals(getActor()))
    6264                        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());
    6567                        if (myvote == null || myvote.getMinPower() > vote.getMinPower()
    6668                                        || myvote.getMaxPower() < vote.getMaxPower())
     
    7678         */
    7779        public Vote getVote(Bid bid) {
    78                 for (Vote vote : votes) {
     80                for (final @NonNull Vote vote : votes) {
    7981                        if (vote.getBid().equals(bid))
    8082                                return vote;
     
    8385        }
    8486
    85         public Set<Vote> getVotes() {
     87        public @NonNull Set<@NonNull Vote> getVotes() {
    8688                return Collections.unmodifiableSet(votes);
    8789        }
     
    113115
    114116        @Override
    115         public String toString() {
    116                 return "Votes[" + getActor() + "," + votes + "]";
     117        public @NonNull String toString() {
     118                return "Votes[" + getActor().toString() + "," + votes.toString() + "]";
    117119        }
    118120}
  • events/src/main/java/geniusweb/actions/VotesWithValue.java

    r52 r54  
    22
    33import java.util.Collections;
     4import java.util.HashSet;
    45import java.util.Map;
    56import java.util.Map.Entry;
     
    78import java.util.Set;
    89import java.util.stream.Collectors;
     10
     11import org.eclipse.jdt.annotation.NonNull;
    912
    1013import com.fasterxml.jackson.annotation.JsonCreator;
     
    1821 */
    1922public class VotesWithValue extends AbstractAction {
    20         private final Set<VoteWithValue> votes;
     23        private final @NonNull Set<@NonNull VoteWithValue> votes = new HashSet<>();
    2124
    2225        /**
    2326         *
    24          * @param id    party id
     27         * @param actor party id
    2528         * @param votes the {@link Vote}s that the party can agree on, if the
    2629         *              condition of the Vote holds. Every {@link Vote#getActor()}
     
    2831         */
    2932        @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);
    3436                if (votes == null)
    3537                        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)) {
    3840                                throw new IllegalArgumentException("All votes must come from "
    39                                                 + id + " but found " + vote);
     41                                                + actor.toString() + " but found " + vote.toString());
    4042                        }
    4143                }
     44                /*#PY
     45                 * if sum( [ v.getValue() for v in votes] ) != 100:
     46                 *   raise ValueError("Sum of the placed votes must be 100")
     47                 */
    4248                if (votes.stream().map(v -> v.getValue()).reduce(0,
    4349                                Integer::sum) != 100)
     
    4551                                        "Sum of the placed votes must be 100");
    4652                // 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                 */
    5064                Optional<Entry<Bid, Long>> nonunique = counts.entrySet().stream()
    5165                                .filter(entry -> entry.getValue() > 1).findAny();
     
    5367                        throw new IllegalArgumentException(
    5468                                        "Votes contains multiple Vote's for "
    55                                                         + nonunique.get().getKey());
     69                                                        + nonunique.get().getKey().toString());
     70                this.votes.addAll(votes);
    5671        }
    5772
     
    6580         * @return true iff this extends the otherVotes.
    6681         */
    67         public boolean isExtending(VotesWithValue otherVotes) {
     82        public boolean isExtending(@NonNull VotesWithValue otherVotes) {
    6883                if (!otherVotes.getActor().equals(getActor()))
    6984                        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());
    7287                        if (myvote == null || myvote.getMinPower() > vote.getMinPower()
    7388                                        || myvote.getMaxPower() < vote.getMaxPower())
     
    8297         * @return myvote for bid, or null if no vote for that bid;
    8398         */
    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) {
    86101                        if (vote.getBid().equals(bid))
    87102                                return vote;
     
    90105        }
    91106
    92         public Set<VoteWithValue> getVotes() {
     107        public @NonNull Set<@NonNull VoteWithValue> getVotes() {
    93108                return Collections.unmodifiableSet(votes);
    94109        }
     
    120135
    121136        @Override
    122         public String toString() {
    123                 return "VotesWithValue[" + getActor() + "," + votes + "]";
     137        public @NonNull String toString() {
     138                return "VotesWithValue[" + getActor().toString() + ","
     139                                + votes.toString() + "]";
    124140        }
    125141}
  • events/src/main/java/geniusweb/events/AbstractEvent.java

    r52 r54  
    11package geniusweb.events;
     2
     3import org.eclipse.jdt.annotation.NonNull;
     4
     5import com.fasterxml.jackson.annotation.JsonCreator;
     6import com.fasterxml.jackson.annotation.JsonProperty;
    27
    38public abstract class AbstractEvent implements NegotiationEvent {
    49
    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        }
    626
    727        @Override
    8         public Long getTime() {
     28        public @NonNull Long getTime() {
    929                return time;
    1030        }
    1131
    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 
    2632        @Override
    27         public String toString() {
    28                 return this.getClass().getSimpleName() + "[" + time + "]";
     33        public @NonNull String toString() {
     34                return this.getClass().getSimpleName() + "[" + time.toString() + "]";
    2935        }
    3036
  • events/src/main/java/geniusweb/events/ActionEvent.java

    r52 r54  
    11package geniusweb.events;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    1214public class ActionEvent extends AbstractEvent {
    1315
    14         private final Action action;
     16        private final @NonNull Action action;
    1517
    1618        /**
     
    2123         */
    2224        @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) {
    2527                super(time);
    26                 if (action == null) {
     28                if (action == null)
    2729                        throw new IllegalArgumentException("Action must not be null");
    28                 }
    2930                this.action = action;
    3031        }
     
    3435         * @return action done by some party in the system.
    3536         */
    36         public Action getAction() {
     37        public @NonNull Action getAction() {
    3738                return action;
    3839        }
    3940
    4041        @Override
    41         public String toString() {
    42                 return this.getClass().getSimpleName() + "[" + getTime() + "," + action
    43                                 + "]";
     42        public @NonNull String toString() {
     43                return this.getClass().getSimpleName() + "[" + getTime().toString()
     44                                + "," + action.toString() + "]";
    4445        }
    4546
  • events/src/main/java/geniusweb/events/CurrentState.java

    r52 r54  
    11package geniusweb.events;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35/**
     
    2022 */
    2123public abstract class CurrentState extends ProtocolEvent {
    22         public CurrentState() {
    23         }
    2424
    25         public CurrentState(Long now) {
     25        public CurrentState(@NonNull Long now) {
    2626                super(now);
    2727        }
  • events/src/main/java/geniusweb/events/NegotiationEvent.java

    r52 r54  
    11package geniusweb.events;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonAutoDetect;
     
    3335         *         accuracy.
    3436         */
     37        @NonNull
    3538        Long getTime();
    3639
  • events/src/main/java/geniusweb/events/ProtocolEvent.java

    r52 r54  
    11package geniusweb.events;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35/**
     
    57 */
    68public abstract class ProtocolEvent extends AbstractEvent {
    7         public ProtocolEvent() {
    89
    9         }
    10 
    11         public ProtocolEvent(Long now) {
     10        public ProtocolEvent(@NonNull Long now) {
    1211                super(now);
    1312        }
  • events/src/main/java/geniusweb/events/SessionStarted.java

    r52 r54  
    22
    33import java.util.List;
     4
     5import org.eclipse.jdt.annotation.NonNull;
    46
    57import com.fasterxml.jackson.annotation.JsonCreator;
     
    911
    1012public 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;
    1315
    1416        @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,
    1720                        @JsonProperty("time") Long time) {
    1821                super(time);
    19                 this.sessionNumber = sessionnr;
     22                this.sessionNumber = sessionNumber;
    2023                this.parties = parties;
    2124        }
    2225
    23         public List<PartyId> getParties() {
     26        public @NonNull List<@NonNull PartyId> getParties() {
    2427                return parties;
    2528        }
    2629
    27         public Long getSessionNumber() {
     30        public @NonNull Long getSessionNumber() {
    2831                return sessionNumber;
    2932        }
     
    6265
    6366        @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() + "]";
    6770        }
    6871
  • events/src/main/java/geniusweb/events/TournamentStarted.java

    r52 r54  
    11package geniusweb.events;
    22
     3import org.eclipse.jdt.annotation.NonNull;
     4
     5import com.fasterxml.jackson.annotation.JsonCreator;
     6import com.fasterxml.jackson.annotation.JsonProperty;
     7
    38public 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;
    1010
    1111        /**
    1212         *
    1313         * @param numberOfSessions the total number of sessions in the tournament
     14         * @param time             the current timestamp. Null is current time.
    1415         */
    15         public TournamentStarted(Long numberOfSessions) {
     16        @JsonCreator
     17        public TournamentStarted(
     18                        @JsonProperty("numberOfSessions") @NonNull Long numberOfSessions,
     19                        @JsonProperty("time") Long time) {
     20                super(time);
    1621                this.numberOfSessions = numberOfSessions;
    1722        }
    1823
    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() {
    3025                return numberOfSessions;
    3126        }
    3227
    3328        @Override
    34         public String toString() {
    35                 return "TournamentStarted[" + getTime() + "," + numberOfSessions + "]";
     29        public @NonNull String toString() {
     30                return "TournamentStarted[" + getTime().toString() + ","
     31                                + numberOfSessions.toString() + "]";
    3632        }
    3733
  • events/src/main/java/geniusweb/inform/ActionDone.java

    r52 r54  
    11package geniusweb.inform;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    1113public class ActionDone implements Inform {
    1214
    13         private final Action action;
     15        private final @NonNull Action action;
    1416
    1517        @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");
    1721                this.action = action;
    1822        }
    1923
    20         public Action getAction() {
     24        public @NonNull Action getAction() {
    2125                return action;
    2226        }
    2327
    2428        @Override
    25         public String toString() {
    26                 return "ActionDone[" + action + "]";
     29        public @NonNull String toString() {
     30                return "ActionDone[" + action.toString() + "]";
    2731        }
    2832
  • events/src/main/java/geniusweb/inform/Agreements.java

    r52 r54  
    66import java.util.Set;
    77import java.util.stream.Collectors;
     8
     9import org.eclipse.jdt.annotation.NonNull;
    810
    911import com.fasterxml.jackson.annotation.JsonAutoDetect;
     
    2224@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
    2325public class Agreements {
    24         @JsonValue
    25         private final Map<PartyId, Bid> agreements;
     26        private final @NonNull Map<@NonNull PartyId, @NonNull Bid> agreements = new HashMap<>();
    2627
    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         */
    3135        @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);
    3440        }
    3541
    3642        /**
     43         * This replaces the overloaded constructor with same arguments
     44         *
    3745         * @param bid     a bid that all parties agreed on
    3846         * @param parties the {@link PartyId}s of the agreeing parties
    3947         */
    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()
    4252                                .collect(Collectors.toMap(pid -> pid, pid -> bid)));
    4353        }
     
    4959         *                                  agreement.
    5060         */
    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()) {
    5464                        if (newagrees.containsKey(pid))
    5565                                throw new IllegalArgumentException(
    56                                                 "party " + pid + " already has agreement");
     66                                                "party " + pid.toString() + " already has agreement");
    5767                        newagrees.put(pid, other.agreements.get(pid));
    5868                }
     
    6070        }
    6171
     72        @JsonValue
    6273        /**
     74         * This replaces the previous getMap() method.
     75         *
    6376         * @return actual agreemenets contained here
    6477         */
    65         public Map<PartyId, Bid> getMap() {
     78        public @NonNull Map<@NonNull PartyId, @NonNull Bid> getAgreements() {
    6679                return Collections.unmodifiableMap(agreements);
    6780        }
    6881
    6982        @Override
    70         public String toString() {
    71                 return "Agreements" + agreements;
     83        public @NonNull String toString() {
     84                return "Agreements" + agreements.toString();
    7285        }
    7386
  • events/src/main/java/geniusweb/inform/Finished.java

    r52 r54  
    11package geniusweb.inform;
     2
     3import org.eclipse.jdt.annotation.NonNull;
    24
    35import com.fasterxml.jackson.annotation.JsonCreator;
     
    1012 */
    1113public class Finished implements Inform {
    12         private final Agreements agreements;
     14        private final @NonNull Agreements agreements;
    1315
    1416        /**
     
    1820         */
    1921        @JsonCreator
    20         public Finished(@JsonProperty("agreements") Agreements agreements) {
     22        public Finished(
     23                        @JsonProperty("agreements") @NonNull Agreements agreements) {
    2124                if (agreements == null)
    2225                        throw new NullPointerException("Agreements can't be null");
     
    2427        }
    2528
    26         public Agreements getAgreements() {
     29        public @NonNull Agreements getAgreements() {
    2730                return agreements;
    2831        }
     
    5558
    5659        @Override
    57         public String toString() {
    58                 return "Finished[" + agreements + "]";
     60        public @NonNull String toString() {
     61                return "Finished[" + agreements.toString() + "]";
    5962        }
    6063}
  • events/src/main/java/geniusweb/inform/OptIn.java

    r52 r54  
    44import java.util.LinkedList;
    55import java.util.List;
     6
     7import org.eclipse.jdt.annotation.NonNull;
    68
    79import com.fasterxml.jackson.annotation.JsonCreator;
     
    1618public class OptIn implements Inform {
    1719
    18         private final List<Votes> votes;
     20        private final @NonNull List<@NonNull Votes> votes;
    1921
    2022        /**
     
    2224         */
    2325        @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");
    2629
    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();
    3034                        if (partyVotes.contains(party))
    3135                                throw new IllegalArgumentException(
     
    3337                        partyVotes.add(party);
    3438                }
     39                this.votes = votes;
    3540        }
    3641
     
    3843         * @return list of votes that can be opted in to
    3944         */
    40         public List<Votes> getVotes() {
     45        public @NonNull List<@NonNull Votes> getVotes() {
    4146                return Collections.unmodifiableList(votes);
    4247        }
     
    6873
    6974        @Override
    70         public String toString() {
    71                 return "OptIn[" + votes + "]";
     75        public @NonNull String toString() {
     76                return "OptIn[" + votes.toString() + "]";
    7277        }
    7378
  • events/src/main/java/geniusweb/inform/OptInWithValue.java

    r52 r54  
    77import java.util.Optional;
    88import java.util.stream.Collectors;
     9
     10import org.eclipse.jdt.annotation.NonNull;
    911
    1012import com.fasterxml.jackson.annotation.JsonCreator;
     
    1921public class OptInWithValue implements Inform {
    2022
    21         private final List<VotesWithValue> votes;
     23        private final @NonNull List<@NonNull VotesWithValue> votes;
    2224
    2325        /**
     
    2527         */
    2628        @JsonCreator
    27         public OptInWithValue(@JsonProperty("votes") List<VotesWithValue> votes) {
    28                 this.votes = votes;
     29        public OptInWithValue(
     30                        @JsonProperty("votes") @NonNull List<@NonNull VotesWithValue> votes) {
    2931
    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();
    3546                if (nonunique.isPresent())
    3647                        throw new IllegalArgumentException(
    3748                                        "OptIn contains multiple Votes for party "
    3849                                                        + nonunique.get().getKey());
    39 
     50                this.votes = votes;
    4051        }
    4152
     
    4354         * @return list of votes that can be opted in to
    4455         */
    45         public List<VotesWithValue> getVotes() {
     56        public @NonNull List<@NonNull VotesWithValue> getVotes() {
    4657                return Collections.unmodifiableList(votes);
    4758        }
     
    7384
    7485        @Override
    75         public String toString() {
    76                 return "OptInWithValue[" + votes + "]";
     86        public @NonNull String toString() {
     87                return "OptInWithValue[" + votes.toString() + "]";
    7788        }
    7889
  • events/src/main/java/geniusweb/inform/Settings.java

    r52 r54  
    33import java.util.HashMap;
    44import java.util.Map;
     5
     6import org.eclipse.jdt.annotation.NonNull;
    57
    68import com.fasterxml.jackson.annotation.JsonCreator;
     
    1921 */
    2022public 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;
    2628
    2729        /**
     
    3941         */
    4042        @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) {
    4648                if (profile == null || protocol == null || progress == null
    47                                 || parameters == null) {
     49                                || parameters == null || id == null) {
    4850                        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.");
    5052                }
    5153                this.profile = profile;
     
    6062         * @return the profile used for this party in this session
    6163         */
    62         public ProfileRef getProfile() {
     64        public @NonNull ProfileRef getProfile() {
    6365                return profile;
    6466        }
    6567
    66         public ProtocolRef getProtocol() {
     68        public @NonNull ProtocolRef getProtocol() {
    6769                return protocol;
    6870        }
     
    7274         * @return the {@link Progress} object used for this session
    7375         */
    74         public Progress getProgress() {
     76        public @NonNull Progress getProgress() {
    7577                return progress;
    7678        }
     
    7981         * @return the party ID of this party
    8082         */
    81         public PartyId getID() {
     83        public @NonNull PartyId getID() {
    8284                return id;
    8385        }
     
    8890         *         parameters that can be used by the party.
    8991         */
    90         public Parameters getParameters() {
     92        public @NonNull Parameters getParameters() {
    9193                return parameters;
    9294        }
    9395
    9496        @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() + "]";
    98101        }
    99102
  • events/src/main/java/geniusweb/inform/Voting.java

    r52 r54  
    11package geniusweb.inform;
    22
     3import java.util.ArrayList;
    34import java.util.Collections;
     5import java.util.HashMap;
    46import java.util.List;
    57import java.util.Map;
     8
     9import org.eclipse.jdt.annotation.NonNull;
    610
    711import com.fasterxml.jackson.annotation.JsonCreator;
     
    1620public class Voting implements Inform {
    1721
    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<>();
    2024
    2125        @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);
    2637        }
    2738
     
    2940         * @return list of offers to be voted on
    3041         */
    31         public List<Offer> getOffers() {
     42        public @NonNull List<@NonNull Offer> getOffers() {
    3243                return Collections.unmodifiableList(offers);
    33         }
    34 
    35         @Deprecated
    36         public List<Offer> getBids() {
    37                 return getOffers();
    3844        }
    3945
     
    4450         *         agreement or walked away.
    4551         */
    46         public Map<PartyId, Integer> getPowers() {
     52        public @NonNull Map<@NonNull PartyId, @NonNull Integer> getPowers() {
    4753                return Collections.unmodifiableMap(powers);
    4854        }
     
    8086
    8187        @Override
    82         public String toString() {
    83                 return "Voting[" + offers + "," + powers + "]";
     88        public @NonNull String toString() {
     89                return "Voting[" + offers.toString() + "," + powers.toString() + "]";
    8490        }
    8591
  • events/src/test/java/geniusweb/actions/AcceptTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    1011import java.util.Map;
    1112
    12 import org.junit.Before;
     13import org.eclipse.jdt.annotation.NonNull;
    1314import org.junit.Test;
     15import org.junit.internal.runners.JUnit4ClassRunner;
     16import org.junit.runner.RunWith;
    1417
    1518import com.fasterxml.jackson.core.JsonProcessingException;
     
    2225import tudelft.utilities.junit.GeneralTests;
    2326
     27@RunWith(JUnit4ClassRunner.class)
    2428public class AcceptTest extends GeneralTests<Accept> {
    25         private final ObjectMapper jackson = new ObjectMapper();
     29        private final static @NonNull ObjectMapper jackson = new ObjectMapper();
    2630
    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>();
    3135        private static Bid bid;
    3236        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");
    3741        // 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 + "),?)+.*";
    3949
    4050        private static Accept accept, accept1, accept2, acceptb;
     
    5969        @Override
    6070        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;
    6676        }
    6777
    6878        @Override
    6979        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() + ".*]");
    7783        }
    7884
    7985        @Test
    8086        public void serializeAcceptTest() throws JsonProcessingException {
    81                 System.out.println(jackson.writeValueAsString(accept));
    82                 assertEquals(acceptstring, jackson.writeValueAsString(accept));
     87                //System.out.println(jackson.writeValueAsString(accept));
     88                assertTrue(jackson.writeValueAsString(accept).matches(acceptstringpat));
    8389        }
    8490
    8591        @Test
    8692        public void deserializeAcceptTest() throws IOException {
    87                 Action act = jackson.readValue(acceptstring, Action.class);
     93                final @NonNull Action act = jackson.readValue(acceptstring,
     94                                Action.class);
    8895                assertEquals(accept, act);
    8996        }
  • events/src/test/java/geniusweb/actions/ComparisonTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    1011import java.util.Map;
    1112
     13import org.eclipse.jdt.annotation.NonNull;
    1214import org.junit.Before;
    1315import org.junit.Test;
     16import org.junit.internal.runners.JUnit4ClassRunner;
     17import org.junit.runner.RunWith;
    1418
    1519import com.fasterxml.jackson.core.JsonProcessingException;
     
    2226import tudelft.utilities.junit.GeneralTests;
    2327
     28@RunWith(JUnit4ClassRunner.class)
    2429public class ComparisonTest extends GeneralTests<Comparison> {
    25         private final ObjectMapper jackson = new ObjectMapper();
     30        private final static @NonNull ObjectMapper jackson = new ObjectMapper();
    2631
    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>();
    3136        private static Bid bid;
    3237        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");
    3742        // 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.*\\[\\].*";
    3950
    4051        private static Comparison accept, accept1, accept2, acceptb, acceptc,
     
    4657                issuevalues.put(ISSUE2, VALUE2);
    4758                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;
    5061                accept = new Comparison(id, bid, better, worse);
    5162                accept1 = new Comparison(id, bid, better, worse);
     
    5970                acceptb = new Comparison(id, bidb, better, worse);
    6071
    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);
    6374                acceptc = new Comparison(id, bidb, better1, worse);
    6475                acceptd = new Comparison(id, bidb, better, worse1);
     
    7687        public List<String> getGeneralTestStrings() {
    7788                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                                                + ".*\\].*");
    83100        }
    84101
    85102        @Test
    86103        public void serializeAcceptTest() throws JsonProcessingException {
    87                 System.out.println(jackson.writeValueAsString(accept));
    88                 assertEquals(acceptstring, jackson.writeValueAsString(accept));
     104                //System.out.println(jackson.writeValueAsString(accept));
     105                assertTrue(jackson.writeValueAsString(accept).matches(acceptstringpat));
    89106        }
    90107
    91108        @Test
    92109        public void deserializeAcceptTest() throws IOException {
    93                 Action act = jackson.readValue(acceptstring, Action.class);
     110                final @NonNull Action act = jackson.readValue(acceptstring,
     111                                Action.class);
    94112                assertEquals(accept, act);
    95113        }
  • events/src/test/java/geniusweb/actions/ElicitComparisonTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    910import java.util.Map;
    1011
     12import org.eclipse.jdt.annotation.NonNull;
    1113import org.junit.Before;
    1214import org.junit.Test;
     15import org.junit.internal.runners.JUnit4ClassRunner;
     16import org.junit.runner.RunWith;
    1317
    1418import com.fasterxml.jackson.core.JsonProcessingException;
     
    2125import tudelft.utilities.junit.GeneralTests;
    2226
     27@RunWith(JUnit4ClassRunner.class)
    2328public class ElicitComparisonTest extends GeneralTests<ElicitComparison> {
    2429        private final ObjectMapper jackson = new ObjectMapper();
    2530
    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>();
    3035        private static Bid bid;
    3136        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");
    3641        // 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\")),?)+\\}\\}\\]\\}\\}";
    3845
    3946        private static ElicitComparison accept1, accept1a, accept2, accept3,
     
    4956                bidb = new Bid(issuevaluesb);
    5057
    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);
    5360
    5461                accept1 = new ElicitComparison(id, bid, opts);
     
    6673        }
    6774
     75        private final static @NonNull String bidpat = "Bid\\{.*(((.*issue1.*value1.*)|(.*issue2.*10)),?)+\\}";
     76        private final static @NonNull String bidbpat = "Bid\\{.*issue1.*10.*\\}";
     77
    6878        @Override
    6979        public List<String> getGeneralTestStrings() {
    7080                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                );
    7591        }
    7692
    7793        @Test
    7894        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));
    8198        }
    8299
    83100        @Test
    84101        public void deserializeAcceptTest() throws IOException {
    85                 Action act = jackson.readValue(acceptstring, Action.class);
     102                final @NonNull Action act = jackson.readValue(acceptstring,
     103                                Action.class);
    86104                assertEquals(accept1, act);
    87105        }
  • events/src/test/java/geniusweb/actions/EndNegoTest.java

    r52 r54  
    88
    99import org.junit.Test;
     10import org.junit.internal.runners.JUnit4ClassRunner;
     11import org.junit.runner.RunWith;
    1012
    1113import com.fasterxml.jackson.core.JsonProcessingException;
     
    1416import tudelft.utilities.junit.GeneralTests;
    1517
     18@RunWith(JUnit4ClassRunner.class)
    1619public class EndNegoTest extends GeneralTests<EndNegotiation> {
    1720        private final ObjectMapper jackson = new ObjectMapper();
     
    3437        @Override
    3538        public List<String> getGeneralTestStrings() {
    36                 return Arrays.asList("EndNegotiation\\[.*" + id + ".*\\]",
    37                                 "EndNegotiation\\[.*" + idb + ".*\\]");
     39                return Arrays.asList("EndNegotiation\\[.*" + id.toString() + ".*\\]",
     40                                "EndNegotiation\\[.*" + idb.toString() + ".*\\]");
    3841        }
    3942
    4043        @Test
    4144        public void serializeEndNegoTest() throws JsonProcessingException {
    42                 System.out.println(jackson.writeValueAsString(endnego));
     45                //System.out.println(jackson.writeValueAsString(endnego));
    4346                assertEquals(endnegostring, jackson.writeValueAsString(endnego));
    4447        }
  • events/src/test/java/geniusweb/actions/FileLocationTest.java

    r52 r54  
    1010
    1111import org.junit.Test;
     12import org.junit.internal.runners.JUnit4ClassRunner;
     13import org.junit.runner.RunWith;
    1214
    1315import com.fasterxml.jackson.core.JsonParseException;
     
    1618import com.fasterxml.jackson.databind.ObjectMapper;
    1719
     20@RunWith(JUnit4ClassRunner.class)
    1821public class FileLocationTest {
    1922        private final ObjectMapper jackson = new ObjectMapper();
    20         private FileLocation fileloc = new FileLocation();
    21         private String filelocstr = "\"" + fileloc.getUUIDString() + "\"";
     23        private FileLocation fileloc = new FileLocation(null);
     24        private String filelocstr = "\"" + fileloc.getUUID().toString() + "\"";
    2225
    2326        private String uuidstr = "b871e65c-e7fe-4664-b607-cb31898cc3ac";
     
    3639        @Test
    3740        public void serializeTest() throws JsonProcessingException {
    38                 System.out.println(jackson.writeValueAsString(fileloc));
     41                //System.out.println(jackson.writeValueAsString(fileloc));
    3942                assertEquals(filelocstr, jackson.writeValueAsString(fileloc));
    4043        }
     
    4851        @Test(expected = JsonParseException.class)
    4952        public void deserializeTestInjectinon()
    50                         throws JsonParseException, JsonMappingException, IOException {
     53                        throws JsonProcessingException, JsonMappingException, IOException {
    5154                jackson.readValue("bla/../..", FileLocation.class);
    5255        }
  • events/src/test/java/geniusweb/actions/LearningDoneTest.java

    r52 r54  
    88
    99import org.junit.Test;
     10import org.junit.internal.runners.JUnit4ClassRunner;
     11import org.junit.runner.RunWith;
    1012
    1113import com.fasterxml.jackson.core.JsonProcessingException;
     
    1416import tudelft.utilities.junit.GeneralTests;
    1517
     18@RunWith(JUnit4ClassRunner.class)
    1619public class LearningDoneTest extends GeneralTests<LearningDone> {
    1720        private final ObjectMapper jackson = new ObjectMapper();
     
    2831        @Override
    2932        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));
    3234        }
    3335
    3436        @Override
    3537        public List<String> getGeneralTestStrings() {
    36                 return Arrays.asList("LearningDone\\[.*" + id + ".*\\]",
    37                                 "LearningDone\\[.*" + idb + ".*\\]");
     38                return Arrays.asList("LearningDone\\[.*" + id.toString() + ".*\\]",
     39                                "LearningDone\\[.*" + idb.toString() + ".*\\]");
    3840        }
    3941
    4042        @Test
    4143        public void serializeEndNegoTest() throws JsonProcessingException {
    42                 System.out.println(jackson.writeValueAsString(done));
     44                //System.out.println(jackson.writeValueAsString(done));
    4345                assertEquals(endnegostring, jackson.writeValueAsString(done));
    4446        }
  • events/src/test/java/geniusweb/actions/OfferTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    910import java.util.Map;
    1011
     12import org.eclipse.jdt.annotation.NonNull;
    1113import org.junit.Test;
     14import org.junit.internal.runners.JUnit4ClassRunner;
     15import org.junit.runner.RunWith;
    1216
    1317import com.fasterxml.jackson.core.JsonProcessingException;
     
    2024import tudelft.utilities.junit.GeneralTests;
    2125
     26@RunWith(JUnit4ClassRunner.class)
    2227public class OfferTest extends GeneralTests<Offer> {
    23         private final ObjectMapper jackson = new ObjectMapper();
     28        private final @NonNull ObjectMapper jackson = new ObjectMapper();
    2429
    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>();
    2833        private static Bid bid;
    2934        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\"}}}}";
    3540
     41        private static final @NonNull String acceptstringpatt = "\\{\"Offer\":\\{\"actor\":\"party1\",\"bid\":\\{\"issuevalues\":\\{(((\"issue1\":\"value1\")|(\"issue2\":10)),?).*\\}\\}\\}\\}";
    3642        private static Offer offer;
    3743        private static Offer offer1;
     
    6167        @Override
    6268        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.*\\]");
    6571        }
    6672
    6773        @Test
    6874        public void serializeAcceptTest() throws JsonProcessingException {
    69                 System.out.println(jackson.writeValueAsString(offer));
    70                 assertEquals(acceptstring, jackson.writeValueAsString(offer));
     75                //System.out.println(jackson.writeValueAsString(offer));
     76                assertTrue(jackson.writeValueAsString(offer).matches(acceptstringpatt));
    7177        }
    7278
    7379        @Test
    7480        public void deserializeAcceptTest() throws IOException {
    75                 Action act = jackson.readValue(acceptstring, Action.class);
     81                final @NonNull Action act = jackson.readValue(acceptstring,
     82                                Action.class);
    7683                assertEquals(offer, act);
    7784        }
  • events/src/test/java/geniusweb/actions/PartyIdTest.java

    r52 r54  
    77
    88import org.junit.Test;
     9import org.junit.internal.runners.JUnit4ClassRunner;
     10import org.junit.runner.RunWith;
    911
    1012import tudelft.utilities.junit.GeneralTests;
    1113
     14@RunWith(JUnit4ClassRunner.class)
    1215public class PartyIdTest extends GeneralTests<PartyId> {
    1316        private final PartyId id = new PartyId("party1");
  • events/src/test/java/geniusweb/actions/PartyIdTest1.java

    r52 r54  
    1010import org.junit.Before;
    1111import org.junit.Test;
     12import org.junit.internal.runners.JUnit4ClassRunner;
     13import org.junit.runner.RunWith;
    1214
    1315import com.fasterxml.jackson.core.JsonParseException;
     
    1820import tudelft.utilities.junit.GeneralTests;
    1921
     22@RunWith(JUnit4ClassRunner.class)
    2023public class PartyIdTest1 extends GeneralTests<PartyId> {
    2124
     
    5154        @Test(expected = IllegalArgumentException.class)
    5255        public void nullTest() throws URISyntaxException {
    53                 new PartyId(null);
     56                new PartyId(nullID());
     57        }
     58
     59        private String nullID() {
     60                return null;
    5461        }
    5562
     
    5966
    6067                String json = jackson.writeValueAsString(party1);
    61                 System.out.println(json);
     68                //System.out.println(json);
    6269                assertEquals(asJson, json);
    6370        }
     
    6875                ObjectMapper jackson = new ObjectMapper();
    6976                PartyId p = jackson.readValue(asJson, PartyId.class);
    70                 System.out.println(p);
     77                //System.out.println(p);
    7178                assertEquals(party1, p);
    7279        }
  • events/src/test/java/geniusweb/actions/VoteTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    910import java.util.Map;
    1011
     12import org.eclipse.jdt.annotation.NonNull;
    1113import org.junit.Before;
    1214import org.junit.Test;
     15import org.junit.internal.runners.JUnit4ClassRunner;
     16import org.junit.runner.RunWith;
    1317
    1418import com.fasterxml.jackson.core.JsonProcessingException;
     
    2125import tudelft.utilities.junit.GeneralTests;
    2226
     27@RunWith(JUnit4ClassRunner.class)
    2328public class VoteTest extends GeneralTests<Vote> {
    2429        private final ObjectMapper jackson = new ObjectMapper();
     
    3641        // issue 2 is NUMBER and thus serializes with leading '='
    3742        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.*";
    3849
    3950        private static Vote vote1, vote1a, vote2, vote3, vote4, vote5;
     
    6879        @Override
    6980        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.*");
    7586        }
    7687
     
    8293        @Test
    8394        public void serializeTest() throws JsonProcessingException {
    84                 System.out.println(jackson.writeValueAsString(vote1));
    85                 assertEquals(votestring, jackson.writeValueAsString(vote1));
     95                //System.out.println(jackson.writeValueAsString(vote1));
     96                assertTrue(jackson.writeValueAsString(vote1).matches(votestringpat));
    8697        }
    8798
  • events/src/test/java/geniusweb/actions/VoteWithValueTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    910import java.util.Map;
    1011
     12import org.eclipse.jdt.annotation.NonNull;
    1113import org.junit.Before;
    1214import org.junit.Test;
     15import org.junit.internal.runners.JUnit4ClassRunner;
     16import org.junit.runner.RunWith;
    1317
    1418import com.fasterxml.jackson.core.JsonProcessingException;
     
    2125import tudelft.utilities.junit.GeneralTests;
    2226
     27@RunWith(JUnit4ClassRunner.class)
    2328public class VoteWithValueTest extends GeneralTests<VoteWithValue> {
    2429        private final ObjectMapper jackson = new ObjectMapper();
    2530
    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>();
    3035        private static Bid bid;
    3136        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");
    3641        // 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.*";
    3848
    3949        private static VoteWithValue vote1, vote1a, vote2, vote3, vote4, vote5,
     
    7282        public List<String> getGeneralTestStrings() {
    7383                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.*");
    8090        }
    8191
     
    8797        @Test
    8898        public void serializeTest() throws JsonProcessingException {
    89                 System.out.println(jackson.writeValueAsString(vote1));
    90                 assertEquals(votestring, jackson.writeValueAsString(vote1));
     99                //System.out.println(jackson.writeValueAsString(vote1));
     100                assertTrue(jackson.writeValueAsString(vote1).matches(votestringpat));
    91101        }
    92102
    93103        @Test
    94104        public void deserializeAcceptTest() throws IOException {
    95                 Action act = jackson.readValue(votestring, Action.class);
     105                final @NonNull Action act = jackson.readValue(votestring, Action.class);
    96106                assertEquals(vote1, act);
    97107        }
  • events/src/test/java/geniusweb/actions/VotesTest.java

    r52 r54  
    1111import java.util.List;
    1212
     13import org.eclipse.jdt.annotation.NonNull;
    1314import org.junit.Test;
     15import org.junit.internal.runners.JUnit4ClassRunner;
     16import org.junit.runner.RunWith;
    1417
    1518import com.fasterxml.jackson.core.JsonProcessingException;
     
    2023import tudelft.utilities.junit.GeneralTests;
    2124
     25@RunWith(JUnit4ClassRunner.class)
    2226public 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.*";
    2530
    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);
    3441
    35         private Votes votes1 = new Votes(partyA,
     42        private final @NonNull Votes votes1 = new Votes(partyA,
    3643                        new HashSet<>(Arrays.asList(voteA1, voteA2)));
    37         private Votes votes1a = new Votes(partyA,
     44        private final @NonNull Votes votes1a = new Votes(partyA,
    3845                        new HashSet<>(Arrays.asList(voteA1, voteA2)));
    39         private Votes votes2 = new Votes(partyB,
     46        private final @NonNull Votes votes2 = new Votes(partyB,
    4047                        new HashSet<>(Arrays.asList(voteB1, voteB2)));
    4148
     
    4956        public List<String> getGeneralTestStrings() {
    5057                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)),?)+.*");
    5360        }
    5461
     
    6168        @Test
    6269        public void serializeTest() throws JsonProcessingException {
    63                 System.out.println(jackson.writeValueAsString(votes1));
    64                 assertEquals(votestring, jackson.writeValueAsString(votes1));
     70                //System.out.println(jackson.writeValueAsString(votes1));
     71                assertTrue(jackson.writeValueAsString(votes1).matches(votestringpat));
    6572        }
    6673
    6774        @Test
    6875        public void deserializeTest() throws IOException {
    69                 Action act = jackson.readValue(votestring, Action.class);
     76                final @NonNull Action act = jackson.readValue(votestring, Action.class);
    7077                assertEquals(votes1, act);
    7178        }
     
    7885        @Test
    7986        public void isExtendingTestExtraVote() {
    80                 Votes otherVotes = new Votes(partyA, Collections.singleton(voteA1));
     87                final @NonNull Votes otherVotes = new Votes(partyA,
     88                                Collections.singleton(voteA1));
    8189                assertTrue(votes1.isExtending(otherVotes));
    8290        }
     
    8492        @Test
    8593        public void isExtendingTestNoVotes() {
    86                 Votes otherVotes = new Votes(partyA, Collections.emptySet());
     94                final @NonNull Votes otherVotes = new Votes(partyA,
     95                                Collections.emptySet());
    8796                assertTrue(votes1.isExtending(otherVotes));
    8897        }
     
    9099        @Test
    91100        public void isExtendingTestMissing() {
    92                 Votes otherVotes = new Votes(partyA, Collections.singleton(voteA1));
     101                final @NonNull Votes otherVotes = new Votes(partyA,
     102                                Collections.singleton(voteA1));
    93103                assertFalse(otherVotes.isExtending(votes1));
    94104        }
     
    101111        @Test
    102112        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,
    105115                                new HashSet<>(Arrays.asList(powervoteA1, voteA2)));
    106116                assertTrue(powerVotes.isExtending(votes1));
     
    109119        @Test
    110120        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,
    113123                                new HashSet<>(Arrays.asList(powervoteA1, voteA2)));
    114124                assertTrue(powerVotes.isExtending(votes1));
     
    117127        @Test
    118128        public void IsNarrowingOneVoteRemoved() {
    119                 Votes narrowVotes = new Votes(partyA, Collections.singleton(voteA2));
     129                final @NonNull Votes narrowVotes = new Votes(partyA,
     130                                Collections.singleton(voteA2));
    120131                assertFalse(narrowVotes.isExtending(votes1));
    121132        }
     
    123134        @Test
    124135        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,
    127138                                new HashSet<>(Arrays.asList(narrowVoteA1, voteA2)));
    128139                assertFalse(narrowVotes.isExtending(votes1));
     
    141152        @Test(expected = IllegalArgumentException.class)
    142153        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,
    145156                                new HashSet<>(Arrays.asList(voteA1, voteA1similar)));
    146157        }
  • events/src/test/java/geniusweb/actions/VotesWithValueTest.java

    r52 r54  
    1111import java.util.List;
    1212
     13import org.eclipse.jdt.annotation.NonNull;
    1314import org.junit.Test;
     15import org.junit.internal.runners.JUnit4ClassRunner;
     16import org.junit.runner.RunWith;
    1417
    1518import com.fasterxml.jackson.core.JsonProcessingException;
     
    2023import tudelft.utilities.junit.GeneralTests;
    2124
     25@RunWith(JUnit4ClassRunner.class)
    2226public 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 + "),?).*";
    2533
    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);
    3852
    39         private VotesWithValue votes1 = new VotesWithValue(partyA,
     53        private @NonNull VotesWithValue votes1 = new VotesWithValue(partyA,
    4054                        new HashSet<>(Arrays.asList(voteA1, voteA2)));
    41         private VotesWithValue votes1a = new VotesWithValue(partyA,
     55        private @NonNull VotesWithValue votes1a = new VotesWithValue(partyA,
    4256                        new HashSet<>(Arrays.asList(voteA1, voteA2)));
    43         private VotesWithValue votes2 = new VotesWithValue(partyB,
     57        private @NonNull VotesWithValue votes2 = new VotesWithValue(partyB,
    4458                        new HashSet<>(Arrays.asList(voteB1, voteB2)));
    4559
     
    5266        @Override
    5367        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.*");
    5770        }
    5871
     
    6578        @Test
    6679        public void serializeTest() throws JsonProcessingException {
    67                 System.out.println(jackson.writeValueAsString(votes1));
    68                 assertEquals(votestring, jackson.writeValueAsString(votes1));
     80                //System.out.println(jackson.writeValueAsString(votes1));
     81                assertTrue(jackson.writeValueAsString(votes1).matches(votestringpat));
    6982        }
    7083
    7184        @Test
    7285        public void deserializeTest() throws IOException {
    73                 Action act = jackson.readValue(votestring, Action.class);
     86                final @NonNull Action act = jackson.readValue(votestring, Action.class);
    7487                assertEquals(votes1, act);
    7588        }
     
    8396        @Test
    8497        public void isExtendingTestExtraVote() {
    85                 VotesWithValue otherVotes = new VotesWithValue(partyA,
     98                final @NonNull VotesWithValue otherVotes = new VotesWithValue(partyA,
    8699                                Collections.singleton(voteA1_100));
    87100                assertTrue(votes1.isExtending(otherVotes));
     
    90103        @Test
    91104        public void isExtendingTestMissing() {
    92                 VotesWithValue otherVotes = new VotesWithValue(partyA,
     105                final @NonNull VotesWithValue otherVotes = new VotesWithValue(partyA,
    93106                                Collections.singleton(voteA1_100));
    94107                assertFalse(otherVotes.isExtending(votes1));
     
    102115        @Test
    103116        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,
    106120                                new HashSet<>(Arrays.asList(powervoteA1, voteA2)));
    107121                assertTrue(powerVotes.isExtending(votes1));
     
    110124        @Test
    111125        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,
    114129                                new HashSet<>(Arrays.asList(powervoteA1, voteA2)));
    115130                assertTrue(powerVotes.isExtending(votes1));
     
    118133        @Test
    119134        public void IsNarrowingOneVoteRemoved() {
    120                 VotesWithValue narrowVotes = new VotesWithValue(partyA,
     135                final @NonNull VotesWithValue narrowVotes = new VotesWithValue(partyA,
    121136                                Collections.singleton(voteA2_100));
    122137                assertFalse(narrowVotes.isExtending(votes1));
     
    125140        @Test
    126141        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,
    129145                                new HashSet<>(Arrays.asList(narrowVoteA1, voteA2)));
    130146                assertFalse(narrowVotes.isExtending(votes1));
  • events/src/test/java/geniusweb/events/ActionEventTest.java

    r52 r54  
    88import java.util.List;
    99
     10import org.eclipse.jdt.annotation.NonNull;
    1011import org.junit.Test;
     12import org.junit.internal.runners.JUnit4ClassRunner;
     13import org.junit.runner.RunWith;
    1114
    1215import com.fasterxml.jackson.core.JsonProcessingException;
     
    1821import tudelft.utilities.junit.GeneralTests;
    1922
     23@RunWith(JUnit4ClassRunner.class)
    2024public 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);
    2933
    3034        @Override
     
    3539        @Override
    3640        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.*\\]");
    3945        }
    4046
    4147        @Test
    4248        public void smoketest() {
    43                 Action action = mock(EndNegotiation.class);
     49                final @NonNull Action action = mock(EndNegotiation.class);
    4450                ActionEvent evt = new ActionEvent(action, 0l);
    4551        }
     
    4753        @Test
    4854        public void serializeTest() throws JsonProcessingException {
    49                 System.out.println(jackson.writeValueAsString(evt));
     55                //System.out.println(jackson.writeValueAsString(evt));
    5056                assertEquals(string, jackson.writeValueAsString(evt));
    5157        }
     
    5359        @Test
    5460        public void deserializeTestReadActionEvent() throws IOException {
    55                 ActionEvent evt1 = jackson.readValue(string, ActionEvent.class);
     61                final @NonNull ActionEvent evt1 = jackson.readValue(string,
     62                                ActionEvent.class);
    5663                // compare fields, as evt is a derived/new inner class
    5764                assertEquals(EndNegotiation.class, evt1.getAction().getClass());
     
    6168        @Test
    6269        public void deserializeTestReadEvent() throws IOException {
    63                 NegotiationEvent evt1 = jackson.readValue(string,
     70                final @NonNull NegotiationEvent evt1 = jackson.readValue(string,
    6471                                NegotiationEvent.class);
    6572                assertEquals(ActionEvent.class, evt1.getClass());
    66                 ActionEvent ev1 = (ActionEvent) evt1;
     73                final @NonNull ActionEvent ev1 = (ActionEvent) evt1;
    6774                assertEquals(EndNegotiation.class, ev1.getAction().getClass());
    6875                assertEquals((Long) 101l, ev1.getTime());
  • events/src/test/java/geniusweb/events/SessionStartedTest.java

    r52 r54  
    88import java.util.List;
    99
     10import org.eclipse.jdt.annotation.NonNull;
    1011import org.junit.Test;
    11 import org.junit.experimental.theories.DataPoint;
    12 import org.junit.experimental.theories.DataPoints;
     12import org.junit.internal.runners.JUnit4ClassRunner;
     13import org.junit.runner.RunWith;
    1314
    1415import com.fasterxml.jackson.core.JsonProcessingException;
     
    1819import tudelft.utilities.junit.GeneralTests;
    1920
     21@RunWith(JUnit4ClassRunner.class)
    2022public class SessionStartedTest extends GeneralTests<SessionStarted> {
    2123
    22         private final ObjectMapper jackson = new ObjectMapper();
     24        private final static @NonNull ObjectMapper jackson = new ObjectMapper();
    2325
    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;
    2729
    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");
    3032
    31         private static List<PartyId> parties = Arrays.asList(PARTY1, PARTY2);
     33        private static @NonNull List<@NonNull PartyId> parties = Arrays
     34                        .asList(PARTY1, PARTY2);
    3235
    33         private static final SessionStarted sessionStartedLater = new SessionStarted(
     36        private static final @NonNull SessionStarted sessionStartedLater = new SessionStarted(
    3437                        SESSIONNR, parties, NOW1);
    35         private static final SessionStarted othersessionStarted = new SessionStarted(
     38        private static final @NonNull SessionStarted othersessionStarted = new SessionStarted(
    3639                        SESSIONNR + 1, parties, NOW);
    3740
    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(
    4144                        SESSIONNR, parties, NOW);
    4245        // 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}}";
    4447        // "{\"sessionstarted\":{\"time\":101,\"sessionNumber\":1,\"parties\":[\"party1\",\"party2\"]}}";
    45         public static String expectedstring = "SessionStarted.*101.*";
     48        public static @NonNull String expectedstring = "SessionStarted.*101.*";
    4649
    4750        @Override
    4851        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;
    5457        }
    5558
    5659        @Override
    5760        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() + ".*");
    6168        }
    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")
    7569
    7670        @Test
    7771        public void serializeStartedTest() throws JsonProcessingException {
    78                 System.out.println(jackson.writeValueAsString(sessionStarted));
     72                //System.out.println(jackson.writeValueAsString(sessionStarted));
    7973                assertEquals(sessionstartedstring,
    8074                                jackson.writeValueAsString(sessionStarted));
     
    8377        @Test
    8478        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);
    8781                assertEquals(SessionStarted.class, evt.getClass());
    88                 SessionStarted event = (SessionStarted) evt;
     82                final @NonNull SessionStarted event = (SessionStarted) evt;
    8983                // compare fields, as sessionended is a derived/new inner class
    9084                assertEquals(NOW, event.getTime());
  • events/src/test/java/geniusweb/events/TournamentStartedTest.java

    r52 r54  
    88import java.util.List;
    99
     10import org.eclipse.jdt.annotation.NonNull;
    1011import org.junit.Test;
     12import org.junit.internal.runners.JUnit4ClassRunner;
     13import org.junit.runner.RunWith;
    1114
    1215import com.fasterxml.jackson.core.JsonProcessingException;
     
    1518import tudelft.utilities.junit.GeneralTests;
    1619
     20@RunWith(JUnit4ClassRunner.class)
    1721public class TournamentStartedTest extends GeneralTests<TournamentStarted> {
    1822
    19         private final ObjectMapper jackson = new ObjectMapper();
     23        private final static @NonNull ObjectMapper jackson = new ObjectMapper();
    2024
    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;
    2529
    26         private static TournamentStarted tournamentStarted = new TournamentStarted(
     30        private final static @NonNull TournamentStarted tournamentStarted = new TournamentStarted(
    2731                        NSESSIONS, NOW);
    28         private static TournamentStarted tournamentStarteda = new TournamentStarted(
     32        private final static @NonNull TournamentStarted tournamentStarteda = new TournamentStarted(
    2933                        NSESSIONS, NOW);
    30         private TournamentStarted otherTournamentStarted = new TournamentStarted(
     34        private final static @NonNull TournamentStarted otherTournamentStarted = new TournamentStarted(
    3135                        NSESSIONS + 1, NOW);
    32         private TournamentStarted tournamentStartedLater = new TournamentStarted(
     36        private final static @NonNull TournamentStarted tournamentStartedLater = new TournamentStarted(
    3337                        NSESSIONS, NOW1);
    3438
    35         private String tournamentstartedstring = "{\"TournamentStarted\":{\"time\":101,\"numberOfSessions\":5}}";
     39        private String tournamentstartedstring = "{\"TournamentStarted\":{\"numberOfSessions\":5,\"time\":101}}";
    3640
    3741        @Override
    3842        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;
    4448        }
    4549
     
    4751        public List<String> getGeneralTestStrings() {
    4852                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() + ".*\\]");
    5359        }
    5460
     
    5662        public void serializeTournamentStartedTest()
    5763                        throws JsonProcessingException {
    58                 System.out.println(jackson.writeValueAsString(tournamentStarted));
     64                //System.out.println(jackson.writeValueAsString(tournamentStarted));
    5965                assertEquals(tournamentstartedstring,
    6066                                jackson.writeValueAsString(tournamentStarted));
     
    6369        @Test
    6470        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);
    6773                assertEquals(TournamentStarted.class, evt.getClass());
    68                 TournamentStarted event = (TournamentStarted) evt;
     74                final @NonNull TournamentStarted event = (TournamentStarted) evt;
    6975                // compare fields, as sessionended is a derived/new inner class
    7076                assertEquals(NSESSIONS, event.getNumberOfSessions());
    7177                assertEquals(NOW, event.getTime());
    72         }
    73 
    74         @Test(expected = IllegalArgumentException.class)
    75         public void testNullTime() {
    76                 new TournamentStarted(NSESSIONS, null);
    7778        }
    7879
  • events/src/test/java/geniusweb/inform/ActionDoneTest.java

    r52 r54  
    77import java.util.List;
    88
    9 import org.junit.Before;
     9import org.eclipse.jdt.annotation.NonNull;
    1010import org.junit.Test;
     11import org.junit.internal.runners.JUnit4ClassRunner;
     12import org.junit.runner.RunWith;
    1113
    1214import com.fasterxml.jackson.core.JsonProcessingException;
     
    1820import tudelft.utilities.junit.GeneralTests;
    1921
     22@RunWith(JUnit4ClassRunner.class)
    2023public class ActionDoneTest extends GeneralTests<ActionDone> {
    21         private final ObjectMapper jackson = new ObjectMapper();
     24        private final @NonNull ObjectMapper jackson = new ObjectMapper();
    2225
    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");
    2528
    26         private final String actiondonestr = "{\"ActionDone\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}}}}";
     29        private final @NonNull String actiondonestr = "{\"ActionDone\":{\"action\":{\"EndNegotiation\":{\"actor\":\"party1\"}}}}";
    2730
    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);
    3033
    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);
    3437
    3538        @Override
     
    4548        }
    4649
    47         @Before
    48         public void before() {
    49 
    50         }
    51 
    5250        @Test
    5351        public void serializeAcceptTest() throws JsonProcessingException {
    54                 System.out.println(jackson.writeValueAsString(done1));
     52                //System.out.println(jackson.writeValueAsString(done1));
    5553                assertEquals(actiondonestr, jackson.writeValueAsString(done1));
    5654        }
     
    5856        @Test
    5957        public void deserializeAcceptTest() throws IOException {
    60                 Inform act = jackson.readValue(actiondonestr, Inform.class);
     58                final @NonNull Inform act = jackson.readValue(actiondonestr,
     59                                Inform.class);
    6160                assertEquals(done1, act);
    6261        }
  • events/src/test/java/geniusweb/inform/AgreementsTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    89import java.util.HashSet;
    910import java.util.List;
     11import java.util.Map;
    1012
    11 import org.junit.Before;
     13import org.eclipse.jdt.annotation.NonNull;
    1214import org.junit.Test;
     15import org.junit.internal.runners.JUnit4ClassRunner;
     16import org.junit.runner.RunWith;
    1317
    1418import com.fasterxml.jackson.core.JsonProcessingException;
     
    2125import tudelft.utilities.junit.GeneralTests;
    2226
     27@RunWith(JUnit4ClassRunner.class)
    2328public class AgreementsTest extends GeneralTests<Agreements> {
    24         private final ObjectMapper jackson = new ObjectMapper();
     29        private final @NonNull ObjectMapper jackson = new ObjectMapper();
    2530
    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(
    3035                        Collections.singletonMap("issue1", VALUE1));
    31         private static Bid bid2 = new Bid(
     36        private static @NonNull Bid bid2 = new Bid(
    3237                        Collections.singletonMap("issue2", VALUE1));
    3338
    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.*";
    3541
    36         private final static Agreements agrees1 = new Agreements(
     42        private final static @NonNull Agreements agrees1 = new Agreements(
    3743                        Collections.singletonMap(id, bid));
    38         private final static Agreements agrees1a = new Agreements(
     44        private final static @NonNull Agreements agrees1a = new Agreements(
    3945                        Collections.singletonMap(id, bid));
    40         private final static Agreements agrees2 = new Agreements(
     46        private final static @NonNull Agreements agrees2 = new Agreements(
    4147                        Collections.singletonMap(id2, bid));
    42         private final static Agreements agrees3 = new Agreements(
     48        private final static @NonNull Agreements agrees3 = new Agreements(
    4349                        Collections.singletonMap(id, bid2));
    4450
     
    5662        }
    5763
    58         @Before
    59         public void before() {
    60 
    61         }
    62 
    6364        @Test
    6465        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));
    6769        }
    6870
    6971        @Test
    7072        public void deserializeAcceptTest() throws IOException {
    71                 Agreements act = jackson.readValue(finishedstring, Agreements.class);
     73                final @NonNull Agreements act = jackson.readValue(finishedstring,
     74                                Agreements.class);
    7275                assertEquals(agrees1, act);
    7376        }
    7477
    75         @SuppressWarnings("unused")
    76         @Test
     78        @Test(expected = NullPointerException.class)
    7779        public void testNull() {
    78                 new Agreements();
     80                new Agreements((Map<@NonNull PartyId, @NonNull Bid>) getNull());
    7981        }
    8082
     
    8789        public void testWith() {
    8890                Agreements agrees = agrees1.with(agrees2);
    89                 assertEquals(bid, agrees.getMap().get(id));
    90                 assertEquals(bid, agrees.getMap().get(id2));
     91                assertEquals(bid, agrees.getAgreements().get(id));
     92                assertEquals(bid, agrees.getAgreements().get(id2));
    9193        }
    9294
    9395        @Test
    9496        public void testBidConstructor() {
    95                 Agreements agrees = new Agreements(bid,
     97                Agreements agrees = Agreements.create(bid,
    9698                                new HashSet<PartyId>(Arrays.asList(id, id2)));
    97                 assertEquals(bid, agrees.getMap().get(id));
    98                 assertEquals(bid, agrees.getMap().get(id2));
     99                assertEquals(bid, agrees.getAgreements().get(id));
     100                assertEquals(bid, agrees.getAgreements().get(id2));
    99101        }
     102
     103        private Object getNull() {
     104                return null;
     105        }
     106
    100107}
  • events/src/test/java/geniusweb/inform/FinishedTest.java

    r52 r54  
    88import java.util.List;
    99
     10import org.eclipse.jdt.annotation.NonNull;
    1011import org.junit.Before;
    1112import org.junit.Test;
     13import org.junit.internal.runners.JUnit4ClassRunner;
     14import org.junit.runner.RunWith;
    1215
    1316import com.fasterxml.jackson.core.JsonProcessingException;
     
    2023import tudelft.utilities.junit.GeneralTests;
    2124
     25@RunWith(JUnit4ClassRunner.class)
    2226public class FinishedTest extends GeneralTests<Finished> {
    23         private final ObjectMapper jackson = new ObjectMapper();
     27        private final @NonNull ObjectMapper jackson = new ObjectMapper();
    2428
    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(
    2933                        Collections.singletonMap("issue1", VALUE1));
    3034
    31         private final String finishedstring = "{\"Finished\":{\"agreements\":{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}}}";
     35        private final @NonNull String finishedstring = "{\"Finished\":{\"agreements\":{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}}}";
    3236
    33         private final static Agreements agrees1 = new Agreements(
     37        private final static @NonNull Agreements agrees1 = new Agreements(
    3438                        Collections.singletonMap(id, bid));
    35         private final static Agreements agrees2 = new Agreements(
     39        private final static @NonNull Agreements agrees2 = new Agreements(
    3640                        Collections.singletonMap(id2, bid));
    3741
    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);
    4145
    4246        @Override
     
    5963        @Test
    6064        public void serializeAcceptTest() throws JsonProcessingException {
    61                 System.out.println(jackson.writeValueAsString(finished1));
     65                //System.out.println(jackson.writeValueAsString(finished1));
    6266                assertEquals(finishedstring, jackson.writeValueAsString(finished1));
    6367        }
     
    6569        @Test
    6670        public void deserializeAcceptTest() throws IOException {
    67                 Inform act = jackson.readValue(finishedstring, Inform.class);
     71                final @NonNull Inform act = jackson.readValue(finishedstring,
     72                                Inform.class);
    6873                assertEquals(finished1, act);
    6974        }
     
    7176        @Test(expected = NullPointerException.class)
    7277        public void testNull() {
    73                 new Finished(null);
     78                new Finished(nullFinish());
     79        }
     80
     81        private Agreements nullFinish() {
     82                return null;
    7483        }
    7584
  • events/src/test/java/geniusweb/inform/OptInTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    910import java.util.List;
    1011
     12import org.eclipse.jdt.annotation.NonNull;
    1113import org.junit.Test;
     14import org.junit.internal.runners.JUnit4ClassRunner;
     15import org.junit.runner.RunWith;
    1216
    1317import com.fasterxml.jackson.core.JsonParseException;
     
    2327import tudelft.utilities.junit.GeneralTests;
    2428
     29@RunWith(JUnit4ClassRunner.class)
    2530public class OptInTest extends GeneralTests<OptIn> {
     31        private static final @NonNull ObjectMapper jackson = new ObjectMapper();
    2632
    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");
    3139
    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);
    3543
    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,
    3847                        new HashSet<>(Arrays.asList(voteB1, voteB2)));
    3948
    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));
    4355
    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.*))+.*";
    4562
    4663        @Override
     
    5370        public List<String> getGeneralTestStrings() {
    5471                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))+.*",
    5673                                "OptIn.*Votes.*Vote.*partyA.*iss.*val.*2.*");
    5774        }
     
    5976        @Test
    6077        public void testSerialize() throws JsonProcessingException {
    61                 ObjectMapper jackson = new ObjectMapper();
    6278
    63                 String json = jackson.writeValueAsString(optIn1);
    64                 System.out.println(json);
    65                 assertEquals(asJson, json);
     79                final @NonNull String jsonstr = jackson.writeValueAsString(optIn1);
     80                //System.out.println(json);
     81                assertTrue(jsonstr.matches(asJsonpat));
    6682        }
    6783
     
    6985        public void testDeserialize()
    7086                        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);
    7489                assertEquals(optIn1, p);
    7590        }
  • events/src/test/java/geniusweb/inform/OptInWithValueTest.java

    r52 r54  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45
    56import java.io.IOException;
     
    910import java.util.List;
    1011
     12import org.eclipse.jdt.annotation.NonNull;
    1113import org.junit.Test;
     14import org.junit.internal.runners.JUnit4ClassRunner;
     15import org.junit.runner.RunWith;
    1216
    1317import com.fasterxml.jackson.core.JsonParseException;
     
    2327import tudelft.utilities.junit.GeneralTests;
    2428
     29@RunWith(JUnit4ClassRunner.class)
    2530public class OptInWithValueTest extends GeneralTests<OptInWithValue> {
     31        private static final @NonNull ObjectMapper jackson = new ObjectMapper();
    2632
    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");
    3139
    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);
    3846
    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)));
    4351
    44         private final OptInWithValue optIn1 = new OptInWithValue(
     52        private static final @NonNull OptInWithValue optIn1 = new OptInWithValue(
    4553                        Arrays.asList(votesA, votesB));
    46         private final OptInWithValue optIn1a = new OptInWithValue(
     54        private static final @NonNull OptInWithValue optIn1a = new OptInWithValue(
    4755                        Arrays.asList(votesA, votesB));
    48         private final OptInWithValue optIn2 = new OptInWithValue(
     56        private static final @NonNull OptInWithValue optIn2 = new OptInWithValue(
    4957                        Arrays.asList(votesA));
    5058
    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))+.*";
    5266
    5367        @Override
     
    6074        public List<String> getGeneralTestStrings() {
    6175                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))+.*",
    6378                                "OptIn.*Votes.*Vote.*partyA.*iss.*val.*2.*");
    6479        }
     
    6681        @Test
    6782        public void testSerialize() throws JsonProcessingException {
    68                 ObjectMapper jackson = new ObjectMapper();
    6983
    70                 String json = jackson.writeValueAsString(optIn1);
    71                 System.out.println(json);
    72                 assertEquals(asJson, json);
     84                final @NonNull String jsonstr = jackson.writeValueAsString(optIn1);
     85                //System.out.println(json);
     86                assertTrue(jsonstr.matches(asJsonpat));
    7387        }
    7488
     
    7690        public void testDeserialize()
    7791                        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);
    8194                assertEquals(optIn1, p);
    8295        }
  • events/src/test/java/geniusweb/inform/SettingsTest.java

    r52 r54  
    77import java.net.URISyntaxException;
    88import java.util.Arrays;
     9import java.util.Collections;
    910import java.util.Date;
    1011import java.util.HashMap;
     
    1213import java.util.Map;
    1314
     15import org.eclipse.jdt.annotation.NonNull;
    1416import org.junit.Before;
    1517import org.junit.Test;
     18import org.junit.internal.runners.JUnit4ClassRunner;
     19import org.junit.runner.RunWith;
    1620
    1721import com.fasterxml.jackson.core.JsonParseException;
     
    2832import tudelft.utilities.junit.GeneralTests;
    2933
     34@RunWith(JUnit4ClassRunner.class)
    3035public class SettingsTest extends GeneralTests<Settings> {
    3136
    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");
    3439
    35         private final String asJson = "{\"Settings\":"
     40        private final @NonNull String asJson = "{\"Settings\":"
    3641                        + "{\"id\":\"party1\",\"profile\":\"ws:profile1\","
    3742                        + "\"protocol\":\"ws:localhost/protocol1\","
    3843                        + "\"progress\":{\"ProgressRounds\":{\"duration\":10,\"currentRound\":0,\"endtime\":999}},"
    3944                        + "\"parameters\":{}}}";
     45        private final @NonNull Date date = new Date(999);
     46        private final static @NonNull ObjectMapper jackson = new ObjectMapper();
    4047
    4148        private Settings negoinfo1, negoinfo1a;
    4249        private Settings negoinfo2, negoinfo3, negoinfo4, negoinfo5;
    43         private final Date date = new Date(999);
    44         private final static ObjectMapper jackson = new ObjectMapper();
    4550
    4651        @Before
     
    4853                        JsonMappingException, IOException {
    4954                // 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"));
    5157                // jackson.readValue(serialized, Profile.class);
    5258
    53                 ProtocolRef protocol1 = new ProtocolRef(
     59                final @NonNull ProtocolRef protocol1 = new ProtocolRef(
    5460                                new URI("ws:localhost/protocol1"));
    55                 ProtocolRef protocol1a = new ProtocolRef(
     61                final @NonNull ProtocolRef protocol1a = new ProtocolRef(
    5662                                new URI("ws:localhost/protocol1"));
    57                 ProtocolRef protocol2 = new ProtocolRef(
     63                final @NonNull ProtocolRef protocol2 = new ProtocolRef(
    5864                                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);
    6271
    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);
    6575
    6676                negoinfo1 = new Settings(id, profile1, protocol1, progress1, settings1);
     
    98108        @Test(expected = IllegalArgumentException.class)
    99109        public void nullTest() throws URISyntaxException {
    100                 new PartyRef((URI) null);
     110                new PartyRef(nullUri());
    101111        }
    102112
     
    104114        public void testSerialize() throws JsonProcessingException {
    105115
    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);
    109119        }
    110120
     
    112122        public void testDeserialize()
    113123                        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);
    116127                assertEquals(negoinfo1, p);
    117128        }
     
    120131        public void testGeneralDict()
    121132                        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;
    125140        }
    126141
  • events/src/test/java/geniusweb/inform/VotingTest.java

    r52 r54  
    99import java.util.Map;
    1010
     11import org.eclipse.jdt.annotation.NonNull;
    1112import org.junit.Test;
     13import org.junit.internal.runners.JUnit4ClassRunner;
     14import org.junit.runner.RunWith;
    1215
    1316import com.fasterxml.jackson.core.JsonParseException;
     
    2225import tudelft.utilities.junit.GeneralTests;
    2326
     27@RunWith(JUnit4ClassRunner.class)
    2428public class VotingTest extends GeneralTests<Voting> {
     29        private final @NonNull ObjectMapper jackson = new ObjectMapper();
    2530
    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")));
    2936
    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);
    3241
    33         private final Voting voting1 = new Voting(
     42        private final @NonNull Voting voting1 = new Voting(
    3443                        Arrays.asList(new Offer(party1, bid1)), powers1);
    35         private final Voting voting1a = new Voting(
     44        private final @NonNull Voting voting1a = new Voting(
    3645                        Arrays.asList(new Offer(party1, bid1)), powers1);
    37         private final Voting voting2 = new Voting(
     46        private final @NonNull Voting voting2 = new Voting(
    3847                        Arrays.asList(new Offer(party1, bid2)), powers1);
    39         private final Voting voting3 = new Voting(
     48        private final @NonNull Voting voting3 = new Voting(
    4049                        Arrays.asList(new Offer(party1, bid1)), powers2);
    4150
     
    5766        @Test
    5867        public void testSerialize() throws JsonProcessingException {
    59                 ObjectMapper jackson = new ObjectMapper();
    6068
    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);
    6472        }
    6573
     
    6775        public void testDeserialize()
    6876                        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);
    7279                assertEquals(voting1, p);
    7380        }
  • events/src/test/java/geniusweb/inform/YourTurnTest.java

    r52 r54  
    44
    55import java.io.IOException;
    6 import java.net.URISyntaxException;
    76import java.util.Arrays;
    87import java.util.List;
    98
    10 import org.junit.Before;
     9import org.eclipse.jdt.annotation.NonNull;
    1110import org.junit.Test;
     11import org.junit.internal.runners.JUnit4ClassRunner;
     12import org.junit.runner.RunWith;
    1213
    1314import com.fasterxml.jackson.core.JsonParseException;
     
    1819import tudelft.utilities.junit.GeneralTests;
    1920
     21class YourTurnAlt extends YourTurn {
     22        @Override
     23        public int hashCode() {
     24                return 2;
     25        }
     26}
     27
     28@RunWith(JUnit4ClassRunner.class)
    2029public class YourTurnTest extends GeneralTests<YourTurn> {
     30        private final static @NonNull ObjectMapper jackson = new ObjectMapper();
    2131
    22         private YourTurn yourturn1, yourturn1b;
     32        private final @NonNull YourTurn yourturn1 = new YourTurn(),
     33                        yourturn1b = new YourTurn();
    2334
    24         private String asJson = "{\"YourTurn\":{}}";
     35        private final static @NonNull String asJson = "{\"YourTurn\":{}}";
    2536
    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();
    4038
    4139        @Override
     
    5250        @Test
    5351        public void testSerialize() throws JsonProcessingException {
    54                 ObjectMapper jackson = new ObjectMapper();
    5552
    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);
    5956        }
    6057
     
    6259        public void testDeserialize()
    6360                        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);
    6764                assertEquals(yourturn1, p);
    6865        }
Note: See TracChangeset for help on using the changeset viewer.