This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch maint-1.16.1
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/maint-1.16.1 by this push:
     new 8c2c403  ISIS-1847: adds missing breaks in veto handling of 
AbstractDomainEvent
8c2c403 is described below

commit 8c2c4038ede2927290dbfab4ba41f146970546c8
Author: Dan Haywood <d...@haywood-associates.co.uk>
AuthorDate: Tue Feb 13 18:00:49 2018 +0000

    ISIS-1847: adds missing breaks in veto handling of AbstractDomainEvent
    
    with some unit tests to specify exact behaviour.
---
 .../services/eventbus/AbstractDomainEvent.java     |  12 ++
 .../eventbus/AbstractDomainEvent_veto_Test.java    | 165 +++++++++++++++++++++
 2 files changed, 177 insertions(+)

diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AbstractDomainEvent.java
 
b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AbstractDomainEvent.java
index aa81a4b..bba4e98 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AbstractDomainEvent.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/services/eventbus/AbstractDomainEvent.java
@@ -245,10 +245,19 @@ public abstract class AbstractDomainEvent<S> extends 
java.util.EventObject {
         switch (getEventPhase()) {
             case HIDE:
                 hide();
+                break;
             case DISABLE:
+                if(reason == null) {
+                    throw new IllegalArgumentException("Reason must be 
non-null");
+                }
                 disable(String.format(reason, args));
+                break;
             case VALIDATE:
+                if(reason == null) {
+                    throw new IllegalArgumentException("Reason must be 
non-null");
+                }
                 invalidate(String.format(reason, args));
+                break;
         }
     }
     /**
@@ -268,10 +277,13 @@ public abstract class AbstractDomainEvent<S> extends 
java.util.EventObject {
         switch (getEventPhase()) {
             case HIDE:
                 hide();
+                break;
             case DISABLE:
                 disable(translatableReason);
+                break;
             case VALIDATE:
                 invalidate(translatableReason);
+                break;
         }
     }
     //endregion
diff --git 
a/core/applib/src/test/java/org/apache/isis/applib/services/eventbus/AbstractDomainEvent_veto_Test.java
 
b/core/applib/src/test/java/org/apache/isis/applib/services/eventbus/AbstractDomainEvent_veto_Test.java
new file mode 100644
index 0000000..2092b47
--- /dev/null
+++ 
b/core/applib/src/test/java/org/apache/isis/applib/services/eventbus/AbstractDomainEvent_veto_Test.java
@@ -0,0 +1,165 @@
+package org.apache.isis.applib.services.eventbus;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import org.apache.isis.applib.services.i18n.TranslatableString;
+
+public class AbstractDomainEvent_veto_Test {
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    AbstractDomainEvent ev = new AbstractDomainEvent() { };
+
+    @Test
+    public void hidden_phase_and_veto_using_null() throws Exception {
+
+        // given
+        ev.setEventPhase(AbstractDomainEvent.Phase.HIDE);
+
+        // when
+        ev.veto((String)null);
+
+        // then ... vetoes
+        Assert.assertTrue(ev.isHidden());
+        Assert.assertFalse(ev.isDisabled());
+        Assert.assertNull(ev.getDisabledReason());
+        Assert.assertFalse(ev.isInvalid());
+        Assert.assertNull(ev.getInvalidityReason());
+    }
+
+    @Test
+    public void hidden_phase_and_veto_using_non_null_string() throws Exception 
{
+        // given
+        ev.setEventPhase(AbstractDomainEvent.Phase.HIDE);
+
+        // when
+        ev.veto("hidden");
+
+        // then ... vetoes
+        Assert.assertTrue(ev.isHidden());
+        Assert.assertFalse(ev.isDisabled());
+        Assert.assertNull(ev.getDisabledReason());
+        Assert.assertFalse(ev.isInvalid());
+        Assert.assertNull(ev.getInvalidityReason());
+    }
+
+    @Test
+    public void hidden_phase_and_veto_using_translatable() throws Exception {
+        // given
+        ev.setEventPhase(AbstractDomainEvent.Phase.HIDE);
+
+        // when
+        final TranslatableString reason = TranslatableString.tr("hidden");
+        ev.veto(reason);
+
+        // then ... vetoes
+        Assert.assertTrue(ev.isHidden());
+        Assert.assertFalse(ev.isDisabled());
+        Assert.assertNull(ev.getDisabledReason());
+        Assert.assertFalse(ev.isInvalid());
+        Assert.assertNull(ev.getInvalidityReason());
+    }
+
+    @Test
+    public void disable_phase_and_attempt_to_veto_with_null() throws Exception 
{
+
+        // given
+        final AbstractDomainEvent ev = new AbstractDomainEvent() {
+        };
+        ev.setEventPhase(AbstractDomainEvent.Phase.DISABLE);
+
+        // expect
+        expectedException.expect(IllegalArgumentException.class);
+
+        // when
+        ev.veto((String)null);
+    }
+
+    @Test
+    public void disable_phase_and_veto_using_non_null_string() throws 
Exception {
+        // given
+        ev.setEventPhase(AbstractDomainEvent.Phase.DISABLE);
+
+        // when
+        final String reason = "no, you can't do that";
+        ev.veto(reason);
+
+        // then
+        Assert.assertFalse(ev.isHidden());
+        Assert.assertTrue(ev.isDisabled());
+        Assert.assertEquals(reason, ev.getDisabledReason());
+        Assert.assertFalse(ev.isInvalid());
+        Assert.assertNull(ev.getInvalidityReason());
+    }
+
+    @Test
+    public void disable_phase_and_veto_using_translatable() throws Exception {
+        // given
+        ev.setEventPhase(AbstractDomainEvent.Phase.DISABLE);
+
+        // when
+        final TranslatableString reason = TranslatableString.tr("no, you can't 
do that");
+        ev.veto(reason);
+
+        // then
+        Assert.assertFalse(ev.isHidden());
+        Assert.assertTrue(ev.isDisabled());
+        Assert.assertEquals(reason, ev.getDisabledReasonTranslatable());
+        Assert.assertFalse(ev.isInvalid());
+        Assert.assertNull(ev.getInvalidityReason());
+    }
+
+    @Test
+    public void validate_phase_and_attempt_to_veto_with_null() throws 
Exception {
+
+        // given
+        ev.setEventPhase(AbstractDomainEvent.Phase.VALIDATE);
+
+        // expect
+        expectedException.expect(IllegalArgumentException.class);
+
+        // when
+        ev.veto((String)null);
+    }
+
+    @Test
+    public void validate_phase_and_veto_using_non_null_string() throws 
Exception {
+
+        // given
+        ev.setEventPhase(AbstractDomainEvent.Phase.VALIDATE);
+
+        // when
+        final String reason = "no, you can't do that";
+        ev.veto(reason);
+
+        // then
+        Assert.assertFalse(ev.isHidden());
+        Assert.assertFalse(ev.isDisabled());
+        Assert.assertNull(ev.getDisabledReason());
+        Assert.assertTrue(ev.isInvalid());
+        Assert.assertEquals(reason, ev.getInvalidityReason());
+    }
+
+    @Test
+    public void validate_phase_and_veto_using_translatable() throws Exception {
+
+        // given
+        ev.setEventPhase(AbstractDomainEvent.Phase.VALIDATE);
+
+        // when
+        final TranslatableString reason = TranslatableString.tr("no, you can't 
do that");
+        ev.veto(reason);
+
+        // then
+        Assert.assertFalse(ev.isHidden());
+        Assert.assertFalse(ev.isDisabled());
+        Assert.assertNull(ev.getDisabledReason());
+        Assert.assertTrue(ev.isInvalid());
+        Assert.assertEquals(reason, ev.getInvalidityReasonTranslatable());
+    }
+
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
danhayw...@apache.org.

Reply via email to