1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.aspectj;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
|
14
|
import java.beans.PropertyChangeEvent;
|
15
|
import java.beans.PropertyChangeListener;
|
16
|
|
17
|
import org.apache.log4j.Level;
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.Test;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
23
|
import eu.etaxonomy.cdm.model.name.Rank;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
26
|
|
27
|
public class PropertyChangeTest implements PropertyChangeListener {
|
28
|
static Logger logger = Logger.getLogger(PropertyChangeTest.class);
|
29
|
private Object lastPropValue;
|
30
|
|
31
|
@Override
|
32
|
public void propertyChange(PropertyChangeEvent e){
|
33
|
logger.debug("Property [" + e.getPropertyName()
|
34
|
+ "] changed from " + e.getOldValue()
|
35
|
+ " to " + e.getNewValue());
|
36
|
lastPropValue = e.getNewValue() == null ? null : e.getNewValue();
|
37
|
}
|
38
|
|
39
|
@Test
|
40
|
public void testPropertyChange() {
|
41
|
INonViralName b = TaxonNameFactory.NewNonViralInstance(Rank.SPECIES());
|
42
|
((TaxonName<?,?>)b).addPropertyChangeListener(this);
|
43
|
b.setGenusOrUninomial("Abies");
|
44
|
assertEquals(b.getGenusOrUninomial(), lastPropValue);
|
45
|
b.setGenusOrUninomial("Picea");
|
46
|
assertEquals(b.getGenusOrUninomial(), lastPropValue);
|
47
|
b.setGenusOrUninomial("Unipicea");
|
48
|
assertEquals(b.getGenusOrUninomial(), lastPropValue);
|
49
|
b.setSpecificEpithet("vulgaris");
|
50
|
assertEquals(b.getSpecificEpithet(), lastPropValue);
|
51
|
b.setParsingProblem(2);
|
52
|
assertEquals(b.getParsingProblem(), lastPropValue);
|
53
|
}
|
54
|
|
55
|
@Test
|
56
|
public void testPropertyChangeBoolean() {
|
57
|
TaxonName b = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
|
58
|
b.addPropertyChangeListener(this);
|
59
|
b.setAnamorphic(true);
|
60
|
assertEquals(b.isAnamorphic(), lastPropValue);
|
61
|
}
|
62
|
|
63
|
@Before
|
64
|
public void updateDebugLevel(){
|
65
|
logger.setLevel(Level.INFO);
|
66
|
}
|
67
|
|
68
|
}
|
69
|
|