Skip to content

Commit

Permalink
Merge pull request #7 from fomin/master
Browse files Browse the repository at this point in the history
Adds possibility to use classes from any package in fixtures
  • Loading branch information
sberan committed Apr 12, 2012
2 parents 0263bc0 + 0bd113d commit d70827c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
14 changes: 12 additions & 2 deletions fixy-core/src/main/java/com/fixy/CoreFixy.java
Expand Up @@ -78,10 +78,20 @@ public CoreFixy(Persister persister) {
@Override
protected Class<?> getClassForName(String name) throws ClassNotFoundException {
if(!Strings.isNullOrEmpty(packageName)) {
return super.getClassForName(packageName + "." + name);
} else {
try {
return super.getClassForName(packageName + "." + name);
} catch (ClassNotFoundException ignored) { }
}
ClassNotFoundException exceptionToThrow;
try {
return super.getClassForName(name);
} catch (ClassNotFoundException e) {
exceptionToThrow = e;
}
try {
return super.getClassForName("java.lang." + name);
} catch (ClassNotFoundException ignored) { }
throw exceptionToThrow;
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions fixy-jpa/src/test/java/com/petstore/Pet.java
Expand Up @@ -6,6 +6,7 @@
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import java.sql.Date;

@Entity
public class Pet {
Expand All @@ -20,6 +21,8 @@ public class Pet {

Long price;

Date birthDate;

@OneToOne(mappedBy = "pet")
Order order;

Expand Down Expand Up @@ -56,6 +59,14 @@ public void setPrice(Long price) {
this.price = price;
}

public Date getBirthDate() {
return birthDate;
}

public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}

public Order getOrder() {
return order;
}
Expand Down
4 changes: 3 additions & 1 deletion fixy-jpa/src/test/resources/pets.yaml
Expand Up @@ -3,4 +3,6 @@

- Pet(fido):
name: Fido
type: PetType(dog)
type: PetType(dog)
price: !!Long 100
birthDate: !!java.sql.Date 2001-09-09T01:46:40Z

0 comments on commit d70827c

Please sign in to comment.