package com.xtremelabs.droidsugar.view;

import android.app.*;
import android.content.*;
import android.content.res.*;
import android.test.mock.*;
import android.view.*;

import static org.mockito.Mockito.*;

@SuppressWarnings({"UnusedDeclaration"})
public class FakeContextWrapper {
    static public ViewLoader viewLoader;
    protected static Context contextForInflation = new ContextWrapper(null);

    public Resources getResources() {
        return new Resources(null, null, null);
    }

    public Context getApplicationContext() {
        return new ContextWrapper(null);
    }

    public ContentResolver getContentResolver() {
        return new MockContentResolver();
    }

    public Object getSystemService(String name) {
        if (name.equals(Context.LAYOUT_INFLATER_SERVICE)) {
            return getFakeLayoutInflater();
        } else if (name.equals(Context.ALARM_SERVICE)) {
            return mock(AlarmManager.class);
        }
        return null;
    }

    public FakeLayoutInflater getFakeLayoutInflater() {
        return new FakeLayoutInflater(viewLoader);
    }

    public static class FakeLayoutInflater extends LayoutInflater {

        private final ViewLoader viewLoader;

        public FakeLayoutInflater(ViewLoader viewLoader) {
            super(null);
            this.viewLoader = viewLoader;
        }

        @Override
        public View inflate(int resource, ViewGroup root) {
            View view = viewLoader.inflateView(contextForInflation, resource);
            if (root != null) {
                root.addView(view);
            }
            return view;
        }

        @Override
        public LayoutInflater cloneInContext(Context context) {
            return this;
        }
    }
}

@@ -1415,20 +1415,42 @@
 oup root
+, boolean attachToRoot
 ) %7B%0A
-
         
@@ -1548,16 +1548,32 @@
  != null
+ && attachToRoot
 ) %7B%0A    
@@ -1610,32 +1610,32 @@
 ;%0A            %7D%0A
-
             retu
@@ -1646,32 +1646,171 @@
 iew;%0A        %7D%0A%0A
+        @Override%0A        public View inflate(int resource, ViewGroup root) %7B%0A            return inflate(resource, root, true);%0A        %7D%0A%0A
         @Overrid

add overloaded inflate method in FakeLayoutInflator