/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package json2notification;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.support.v4.app.FragmentActivity;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import android.app.Notification;
import android.app.NotificationManager;

import org.json.JSONObject;
import org.json.JSONException;

import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.Mockito.verify;
import android.app.PendingIntent;
import android.app.Notification;
import android.support.v4.app.NotificationCompat;
import android.content.Intent;

import com.infstory.notification.BuildConfig;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
//@Config(manifest = Config.NONE)
public class MainTest {
    // support library fragments
    private FragmentActivity fragmentActivity;
    private android.support.v4.app.Fragment supportFragment;

    // native fragments
    private Activity activity;
    private Fragment fragment;

    @Mock
    private JSONObject json;

    private String rawJson = "{" +
                                   "\"android\": {" +
                                       "\"notification\": {" +
                                           "\"contentTitle\": \"contentTitle\"," +
                                           "\"contentText\": \"contentText\"," +
                                           "\"contentInfo\": \"contentInfo\"," +
                                           "\"contentIntent\": {" +
                                               "\"start\": \"activity\"," +
                                               "\"intent\": {" +
                                                    "\"action\" : \"android.intent.action.VIEW\"," +
                                                    "\"data\" : {" +
                                                        "\"scheme\" : \"http\"," +
                                                        "\"opaquePart\" : \"//wikipedia.org\"," +
                                                        "\"authority\" : \"wikipedia.org\"," +
                                                        "\"path\" : \"/wiki/Christmas\"," +
                                                        "\"query\" : \"\"," +
                                                        "\"fragment\" : \"\"" +
                                                    "}," +
                                                    "\"dataString\" : \"http://wikipedia.org/wiki/Christmas\"," +
                                                    "\"flags\" : 0," +
                                                    "\"scheme\" : \"http\"," +
                                                    "\"excludingStopped\" : false" +
                                               "}," +
                                               "\"flags\": 0," +
                                               "\"options\": null" +
                                           "}," +
                                           "\"largeIcon\": \"largeIcon\"," +
                                           "\"smallIcon\": \"smallIcon\"," +
                                           "\"style\": {" +
                                               "\"contentTitle\": \"contentTitle\"," +
                                               "\"contentText\": \"contentText\"," +
                                               "\"contentInfo\": \"contentInfo\"," +
                                               "\"summaryText\": \"summaryText\"," +
                                               "\"bigLargeIcon\": \"bigLargeIcon\"," +
                                               "\"bigPicture\": \"bigPicture\"," +
                                               "\"contentIntent\": {" +
                                                   "\"start\": \"activity\"," +
                                                   "\"intent\": {" +
                                                        "\"action\" : \"android.intent.action.VIEW\"," +
                                                        "\"data\" : {" +
                                                            "\"scheme\" : \"http\"," +
                                                            "\"opaquePart\" : \"//wikipedia.org\"," +
                                                            "\"authority\" : \"wikipedia.org\"," +
                                                            "\"path\" : \"/wiki/Christmas\"," +
                                                            "\"query\" : \"\"," +
                                                            "\"fragment\" : \"\"" +
                                                        "}," +
                                                        "\"dataString\" : \"http://wikipedia.org/wiki/Christmas\"," +
                                                        "\"flags\" : 0," +
                                                        "\"scheme\" : \"http\"," +
                                                        "\"excludingStopped\" : false" +
                                                   "}," +
                                                   "\"flags\": 0," +
                                                   "\"options\": null" +
                                               "}" +
                                           "}," +
                                           "\"autoCancel\": true" +
                                       "}" +
                                   "}" +
                                "}";

    NotificationManager notificationManager;
    Context context;

    @Before
    public void setup() {
        notificationManager = (NotificationManager) RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
        context = RuntimeEnvironment.application.getApplicationContext();
    }

    @Test
    public void parse() {
        Notification n = Json2Notification.from(context).with(rawJson).notification();
        System.out.println(n);
        assertThat(n).isNotNull();
        notificationManager.notify(1, n);
        //assertThat(shadowOf(notificationManager).getNotification(1)).isNull();
    }

    @Test
    public void testSerialize() {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        Notification notification = new NotificationCompat.Builder(context)
            .setContentTitle("Hello World!")
            .setContentText("Hello World!")
            .setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
            .build();

        String json = Json2Notification.from(context).with(notification).serialize();
        System.out.println(json);
        assertThat(json).isNotNull();
    }
}

@@ -599,24 +599,28 @@
 oid.app.
-Activity
+Notification
 ;%0Aimport
@@ -632,21 +632,66 @@
 oid.app.
-Fragm
+NotificationManager;%0Aimport android.app.PendingInt
 ent;%0Aimp
@@ -738,1193 +738,499 @@
 oid.
-support.v4.app.FragmentActivity;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.MockitoAnnotations;%0Aimport org.robolectric.Robolectric;%0Aimport org.robolectric.RobolectricTestRunner;%0Aimport org.robolectric.RuntimeEnvironment;%0Aimport org.robolectric.annotation.Config;%0A%0Aimport android.app.Notification;%0Aimport android.app.NotificationManager;%0A%0Aimport org.json.JSONObject;%0Aimport org.json.JSONException;%0A%0Aimport static org.assertj.core.api.Java6Assertions.assertThat;%0Aimport static org.mockito.Mockito.verify;%0Aimport android.app.PendingIntent;%0Aimport android.app.Notification;%0Aimport android.support.v4.app.NotificationCompat;%0Aimport android.content.Intent;%0A%0Aimport com.infstory.notification.BuildConfig;%0A%0A@RunWith(RobolectricTestRunner.class)%0A@Config(constants = BuildConfig.class)%0A//@Config(manifest = Config.NONE)%0Apublic class MainTest %7B%0A    // support library fragments%0A    private FragmentActivity fragmentActivity;%0A    private android.support.v4.app.Fragment supportFragment;%0A%0A    // native fragments%0A    private Activity activity;%0A    private Fragment fragment;%0A%0A    @Mock%0A    private JSONObject json;%0A
+content.Intent;%0Aimport android.support.v4.app.NotificationCompat;%0A%0Aimport com.infstory.notification.BuildConfig;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.robolectric.RobolectricTestRunner;%0Aimport org.robolectric.RuntimeEnvironment;%0Aimport org.robolectric.annotation.Config;%0A%0Aimport static org.assertj.core.api.Java6Assertions.assertThat;%0A%0A@RunWith(RobolectricTestRunner.class)%0A@Config(constants = BuildConfig.class)%0Apublic class MainTest %7B
 %0A   

Optimize code