Skip to content

Commit

Permalink
fixed test with null Persistence-Manager and wrapped RuntimeExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed May 23, 2011
1 parent fc588f2 commit 3bf8d31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
7 changes: 5 additions & 2 deletions aspectj/src/main/java/com/example/support/DomaenenAspekt.aj
Expand Up @@ -7,7 +7,7 @@ import org.aspectj.lang.reflect.MethodSignature;

public privileged aspect DomaenenAspekt {

private PersistenceManager pm;
private PersistenceManager pm = new PersistenceManager();
public interface DomaenenObjekt {}
pointcut domainObject() : within(com.example.domain.*);

Expand All @@ -29,9 +29,12 @@ public privileged aspect DomaenenAspekt {
Object result=proceed();
pm.commit();
return result;
} catch(RuntimeException e) {
pm.rollback();
throw e;
} catch(Exception e) {
pm.rollback();
throw new RuntimeException("Fehler beim transaktionalem AusfŸhren",e);
throw new RuntimeException(e);
}
}

Expand Down
21 changes: 14 additions & 7 deletions aspectj/src/main/java/com/example/support/PersistenceManager.java
@@ -1,11 +1,18 @@
package com.example.support;

public interface PersistenceManager {
void begin();
void commit();
void rollback();
public class PersistenceManager {
void begin() {}
void commit() {}
void rollback() {}

<T> T persist(T entity);
void delete(Object entity);
<T> T load(Class<T> type, long id);
<T> T persist(T entity) { return entity; }
void delete(Object entity) {}

<T> T load(Class<T> type, long id) {
try {
return type.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
2 changes: 1 addition & 1 deletion aspectj/src/test/java/com/example/domain/KontoTest.java
Expand Up @@ -25,7 +25,7 @@ public void kontoShouldNotAllowNegativeValue() {

@Test(expected = IllegalStateException.class)
public void kontoShouldNotAllowValueToBecomeNegative() {
new Konto(1,"test").buche(-2);
new Konto(11,"test").buche(-20);
}

@Test(expected = IllegalStateException.class)
Expand Down

0 comments on commit 3bf8d31

Please sign in to comment.