//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void eventShouldBubbleUp() public virtual void EventShouldBubbleUp() { Monitors parent = new Monitors(); MyMonitor parentListener = mock(typeof(MyMonitor)); parent.AddMonitorListener(parentListener); Monitors child = new Monitors(parent); MyMonitor childListener = mock(typeof(MyMonitor)); child.AddMonitorListener(childListener); // Calls on monitors from parent should not reach child listeners MyMonitor parentMonitor = parent.NewMonitor(typeof(MyMonitor)); parentMonitor.AVoid(); verify(parentListener, times(1)).aVoid(); verifyZeroInteractions(childListener); // Calls on monitors from child should reach both listeners MyMonitor childMonitor = child.NewMonitor(typeof(MyMonitor)); childMonitor.AVoid(); verify(parentListener, times(2)).aVoid(); verify(childListener, times(1)).aVoid(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldProvideNoOpDelegate() public virtual void ShouldProvideNoOpDelegate() { // Given Monitors monitors = new Monitors(); // When MyMonitor monitor = monitors.NewMonitor(typeof(MyMonitor)); // Then those should be no-ops monitor.AVoid(); monitor.TakesArgs("ha", 12, new object()); }
public override object Invoke(object proxy, System.Reflection.MethodInfo method, object[] args) { InvokeMonitorListeners(Monitor, Tags, proxy, method, args); // Bubble up Monitors current = Monitor.parent; while (current != null) { InvokeMonitorListeners(current, Tags, proxy, method, args); current = current._parent; } return(null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRegister() public virtual void ShouldRegister() { // Given Monitors monitors = new Monitors(); MyMonitor listener = mock(typeof(MyMonitor)); MyMonitor monitor = monitors.NewMonitor(typeof(MyMonitor)); object obj = new object(); // When monitors.AddMonitorListener(listener); monitor.AVoid(); monitor.TakesArgs("ha", 12, obj); // Then verify(listener).aVoid(); verify(listener).takesArgs("ha", 12, obj); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void multipleListenersRegistration() public virtual void MultipleListenersRegistration() { Monitors monitors = new Monitors(); MyMonitor listener1 = mock(typeof(MyMonitor)); MyMonitor listener2 = mock(typeof(MyMonitor)); assertFalse(monitors.HasListeners(typeof(MyMonitor))); monitors.AddMonitorListener(listener1); monitors.AddMonitorListener(listener2); assertTrue(monitors.HasListeners(typeof(MyMonitor))); monitors.RemoveMonitorListener(listener1); assertTrue(monitors.HasListeners(typeof(MyMonitor))); monitors.RemoveMonitorListener(listener2); assertFalse(monitors.HasListeners(typeof(MyMonitor))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUnregister() public virtual void ShouldUnregister() { // Given Monitors monitors = new Monitors(); MyMonitor listener = mock(typeof(MyMonitor)); MyMonitor monitor = monitors.NewMonitor(typeof(MyMonitor)); object obj = new object(); monitors.AddMonitorListener(listener); // When monitors.RemoveMonitorListener(listener); monitor.AVoid(); monitor.TakesArgs("ha", 12, obj); // Then verifyNoMoreInteractions(listener); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRespectTags() public virtual void ShouldRespectTags() { // Given Monitors monitors = new Monitors(); MyMonitor listener = mock(typeof(MyMonitor)); MyMonitor monitorTag1 = monitors.NewMonitor(typeof(MyMonitor), "tag1"); MyMonitor monitorTag2 = monitors.NewMonitor(typeof(MyMonitor), "tag2"); // When monitors.AddMonitorListener(listener, "tag2"); // Then monitorTag1.AVoid(); verifyZeroInteractions(listener); monitorTag2.AVoid(); verify(listener, times(1)).aVoid(); verifyNoMoreInteractions(listener); }
internal static void InvokeMonitorListeners(Monitors monitor, string[] tags, object proxy, System.Reflection.MethodInfo method, object[] args) { ISet <MonitorListenerInvocationHandler> handlers = monitor._methodMonitorListeners[method]; if (handlers == null || handlers.Count == 0) { return; } foreach (MonitorListenerInvocationHandler monitorListenerInvocationHandler in handlers) { try { monitorListenerInvocationHandler.Invoke(proxy, method, args, tags); } catch (Exception) { } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTellIfMonitorHasListeners() public virtual void ShouldTellIfMonitorHasListeners() { // Given Monitors monitors = new Monitors(); MyMonitor listener = mock(typeof(MyMonitor)); // When I have a monitor with no listeners monitors.NewMonitor(typeof(MyMonitor)); // Then assertFalse(monitors.HasListeners(typeof(MyMonitor))); // When I add a listener monitors.AddMonitorListener(listener); // Then assertTrue(monitors.HasListeners(typeof(MyMonitor))); // When that listener is removed again monitors.RemoveMonitorListener(listener); // Then assertFalse(monitors.HasListeners(typeof(MyMonitor))); }
/// <summary> /// Create a child monitor with a given {@code parent}. Propagation works as expected where you can subscribe to /// global monitors through the child monitor, but not the other way around. E.g. you can not subscribe to monitors /// that are registered on the child monitor through the parent monitor. /// <para> /// Events will bubble up from the children in a way that listeners on the child monitor will be invoked before the /// parent ones. /// /// </para> /// </summary> /// <param name="parent"> to propagate events to and from. </param> public Monitors(Monitors parent) { this._parent = parent; }
internal MonitorInvocationHandler(Monitors monitor, params string[] tags) { this.Monitor = monitor; this.Tags = tags; }