001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.shared;
034:
035: import com.flexive.shared.AbstractSelectableObjectWithLabel;
036: import com.flexive.shared.value.FxString;
037: import org.testng.annotations.Test;
038:
039: /**
040: * Selectable object tests, especially equality and comparable tests.
041: * NOTE: currently copied from SelectableObjectTest, it's OK to delete this test file entirely
042: * when the SelectableObjectWithName and SelectableObjectWithLabel interfaces are combined.
043: *
044: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
045: * @version $Rev: 181 $
046: */
047: @Test(groups="shared")
048: public class SelectableObjectWithLabelTest {
049: private static class SelectableFromAbstract extends
050: AbstractSelectableObjectWithLabel {
051: private long id;
052: private FxString label;
053:
054: public SelectableFromAbstract(long id, FxString label) {
055: this .id = id;
056: this .label = label;
057: }
058:
059: public long getId() {
060: return id;
061: }
062:
063: public FxString getLabel() {
064: return label;
065: }
066: }
067:
068: private static class SubSelectableFromAbstract extends
069: SelectableFromAbstract {
070: public SubSelectableFromAbstract(long id, FxString label) {
071: super (id, label);
072: }
073: }
074:
075: @Test
076: public void selectableFromAbstractEquals() {
077: SelectableFromAbstract sfa1 = new SelectableFromAbstract(1,
078: new FxString("test"));
079: SelectableFromAbstract sfa2 = new SelectableFromAbstract(2,
080: new FxString("test"));
081: assert !sfa1.equals(sfa2);
082: assert !sfa2.equals(sfa1);
083: //noinspection ObjectEqualsNull
084: assert !sfa1.equals(null); // check for NPE
085: SelectableFromAbstract sfa2_2 = new SelectableFromAbstract(2,
086: new FxString("test"));
087: assert sfa2.equals(sfa2_2);
088: }
089:
090: /**
091: * Checks that objects of different types, but the same ID are considered unequal.
092: */
093: @Test
094: public void selectableFromAbstractSubclassEquals() {
095: SelectableFromAbstract sfa = new SelectableFromAbstract(1,
096: new FxString("test"));
097: SubSelectableFromAbstract ssfa = new SubSelectableFromAbstract(
098: 1, new FxString("test"));
099: assert !sfa.equals(ssfa);
100: }
101: }
|