// Path: airomem-direct/src/test/java/pl/setblack/airomem/direct/SampleController.java
// @Persistent
// public class SampleController {
// 
//     @PersistentObject
//     protected SampleObject object;
// 
//     public void writeMethod() {
//         assertNotNull(object);
//         object.setField1("changed field1");
//         object.value += 14;
//     }
// 
//     public void writeMethod2(int val1, String val2) {
//         assertNotNull(object);
//         object.setField1(val2);
//         object.value += val1;
//     }
// 
//     @GET
//     public String readMethod() {
//         assertNotNull(object);
//         object.value += 7;
//         return object.getField1();
//     }
// 
//     @GET
//     public String readMethod(String postfix) {
//         assertNotNull(object);
//         object.value += 7;
//         return object.getField1() + postfix;
//     }
// 
//     public SampleObject getObject() {
//         return this.object;
//     }
// 
// }


import java.io.File;
import java.lang.reflect.Method;
import org.apache.commons.io.FileUtils;
import org.jglue.cdiunit.CdiRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import pl.setblack.airomem.core.builders.PersistenceFactory;
import pl.setblack.airomem.direct.SampleController;
import pl.setblack.badass.Politician;

/*
 *  Copyright (c) Jarek Ratajski, Licensed under the Apache License, Version 2.0
 *  http://www.apache.org/licenses/LICENSE-2.0
 */
package pl.setblack.airomem.direct.impl;


/**
 *
 * @author jarek ratajski
 */
@RunWith(CdiRunner.class)
public class ClassContextTest {

    public ClassContextTest() {
    }

    @Before
    public void setUp() {
        PrevaylerRegister.getInstance().clear();
        Politician.beatAroundTheBush(() -> {
            FileUtils.deleteDirectory(new File(PersistenceFactory.STORAGE_FOLDER));
        });
    }

    @After
    public void tearDown() {
        PrevaylerRegister.getInstance().clear();
        Politician.beatAroundTheBush(() -> {
            FileUtils.deleteDirectory(new File(PersistenceFactory.STORAGE_FOLDER));
        });
    }

    @Test(expected = IllegalStateException.class)
    public void shouldNotInstantiateNoCDIBean() throws NoSuchMethodException {

        //WHEN
        final ClassContext ctx = new ClassContext(Object.class);

    }

    @Test(expected = RuntimeException.class)
    public void shouldFailOnNoBeanClass() throws NoSuchMethodException {
        //GIVEN

// Path: airomem-direct/src/test/java/pl/setblack/airomem/direct/SampleController.java
// @Persistent
// public class SampleController {
// 
//     @PersistentObject
//     protected SampleObject object;
// 
//     public void writeMethod() {
//         assertNotNull(object);
//         object.setField1("changed field1");
//         object.value += 14;
//     }
// 
//     public void writeMethod2(int val1, String val2) {
//         assertNotNull(object);
//         object.setField1(val2);
//         object.value += val1;
//     }
// 
//     @GET
//     public String readMethod() {
//         assertNotNull(object);
//         object.value += 7;
//         return object.getField1();
//     }
// 
//     @GET
//     public String readMethod(String postfix) {
//         assertNotNull(object);
//         object.value += 7;
//         return object.getField1() + postfix;
//     }
// 
//     public SampleObject getObject() {
//         return this.object;
//     }
// 
// }


// Path: airomem-direct/src/test/java/pl/setblack/airomem/direct/impl/ClassContextTest.java
import java.io.File;
import java.lang.reflect.Method;
import org.apache.commons.io.FileUtils;
import org.jglue.cdiunit.CdiRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import pl.setblack.airomem.core.builders.PersistenceFactory;
import pl.setblack.airomem.direct.SampleController;
import pl.setblack.badass.Politician;

/*
 *  Copyright (c) Jarek Ratajski, Licensed under the Apache License, Version 2.0
 *  http://www.apache.org/licenses/LICENSE-2.0
 */
package pl.setblack.airomem.direct.impl;


/**
 *
 * @author jarek ratajski
 */
@RunWith(CdiRunner.class)
public class ClassContextTest {

    public ClassContextTest() {
    }

    @Before
    public void setUp() {
        PrevaylerRegister.getInstance().clear();
        Politician.beatAroundTheBush(() -> {
            FileUtils.deleteDirectory(new File(PersistenceFactory.STORAGE_FOLDER));
        });
    }

    @After
    public void tearDown() {
        PrevaylerRegister.getInstance().clear();
        Politician.beatAroundTheBush(() -> {
            FileUtils.deleteDirectory(new File(PersistenceFactory.STORAGE_FOLDER));
        });
    }

    @Test(expected = IllegalStateException.class)
    public void shouldNotInstantiateNoCDIBean() throws NoSuchMethodException {

        //WHEN
        final ClassContext ctx = new ClassContext(Object.class);

    }

    @Test(expected = RuntimeException.class)
    public void shouldFailOnNoBeanClass() throws NoSuchMethodException {
        //GIVEN

        SampleController ctrl = new SampleController() {
