package com.pivotallabs.robolectricgem.expect;

import com.pivotallabs.greatexpectations.BaseMatcher;
import com.pivotallabs.greatexpectations.ExpectGenerator;
import com.pivotallabs.robolectricgem.matchers.ActivityMatcher;
import com.pivotallabs.robolectricgem.matchers.AlertDialogMatcher;
import com.pivotallabs.robolectricgem.matchers.CompoundButtonMatcher;
import com.pivotallabs.robolectricgem.matchers.DialogMatcher;
import com.pivotallabs.robolectricgem.matchers.FakeHttpLayerMatcher;
import com.pivotallabs.robolectricgem.matchers.ImageViewMatcher;
import com.pivotallabs.robolectricgem.matchers.TextViewMatcher;
import com.pivotallabs.robolectricgem.matchers.ViewMatcher;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;

/**
 * See https://github.com/xian/great-expectations
 */
public class RunnableExpectGenerator extends ExpectGenerator {

    @SuppressWarnings({"unchecked"})
    public static final Class<? extends BaseMatcher>[] CUSTOM_MATCHER_CLASSES = new Class[] {
            ActivityMatcher.class,
            AlertDialogMatcher.class,
            CompoundButtonMatcher.class,
            DialogMatcher.class,
            FakeHttpLayerMatcher.class,
            ImageViewMatcher.class,
            TextViewMatcher.class,
            ViewMatcher.class
    };

    public RunnableExpectGenerator(String packageName) {
        super(packageName);
    }

    public static void main(String args[]) throws java.io.IOException {
        generateCustomExpect();
    }

    public static void generateCustomExpect() throws FileNotFoundException {
        String packageName = Expect.class.getPackage().getName();
        String path = "src/robolectricgem/" + packageName.replace(".", "/") + "/Expect.java";
        System.out.println("path = " + path);
        System.out.println("packagename = " + packageName);
        RunnableExpectGenerator expectGenerator = new RunnableExpectGenerator(packageName);
        expectGenerator.setOut(new PrintStream(new File(path)));
        expectGenerator.generate();
    }
    
    @Override
    @SuppressWarnings({"unchecked"})
    public List<Class<? extends BaseMatcher>> matcherClasses() {
        List<Class<? extends BaseMatcher>> classes = super.matcherClasses();
        classes.addAll(Arrays.asList(CUSTOM_MATCHER_CLASSES));
        return classes;
    }
}

@@ -869,12 +869,196 @@
 ons%0A
+ *%0A * Run this class to regenerate Expect.java.%0A *%0A * This class is designed to be subclassed, in case you want to extend%0A * the list of matcher classes with your own matcher classes.%0A
  */%0A
-
 publ
@@ -1155,29 +1155,32 @@
 ked%22%7D)%0A    p
-ublic
+rotected
  static fina
@@ -1248,17 +1248,16 @@
  Class%5B%5D
- 
 %7B%0A      
@@ -1859,37 +1859,29 @@
 e = 
+get
 Expect
-.c
+C
 lass
-.get
 Package
-().get
 Name
@@ -1910,78 +1910,32 @@
 h = 
-%22src/robolectricgem/%22 + packageName.replace(%22.%22, %22/%22) + %22/Expect.java%22
+getExpectClassFilePath()
 ;%0A  
@@ -2241,13 +2241,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -2490,24 +2490,24 @@
 _CLASSES));%0A
-
         retu
@@ -2523,11 +2523,405 @@
 s;%0A    %7D
+%0A%0A    protected static String getExpectClassPackageName() %7B%0A        return Expect.class.getPackage().getName();%0A    %7D%0A%0A    protected static String getExpectClassFilePath() %7B%0A        return %22src%22 + File.separator +%0A                %22robolectricgem%22 + File.separator +%0A                getExpectClassPackageName().replace(%22.%22, File.separator) + File.separator +%0A                %22Expect.java%22;%0A    %7D
 %0A%7D%0A

update RunnableExpectGenerator to make it easier to subclass