Skip to content

Commit

Permalink
package misannotated -> problemfacts (package names are functionality…
Browse files Browse the repository at this point in the history
… based) + remove "test" prefix of test names (JUnit 4)
  • Loading branch information
ge0ffrey committed Mar 25, 2016
1 parent 06592ca commit f283a3e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 92 deletions.
Expand Up @@ -17,23 +17,20 @@


import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.optaplanner.core.impl.testdata.domain.extended.unimplemented.TestdataExtendedAbstractSolution; import org.optaplanner.core.impl.testdata.domain.extended.abstractsolution.TestdataExtendedAbstractSolution;
import org.optaplanner.core.impl.testdata.domain.misannotated.TestdataEntityWithInvalidFactPropertyGetter; import org.optaplanner.core.impl.testdata.domain.problemfacts.TestdataInvalidProblemFactCollectionPropertySolution;


public class SolutionDescriptorTest { public class SolutionDescriptorTest {


@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
public void testSolutionWithFactPropertyGetterHavingAttributes() { public void invalidProblemFactCollectionProperty() {
SolutionDescriptor<TestdataEntityWithInvalidFactPropertyGetter> descriptor = TestdataInvalidProblemFactCollectionPropertySolution.buildSolutionDescriptor();
new SolutionDescriptor<>(TestdataEntityWithInvalidFactPropertyGetter.class);
descriptor.processAnnotations(null);
} }


@Test @Test
public void testExtendingAbstractSolution() { public void extendedAbstractSolution() {
SolutionDescriptor<TestdataExtendedAbstractSolution> descriptor SolutionDescriptor<TestdataExtendedAbstractSolution> descriptor
= new SolutionDescriptor<>(TestdataExtendedAbstractSolution.class); = TestdataExtendedAbstractSolution.buildSolutionDescriptor();
descriptor.processAnnotations(null);
Assert.assertEquals("Fact collection inherited from abstract class is not registered.", Assert.assertEquals("Fact collection inherited from abstract class is not registered.",
1, descriptor.getFactCollectionPropertyAccessorMap().size()); 1, descriptor.getFactCollectionPropertyAccessorMap().size());
Assert.assertEquals("Private fact property from the solution class is not registered.", Assert.assertEquals("Private fact property from the solution class is not registered.",
Expand Down
Expand Up @@ -20,9 +20,12 @@
import org.optaplanner.core.api.score.buildin.simple.SimpleScore; import org.optaplanner.core.api.score.buildin.simple.SimpleScore;
import org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor; import org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor;
import org.optaplanner.core.impl.testdata.domain.TestdataObject; import org.optaplanner.core.impl.testdata.domain.TestdataObject;
import org.optaplanner.core.impl.testdata.domain.TestdataValue;


import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;


@PlanningSolution @PlanningSolution
public class TestdataEntityProvidingSolution extends TestdataObject { public class TestdataEntityProvidingSolution extends TestdataObject {
Expand Down Expand Up @@ -65,8 +68,12 @@ public void setScore(SimpleScore score) {
// ************************************************************************ // ************************************************************************


@PlanningFactCollectionProperty @PlanningFactCollectionProperty
public Collection<? extends Object> getProblemFacts() { public Collection<TestdataValue> getProblemFacts() {
throw new UnsupportedOperationException(); Set<TestdataValue> valueSet = new HashSet<>();
for (TestdataEntityProvidingEntity entity : entityList) {
valueSet.addAll(entity.getValueRange());
}
return valueSet;
} }


} }
Expand Up @@ -16,6 +16,7 @@


package org.optaplanner.core.impl.testdata.domain.extended; package org.optaplanner.core.impl.testdata.domain.extended;


import org.optaplanner.core.api.domain.solution.PlanningFactProperty;
import org.optaplanner.core.impl.testdata.domain.TestdataSolution; import org.optaplanner.core.impl.testdata.domain.TestdataSolution;


public class TestdataExtendedSolution extends TestdataSolution { public class TestdataExtendedSolution extends TestdataSolution {
Expand All @@ -34,6 +35,7 @@ public TestdataExtendedSolution(String code, Object extraObject) {
this.extraObject = extraObject; this.extraObject = extraObject;
} }


@PlanningFactProperty
public Object getExtraObject() { public Object getExtraObject() {
return extraObject; return extraObject;
} }
Expand Down
@@ -1,5 +1,5 @@
/* /*
* Copyright 2012 Red Hat, Inc. and/or its affiliates. * Copyright 2016 Red Hat, Inc. and/or its affiliates.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
Expand All @@ -14,22 +14,27 @@
* limitations under the License. * limitations under the License.
*/ */


package org.optaplanner.core.impl.testdata.domain.extended.unimplemented; package org.optaplanner.core.impl.testdata.domain.extended.abstractsolution;


import java.util.List; import java.util.List;


import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty; import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningFactProperty; import org.optaplanner.core.api.domain.solution.PlanningFactProperty;
import org.optaplanner.core.api.domain.solution.PlanningSolution; import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.impl.domain.solution.AbstractSolution; import org.optaplanner.core.impl.domain.solution.AbstractSolution;
import org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor;
import org.optaplanner.core.impl.testdata.domain.TestdataEntity;


@PlanningSolution @PlanningSolution
public class TestdataExtendedAbstractSolution extends AbstractSolution { public class TestdataExtendedAbstractSolution extends AbstractSolution {


public static SolutionDescriptor buildSolutionDescriptor() {
return SolutionDescriptor.buildSolutionDescriptor(TestdataExtendedAbstractSolution.class, TestdataEntity.class);
}

private Object extraObject; private Object extraObject;


@PlanningEntityCollectionProperty private List<TestdataEntity> entityList;
private List<Object> entities;


public TestdataExtendedAbstractSolution(String code) { public TestdataExtendedAbstractSolution(String code) {
super(); super();
Expand All @@ -44,6 +49,15 @@ public void setExtraObject(Object extraObject) {
this.extraObject = extraObject; this.extraObject = extraObject;
} }


@PlanningEntityCollectionProperty
public List<TestdataEntity> getEntityList() {
return entityList;
}

public void setEntityList(List<TestdataEntity> entityList) {
this.entityList = entityList;
}

// ************************************************************************ // ************************************************************************
// Complex methods // Complex methods
// ************************************************************************ // ************************************************************************
Expand Down

This file was deleted.

@@ -0,0 +1,44 @@
/*
* Copyright 2016 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.optaplanner.core.impl.testdata.domain.problemfacts;

import java.util.Collection;
import java.util.Collections;

import org.optaplanner.core.api.domain.solution.PlanningFactCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor;
import org.optaplanner.core.impl.testdata.domain.TestdataEntity;
import org.optaplanner.core.impl.testdata.domain.TestdataSolution;

@PlanningSolution
public class TestdataInvalidProblemFactCollectionPropertySolution extends TestdataSolution {

public static SolutionDescriptor buildSolutionDescriptor() {
return SolutionDescriptor.buildSolutionDescriptor(TestdataInvalidProblemFactCollectionPropertySolution.class, TestdataEntity.class);
}

// ************************************************************************
// Complex methods
// ************************************************************************

@PlanningFactCollectionProperty
public Collection<Object> getInvalidProblemFacts(int invalidArgument) {
return Collections.<Object>emptyList();
}

}

0 comments on commit f283a3e

Please sign in to comment.