// Path: app/src/test/java/io/petros/posts/PreconfiguredRobolectricTestRunner.java
// public class PreconfiguredRobolectricTestRunner extends RobolectricTestRunner {
// 
//     private static final int SDK_API_LEVEL_TO_EMULATE = 25;
// 
//     /**
//      * Creates a runner to run {@code testClass}. Looks in your working directory for your AndroidManifest.xml file and res directory by
//      * default. Use the {@link Config} annotation to configure.
//      *
//      * @param testClass The test class to be run.
//      * @throws InitializationError If junit says so.
//      */
//     public PreconfiguredRobolectricTestRunner(final Class<?> testClass) throws InitializationError {
//         super(testClass);
//     }
// 
//     @Override
//     protected Config buildGlobalConfig() {
//         return new Config.Builder()
//                 .setSdk(SDK_API_LEVEL_TO_EMULATE)
//                 .setManifest(Config.NONE)
//                 .setApplication(TestPostsApplication.class)
//                 .build();
//     }
// 
// }
// 
// Path: app/src/test/java/io/petros/posts/RobolectricGeneralTestHelper.java
// public class RobolectricGeneralTestHelper extends GeneralTestHelper {
// 
//     // Application specific fields.
//     protected final Context context = getTestContext();
//     protected final PostsApplication application = getTestApplication();
// 
//     // System specific fields.
//     @Mock protected ConnectivityManager connectivityManagerMock;
// 
//     // Activity specific fields.
//     @Mock protected PostsApplication applicationMock;
//     @Mock protected SnackbarActions snackbarActionsMock;
// 
//     // ROBOLECTRIC // *******************************************************************************************************
// 
//     private Context getTestContext() {
//         return getShadowApplication().getApplicationContext();
//     }
// 
//     private ShadowApplication getShadowApplication() {
//         return ShadowApplication.getInstance();
//     }
// 
//     private PostsApplication getTestApplication() {
//         return (PostsApplication) RuntimeEnvironment.application;
//     }
// 
//     // MOCKS // *************************************************************************************************************
// 
//     protected void setUpMocks() {
//         super.setUpMocks();
//         setUpApplicationMocks();
//     }
// 
//     private void setUpApplicationMocks() {
//         when(applicationMock.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManagerMock);
//         when(applicationMock.snackbar()).thenReturn(snackbarActionsMock);
//     }
// 
//     // POST // **************************************************************************************************************
// 
//     protected Bundle getExtras(final Post post) {
//         final Bundle extras = new Bundle();
//         extras.putInt(Post.USER_ID, post.getUserId());
//         extras.putInt(Post.ID, post.getId());
//         extras.putString(Post.TITLE, post.getTitle());
//         extras.putString(Post.BODY, post.getBody());
//         return extras;
//     }
// 
// }
// 
// Path: app/src/main/java/io/petros/posts/model/User.java
// public class User extends RealmObject {
// 
//     public static final String ID = "id";
//     public static final String NAME = "name";
//     public static final String USERNAME = "username";
//     public static final String EMAIL = "email";
// 
//     @SerializedName(ID)
//     @Expose
//     @PrimaryKey
//     private Integer id;
// 
//     @SerializedName(NAME)
//     @Expose
//     private String name;
// 
//     @SerializedName(USERNAME)
//     @Expose
//     private String username;
// 
//     @SerializedName(EMAIL)
//     @Expose
//     private String email;
// 
//     public Integer getId() {
//         return id;
//     }
// 
//     public void setId(final Integer id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(final String name) {
//         this.name = name;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(final String email) {
//         this.email = email;
//     }
// 
// }


import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import io.petros.posts.PreconfiguredRobolectricTestRunner;
import io.petros.posts.RobolectricGeneralTestHelper;
import io.petros.posts.model.User;
import io.realm.Realm;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
package io.petros.posts.datastore;




/**
 * This test is ignored until PowerMock is introduced, which will mock all the Realm objects.
 */
@Ignore("java.lang.NullPointerException at io.realm.BaseRealm.beginTransaction")
@RunWith(PreconfiguredRobolectricTestRunner.class)
public class DatastoreUpdateActionsTest extends RobolectricGeneralTestHelper {

    private DatastoreUpdateActions datastoreUpdateActions;
    @Mock private Realm realmMock;
    @Mock private User realmUserMock;

    @Before
    public void setUp() {
        setUpMocks();
        setUpDatastoreActions();
    }

    private void setUpDatastoreActions() {
        datastoreUpdateActions = new DatastoreUpdateActions(realmMock);
    }

    @Test
    public void addUserTest() {
        final boolean isSuccessful = datastoreUpdateActions.user(realmUserMock, user);

        verify(realmMock, times(1)).beginTransaction();
        verify(realmUserMock, times(1)).setName(user.getName());
        verify(realmUserMock, times(1)).setUsername(user.getUsername());
        verify(realmUserMock, times(1)).setEmail(user.getEmail());
        verifyNoMoreInteractions(realmUserMock);
// Path: app/src/test/java/io/petros/posts/PreconfiguredRobolectricTestRunner.java
// public class PreconfiguredRobolectricTestRunner extends RobolectricTestRunner {
// 
//     private static final int SDK_API_LEVEL_TO_EMULATE = 25;
// 
//     /**
//      * Creates a runner to run {@code testClass}. Looks in your working directory for your AndroidManifest.xml file and res directory by
//      * default. Use the {@link Config} annotation to configure.
//      *
//      * @param testClass The test class to be run.
//      * @throws InitializationError If junit says so.
//      */
//     public PreconfiguredRobolectricTestRunner(final Class<?> testClass) throws InitializationError {
//         super(testClass);
//     }
// 
//     @Override
//     protected Config buildGlobalConfig() {
//         return new Config.Builder()
//                 .setSdk(SDK_API_LEVEL_TO_EMULATE)
//                 .setManifest(Config.NONE)
//                 .setApplication(TestPostsApplication.class)
//                 .build();
//     }
// 
// }
// 
// Path: app/src/test/java/io/petros/posts/RobolectricGeneralTestHelper.java
// public class RobolectricGeneralTestHelper extends GeneralTestHelper {
// 
//     // Application specific fields.
//     protected final Context context = getTestContext();
//     protected final PostsApplication application = getTestApplication();
// 
//     // System specific fields.
//     @Mock protected ConnectivityManager connectivityManagerMock;
// 
//     // Activity specific fields.
//     @Mock protected PostsApplication applicationMock;
//     @Mock protected SnackbarActions snackbarActionsMock;
// 
//     // ROBOLECTRIC // *******************************************************************************************************
// 
//     private Context getTestContext() {
//         return getShadowApplication().getApplicationContext();
//     }
// 
//     private ShadowApplication getShadowApplication() {
//         return ShadowApplication.getInstance();
//     }
// 
//     private PostsApplication getTestApplication() {
//         return (PostsApplication) RuntimeEnvironment.application;
//     }
// 
//     // MOCKS // *************************************************************************************************************
// 
//     protected void setUpMocks() {
//         super.setUpMocks();
//         setUpApplicationMocks();
//     }
// 
//     private void setUpApplicationMocks() {
//         when(applicationMock.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManagerMock);
//         when(applicationMock.snackbar()).thenReturn(snackbarActionsMock);
//     }
// 
//     // POST // **************************************************************************************************************
// 
//     protected Bundle getExtras(final Post post) {
//         final Bundle extras = new Bundle();
//         extras.putInt(Post.USER_ID, post.getUserId());
//         extras.putInt(Post.ID, post.getId());
//         extras.putString(Post.TITLE, post.getTitle());
//         extras.putString(Post.BODY, post.getBody());
//         return extras;
//     }
// 
// }
// 
// Path: app/src/main/java/io/petros/posts/model/User.java
// public class User extends RealmObject {
// 
//     public static final String ID = "id";
//     public static final String NAME = "name";
//     public static final String USERNAME = "username";
//     public static final String EMAIL = "email";
// 
//     @SerializedName(ID)
//     @Expose
//     @PrimaryKey
//     private Integer id;
// 
//     @SerializedName(NAME)
//     @Expose
//     private String name;
// 
//     @SerializedName(USERNAME)
//     @Expose
//     private String username;
// 
//     @SerializedName(EMAIL)
//     @Expose
//     private String email;
// 
//     public Integer getId() {
//         return id;
//     }
// 
//     public void setId(final Integer id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(final String name) {
//         this.name = name;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public void setEmail(final String email) {
//         this.email = email;
//     }
// 
// }


// Path: app/src/test/java/io/petros/posts/datastore/DatastoreUpdateActionsTest.java
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import io.petros.posts.PreconfiguredRobolectricTestRunner;
import io.petros.posts.RobolectricGeneralTestHelper;
import io.petros.posts.model.User;
import io.realm.Realm;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

package io.petros.posts.datastore;




/**
 * This test is ignored until PowerMock is introduced, which will mock all the Realm objects.
 */
@Ignore("java.lang.NullPointerException at io.realm.BaseRealm.beginTransaction")
@RunWith(PreconfiguredRobolectricTestRunner.class)
public class DatastoreUpdateActionsTest extends RobolectricGeneralTestHelper {

    private DatastoreUpdateActions datastoreUpdateActions;
    @Mock private Realm realmMock;
    @Mock private User realmUserMock;

    @Before
    public void setUp() {
        setUpMocks();
        setUpDatastoreActions();
    }

    private void setUpDatastoreActions() {
        datastoreUpdateActions = new DatastoreUpdateActions(realmMock);
    }

    @Test
    public void addUserTest() {
        final boolean isSuccessful = datastoreUpdateActions.user(realmUserMock, user);

        verify(realmMock, times(1)).beginTransaction();
        verify(realmUserMock, times(1)).setName(user.getName());
        verify(realmUserMock, times(1)).setUsername(user.getUsername());
        verify(realmUserMock, times(1)).setEmail(user.getEmail());
        verifyNoMoreInteractions(realmUserMock);
        verify(realmMock, times(1)).commitTransaction();