This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setters to have a different collection raw type (#33)
* Allow setters to have a different collection raw type Change-Id: I403febc863bb145b3ee71b5032889f3aded47504 Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
- Loading branch information
1 parent
b22a910
commit 517e22c
Showing
3 changed files
with
119 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...oslc4j.core/src/test/java/org/eclipse/lyo/oslc4j/core/model/ResourceShapeFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.eclipse.lyo.oslc4j.core.model; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import org.eclipse.lyo.oslc4j.core.exception.OslcCoreMissingSetMethodException; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
/** | ||
* @version $version-stub$ | ||
* @since 2.4.0 | ||
*/ | ||
public class ResourceShapeFactoryTest { | ||
|
||
@Test | ||
public void detectCollectionType() throws NoSuchMethodException { | ||
final boolean isCollectionType = ResourceShapeFactory.isCollectionType( | ||
Dummy.class.getMethod("getValue").getReturnType()); | ||
|
||
assertThat(isCollectionType).isTrue(); | ||
} | ||
|
||
@Test | ||
public void detectNonCollectionType() throws NoSuchMethodException { | ||
final boolean isCollectionType = ResourceShapeFactory.isCollectionType( | ||
Dummy.class.getMethod("getValue2").getReturnType()); | ||
|
||
assertThat(isCollectionType).isFalse(); | ||
} | ||
|
||
@Test | ||
public void findSetterNonCollection() | ||
throws NoSuchMethodException, OslcCoreMissingSetMethodException { | ||
ResourceShapeFactory.validateSetMethodExists(Dummy.class, Dummy.class.getMethod("getValue2")); | ||
} | ||
|
||
@Test | ||
public void findSetterCollection() | ||
throws NoSuchMethodException, OslcCoreMissingSetMethodException { | ||
ResourceShapeFactory.validateSetMethodExists(Dummy.class, Dummy.class.getMethod("getValue")); | ||
} | ||
|
||
@Test(expected = OslcCoreMissingSetMethodException.class) | ||
public void findSetterCollectionMismachGenType() | ||
throws NoSuchMethodException, OslcCoreMissingSetMethodException { | ||
ResourceShapeFactory.validateSetMethodExists(Dummy.class, Dummy.class.getMethod("getValueDifferent")); | ||
} | ||
|
||
interface Dummy { | ||
public ArrayList<BigDecimal> getValue(); | ||
|
||
public void setValue(HashSet<BigDecimal> ds); | ||
|
||
public ArrayList<BigDecimal> getValueDifferent(); | ||
|
||
public void setValueDifferent(HashSet<Integer> ds); | ||
|
||
public BigDecimal getValue2(); | ||
|
||
public void setValue2(BigDecimal d); | ||
} | ||
} |