PageRenderTime 26ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 14ms app.codeStats 1ms

/src/test/java/org/exoplatform/social/client/core/service/PropertyChangeListenerTest.java

http://github.com/exosocial/exo.social.client
Java | 94 lines | 58 code | 17 blank | 19 comment | 0 complexity | 26675c79dc6f503d392f8c61bdc8ae69 MD5 | raw file
Possible License(s): AGPL-3.0
 1/*
 2 * Copyright (C) 2003-2011 eXo Platform SAS.
 3 *
 4 * This program is free software: you can redistribute it and/or modify
 5 * it under the terms of the GNU Affero General Public License as published by
 6 * the Free Software Foundation, either version 3 of the License, or
 7 * (at your option) any later version.
 8 *
 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17package org.exoplatform.social.client.core.service;
18
19import org.testng.annotations.AfterMethod;
20import org.testng.annotations.BeforeMethod;
21import org.testng.annotations.Test;
22
23import static org.testng.Assert.assertEquals;
24import static org.testng.Assert.assertNull;
25import static org.testng.Assert.assertTrue;
26
27/**
28 * Unit Test for {@link org.exoplatform.social.client.api.event.PropertyChangeListener}.
29 */
30public class PropertyChangeListenerTest extends AbstractLifecycleTest {
31
32  @BeforeMethod
33  public void setUp() throws Exception {
34    super.setUp();
35    capturePropertyChange = new MockPropertyChangeListener();
36    mockModel = new MockModel();
37    mockModel.addPropertyChangeListener(capturePropertyChange);
38  }
39  
40  @AfterMethod
41  public void tearDown() throws Exception {
42    super.tearDown();
43    capturePropertyChange = null;
44    mockModel = null;
45    
46  }
47  
48  @Test
49  public void checkPropertyChangeListener() throws Exception {
50    assertEquals(1, mockModel.findPropertyChangeListeners().length);
51  }
52  
53  @Test
54  public void handlePropertyChangeListener() throws Exception {
55    mockModel.setField(MockModel.Field.ID.toString(), "newValue");
56    assertTrue(capturePropertyChange.eventHolder.containsKey(MockModel.Field.ID.toString()));
57    assertEquals(MockModel.Field.ID.toString(),
58            capturePropertyChange.eventHolder.get(MockModel.Field.ID.toString()).getPropertyName());
59    assertEquals("newValue", capturePropertyChange.eventHolder.get(MockModel.Field.ID.toString()).getNewValue());
60    assertNull(capturePropertyChange.eventHolder.get(MockModel.Field.ID.toString()).getOldValue());
61  }
62  
63  @Test
64  public void checkOldValue() throws Exception {
65    mockModel.setField(MockModel.Field.ID.toString(), "oldValue");
66    mockModel.setField(MockModel.Field.ID.toString(), "newValue");
67    
68    assertEquals(1, capturePropertyChange.eventHolder.size());
69    assertTrue(capturePropertyChange.eventHolder.containsKey(MockModel.Field.ID.toString()));
70    assertEquals(MockModel.Field.ID.toString(),
71            capturePropertyChange.eventHolder.get(MockModel.Field.ID.toString()).getPropertyName());
72    assertEquals("newValue", capturePropertyChange.eventHolder.get(MockModel.Field.ID.toString()).getNewValue());
73    assertEquals("oldValue", capturePropertyChange.eventHolder.get(MockModel.Field.ID.toString()).getOldValue());
74  }
75  
76  @Test
77  public void checkRaiseEventCountSameField() throws Exception {
78    mockModel.setField(MockModel.Field.ID.toString(), "oldValue");
79    mockModel.setField(MockModel.Field.ID.toString(), "newValue");
80    assertEquals(capturePropertyChange.eventHolder.size(), 1);
81  }
82  @Test
83  public void checkRaiseEventCountNotSameField() throws Exception {
84    mockModel.setField(MockModel.Field.ID.toString(), "oldValue");
85    mockModel.setField(MockModel.Field.CONTENT.toString(), "oldContentValue");
86    
87    assertEquals(capturePropertyChange.eventHolder.size(), 2);
88   
89  }
90  
91  
92  
93  
94}