Commit ad9ffe7b authored by Matthias Betz's avatar Matthias Betz
Browse files

added Check tests

parent aaee62de
Pipeline #2294 passed with stage
in 3 minutes and 8 seconds
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.check;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import de.hft.stuttgart.citydoctor2.check.error.AttributeMissingError;
import de.hft.stuttgart.citydoctor2.datastructure.AbstractBuilding;
import de.hft.stuttgart.citydoctor2.datastructure.BoundarySurface;
import de.hft.stuttgart.citydoctor2.datastructure.Building;
import de.hft.stuttgart.citydoctor2.datastructure.Vegetation;
import de.hft.stuttgart.citydoctor2.datastructure.Vegetation.VegetationType;
public class CheckTest {
@Test
public void testCheckOneMethod() {
Check c = new Check() {
@Override
public Set<Requirement> appliesToRequirements() {
return null;
}
@Override
public CheckId getCheckId() {
return null;
}
@Override
public RequirementType getType() {
return null;
}
@Override
public Check createNewInstance() {
return null;
}
public void check(AbstractBuilding ab) {
};
};
List<Class<Checkable>> applicableToClasses = c.getApplicableToClasses();
assertEquals(1, applicableToClasses.size());
Class<Checkable> class1 = applicableToClasses.get(0);
assertEquals(class1, AbstractBuilding.class);
}
@Test
public void testCheckTwoMethod() {
Check c = new Check() {
@Override
public Set<Requirement> appliesToRequirements() {
return null;
}
@Override
public CheckId getCheckId() {
return null;
}
@Override
public RequirementType getType() {
return null;
}
@Override
public Check createNewInstance() {
return null;
}
public void check(AbstractBuilding ab) {
};
@Override
public void check(BoundarySurface bs) {
check(bs, 1);
check(2);
}
public void check(BoundarySurface bs, Integer test) {
}
public void check(Integer i) {
}
};
List<Class<Checkable>> applicableToClasses = c.getApplicableToClasses();
assertEquals(2, applicableToClasses.size());
assertTrue(applicableToClasses.contains(AbstractBuilding.class));
assertTrue(applicableToClasses.contains(BoundarySurface.class));
assertFalse(applicableToClasses.contains(Integer.class));
}
@Test
public void testGetDependencies() {
Check c = new Check() {
@Override
public Set<Requirement> appliesToRequirements() {
return null;
}
@Override
public CheckId getCheckId() {
return null;
}
@Override
public RequirementType getType() {
return null;
}
@Override
public Check createNewInstance() {
return null;
}
};
assertTrue(c.getDependencies().isEmpty());
}
@Test
public void testCanExecute() {
Check c2 = new Check() {
@Override
public Set<Requirement> appliesToRequirements() {
return null;
}
@Override
public CheckId getCheckId() {
return CheckId.C_GE_P_INNER_RINGS_NESTED;
}
@Override
public RequirementType getType() {
return null;
}
@Override
public Check createNewInstance() {
return null;
}
@Override
public List<CheckId> getDependencies() {
return Collections.singletonList(CheckId.C_GE_P_HOLE_OUTSIDE);
}
public void check(AbstractBuilding b) {
};
};
Building b = new Building();
assertTrue(c2.canExecute(b));
b.addCheckResult(new CheckResult(CheckId.C_GE_P_HOLE_OUTSIDE, ResultStatus.ERROR,
new AttributeMissingError(b, null, null, false)));
assertEquals(1, b.getAllCheckResults().size());
assertTrue(b.getAllCheckResults().containsKey(CheckId.C_GE_P_HOLE_OUTSIDE));
assertFalse(c2.canExecute(b));
assertEquals(2, b.getAllCheckResults().size());
assertTrue(b.getAllCheckResults().containsKey(CheckId.C_GE_P_INNER_RINGS_NESTED));
assertFalse(c2.canExecute(b));
Vegetation veg = new Vegetation(VegetationType.PLANT_COVER);
assertFalse(c2.canExecute(veg));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment