package com.google.code.morphia.callbacks;


import org.bson.types.ObjectId;
import org.junit.Test;
import com.google.code.morphia.TestBase;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.PostLoad;
import com.google.code.morphia.annotations.PostPersist;
import com.google.code.morphia.annotations.PreLoad;
import com.google.code.morphia.annotations.PrePersist;
import junit.framework.Assert;


public class TestMultipleCallbackMethods extends TestBase {
  abstract static class CallbackAbstractEntity {
    @Id
    private final ObjectId _id = new ObjectId();

    public ObjectId getId() {
      return _id;
    }

    int foo;
    int loading;

    @PrePersist
    void prePersist1() {
      foo++;
    }

    @PrePersist
    void prePersist2() {
      foo++;
    }

    @PostPersist
    void postPersist1() {
      foo++;
    }

    @PostPersist
    void postPersist2() {
      foo++;
    }

    @PreLoad
    void preLoad1() {
      loading++;
    }

    @PreLoad
    void preLoad2() {
      loading++;
    }

    @PostLoad
    void postLoad1() {
      foo--;
    }

    @PostLoad
    void postLoad2() {
      foo--;
    }

    @PostLoad
    void postLoad3() {
      foo--;
    }
  }

  static class SomeEntity extends CallbackAbstractEntity {

  }

  @Test
  public void testMultipleCallbackAnnotation() throws Exception {
    final SomeEntity entity = new SomeEntity();
    ds.save(entity);

    Assert.assertEquals(4, entity.foo);
    Assert.assertEquals(0, entity.loading);

    final SomeEntity someEntity = ds.find(SomeEntity.class, "_id", entity.getId()).get();

    Assert.assertEquals(4, entity.foo);
    Assert.assertEquals(0, entity.loading);

    Assert.assertEquals(-1, someEntity.foo);
//    Assert.assertEquals(2, someEntity.loading);
  }
}
@@ -505,16 +505,49 @@
 Base %7B%0D%0A
+  private static int loading;%0D%0A%0D%0A
   abstra
@@ -725,26 +725,8 @@
 oo;%0D
-%0A    int loading;%0D
 %0A%0D%0A 
@@ -1589,39 +1589,32 @@
 assertEquals(0, 
-entity.
 loading);%0D%0A%0D%0A   
@@ -1747,53 +1747,8 @@
 o);%0D
-%0A    Assert.assertEquals(0, entity.loading);%0D
 %0A%0D%0A 
@@ -1796,10 +1796,8 @@
 );%0D%0A
-//
     
@@ -1819,27 +1819,16 @@
 uals(2, 
-someEntity.
 loading)

correct @PreLoad test