Coverage Report - com.nilhcem.fakesmtp.model.UIModel
 
Classes in this File Line Coverage Branch Coverage Complexity
UIModel
79%
23/29
100%
4/4
1.273
 
 1  
 package com.nilhcem.fakesmtp.model;
 2  
 
 3  
 import java.util.HashMap;
 4  
 import java.util.List;
 5  
 import java.util.Map;
 6  
 import com.nilhcem.fakesmtp.core.I18n;
 7  
 import com.nilhcem.fakesmtp.core.exception.BindPortException;
 8  
 import com.nilhcem.fakesmtp.core.exception.InvalidPortException;
 9  
 import com.nilhcem.fakesmtp.core.exception.OutOfRangePortException;
 10  
 import com.nilhcem.fakesmtp.server.SMTPServerHandler;
 11  
 
 12  
 /**
 13  
  * UI presentation model of the application.
 14  
  * <p>
 15  
  * The essence of a Presentation Model is of a fully self-contained class that represents all the data
 16  
  * and behavior of the UI window, but without any of the controls used to render that UI on the screen.
 17  
  * </p>
 18  
  *
 19  
  * @author Nilhcem
 20  
  * @since 1.0
 21  
  * @see <a href="link">http://martinfowler.com/eaaDev/PresentationModel.html</a>
 22  
  */
 23  1
 public enum UIModel {
 24  1
         INSTANCE;
 25  
 
 26  1
         private boolean started = false; // server is not started by default
 27  
         private String portStr;
 28  1
         private int nbMessageReceived = 0;
 29  1
         private String savePath = I18n.INSTANCE.get("emails.default.dir");
 30  1
         private final Map<Integer, String> listMailsMap = new HashMap<Integer, String>();
 31  
         private List<String> relayDomains;
 32  
 
 33  1
         UIModel() {
 34  1
         }
 35  
 
 36  
         /**
 37  
          * Happens when a user clicks on the start button.
 38  
          * <p>
 39  
          * This method will notify the {@code SMTPServerHandler} to start the server.
 40  
          * </p>
 41  
          *
 42  
          * @throws InvalidPortException when the port is invalid.
 43  
          * @throws BindPortException when the port cannot be bound.
 44  
          * @throws OutOfRangePortException when the port is out of range.
 45  
          * @throws RuntimeException when an unknown exception happened.
 46  
          */
 47  
         public void toggleButton() throws BindPortException, OutOfRangePortException, InvalidPortException {
 48  3
                 if (started) {
 49  
                         // Do nothing. We can't stop the server. User has to quit the app (issue with SubethaSMTP)
 50  
                 } else {
 51  
                         int port;
 52  
 
 53  
                         try {
 54  2
                                 port = Integer.parseInt(portStr);
 55  1
                         } catch (NumberFormatException e) {
 56  1
                                 throw new InvalidPortException(e);
 57  1
                         }
 58  1
                         SMTPServerHandler.INSTANCE.startServer(port, null);
 59  
                 }
 60  2
                 started = !started;
 61  2
         }
 62  
 
 63  
         /**
 64  
          * Returns {@code true} if the server is started.
 65  
          *
 66  
          * @return {@code true} if the server is started.
 67  
          */
 68  
         public boolean isStarted() {
 69  3
                 return started;
 70  
         }
 71  
 
 72  
         public void setPort(String port) {
 73  2
                 this.portStr = port;
 74  2
         }
 75  
 
 76  
         public int getNbMessageReceived() {
 77  1
                 return nbMessageReceived;
 78  
         }
 79  
 
 80  
         public void setNbMessageReceived(int nbMessageReceived) {
 81  0
                 this.nbMessageReceived = nbMessageReceived;
 82  0
         }
 83  
 
 84  
         public String getSavePath() {
 85  1
                 return savePath;
 86  
         }
 87  
 
 88  
         public void setSavePath(String savePath) {
 89  0
                 this.savePath = savePath;
 90  0
         }
 91  
 
 92  
         public Map<Integer, String> getListMailsMap() {
 93  2
                 return listMailsMap;
 94  
         }
 95  
 
 96  
         public List<String> getRelayDomains() {
 97  1
                 return relayDomains;
 98  
         }
 99  
 
 100  
         public void setRelayDomains(List<String> relayDomains) {
 101  0
                 this.relayDomains = relayDomains;
 102  0
         }
 103  
 }