package icepick;

import android.os.Bundle;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.when;

@PrepareForTest(Bundle.class) @RunWith(PowerMockRunner.class)
public class IcepickTest {

  static final String KEY = "key";
  static final String VALUE = "value";
  static final String ANOTHER_VALUE = "anotherValue";

  final Bundle state = PowerMockito.mock(Bundle.class);
  final ClassToInject classToInject = new ClassToInject();

  @Test public void saveState() throws Exception {
    Icepick.saveInstanceState(classToInject, state);

    verify(state).putString(KEY, VALUE);
  }

  @Test public void restoreState() throws Exception {
    when(state.getString(KEY)).thenReturn(ANOTHER_VALUE);

    Icepick.restoreInstanceState(classToInject, state);

    Assert.assertEquals(ANOTHER_VALUE, classToInject.string);
  }

  static class ClassToInject {
    String string = VALUE;
  }

  @SuppressWarnings("unused")
  static class ClassToInject$$Icicle {

    public static void saveInstanceState(ClassToInject target, Bundle outState) {
      outState.putString(KEY, target.string);
    }

    public static void restoreInstanceState(ClassToInject target, Bundle saveInstanceState) {
      target.string = saveInstanceState.getString(KEY);
    }
  }
}

@@ -41,33 +41,8 @@
 le;%0A
-import org.junit.Assert;%0A
 impo
@@ -260,16 +260,61 @@
 unner;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -1067,23 +1067,16 @@
 );%0A%0A    
-Assert.
 assertEq
@@ -1257,168 +1257,272 @@
 cle 
-%7B%0A%0A    public static void saveInstanceState(ClassToInject target, Bundle outState) %7B%0A      outState.putString(KEY, target.string);%0A    %7D%0A%0A    public static void
+implements StateHelper%3CBundle%3E %7B%0A%0A    @Override public Bundle saveInstanceState(Object obj, Bundle outState) %7B%0A      ClassToInject target = (ClassToInject) obj;%0A      outState.putString(KEY, target.string);%0A      return outState;%0A    %7D%0A%0A    @Override public Bundle
  res
@@ -1539,36 +1539,26 @@
 ceState(
-ClassToInject target
+Object obj
 , Bundle
@@ -1575,24 +1575,74 @@
 nceState) %7B%0A
+      ClassToInject target = (ClassToInject) obj;%0A
       target
@@ -1685,16 +1685,48 @@
 g(KEY);%0A
+      return saveInstanceState;%0A
     %7D%0A  

Format tests