Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
994feec
Add the gradle task for Robolectric.
dalinaum Nov 23, 2015
ab599a4
Add Robolectric example.
dalinaum Dec 4, 2015
735ccb4
Merge branch 'master' into lk/robolectric
dalinaum Dec 5, 2015
5380abd
Add librealm-jni-darwin.dylib temporarily
dalinaum Dec 5, 2015
066ae5e
Merge branch 'master' into lk/robolectric
dalinaum Dec 5, 2015
d4dc02a
Add testRobolectric task.
dalinaum Dec 8, 2015
c4602cb
Update test example.
dalinaum Dec 8, 2015
39b455c
Use Gradle plugin instead of using a prebuilt file.
dalinaum Dec 12, 2015
5c6eaf5
Apply statc core lib.
dalinaum Dec 23, 2015
6e659f4
Fix 'gradle assemble'
dalinaum Dec 23, 2015
b1ed203
Merge remote-tracking branch 'origin/master' into lk/robolectric
dalinaum Dec 23, 2015
669266c
Update robolectricExample
dalinaum Dec 23, 2015
64ed2b2
Add missing dylib file.
dalinaum Dec 23, 2015
393ee11
Merge remote-tracking branch 'origin/master' into lk/robolectric
dalinaum Dec 23, 2015
b3b2995
update librealm-jni-darwin.dylib
dalinaum Dec 24, 2015
54b74da
Modify gradle scripts and change native lib path.
dalinaum Jan 8, 2016
20e5b97
Delete many tests.
dalinaum Jan 8, 2016
5878f0e
Fix buildRobolectric.
dalinaum Jan 8, 2016
368247e
Merge branch 'master' into lk/robolectric
dalinaum Jan 12, 2016
b020122
Rename tasks and delete testRobolectric.
dalinaum Jan 12, 2016
7c41b8f
Add robolectricDistribuitionPackage.
dalinaum Jan 12, 2016
d4764cb
Change the Robolectric distribution filename.
dalinaum Jan 12, 2016
7a59bfe
Add uploadRobolectricDistributionPackage
dalinaum Jan 12, 2016
e6f19d4
Fix a problem with ReLinker.
dalinaum Jan 12, 2016
c3242be
Update changelog.txt
dalinaum Jan 12, 2016
2f5c9f1
Add download Realm Robolectric for Robolectric example.
dalinaum Jan 12, 2016
72eb8d9
Merge branch 'master' into lk/robolectric
dalinaum Jan 12, 2016
f93e81b
Add .gitignore.
dalinaum Jan 12, 2016
fbf2a52
Delete unused Proguard rules.
dalinaum Jan 12, 2016
ffc8ef9
Improve formatting and change names and sentences as reviews.
dalinaum Jan 13, 2016
21a2f5b
Improve formatting.
dalinaum Jan 13, 2016
4520c9a
setProperty is moved to @BeforeClass method to prvent setting per test.
dalinaum Jan 13, 2016
9c859f5
Fix a broken build.gradle
dalinaum Jan 13, 2016
0189e69
Use a very simple tests instead of RealmTest.
dalinaum Jan 13, 2016
69ccf00
Update a launcher icon.
dalinaum Jan 13, 2016
911a59c
Fix a broken icon reference.
dalinaum Jan 13, 2016
cf008ad
Add Gradle Plugin 'realm-robolectric'
dalinaum Jan 13, 2016
4d2c8d7
Remove unused imports.
dalinaum Jan 13, 2016
ec65ddd
Fix a typo
dalinaum Jan 13, 2016
a5454ff
Remove unused imports.
dalinaum Jan 14, 2016
defd84e
Introduce the environment variable REALM_CORE_LIB
dalinaum Jan 14, 2016
a87602f
Remove unnecessasry imports and variables and reaname fields.
dalinaum Jan 14, 2016
2aae168
Remove unnecessary TestHelper.
dalinaum Jan 14, 2016
ba4dd13
robolectricExample only has 1 test now.
dalinaum Jan 14, 2016
ae2b224
Modify assembleRobolectric task little.
dalinaum Jan 14, 2016
106a762
Locale.getDefault() -> Locale.US
dalinaum Jan 14, 2016
ce98b1d
Fix weird formmaing.
dalinaum Jan 14, 2016
d6dbd11
Add comment of loadLibrary
dalinaum Jan 14, 2016
4d4a405
Support the debug version of Robolectric for Darwin.
dalinaum Jan 14, 2016
71b8a89
robolectricLibs -> src/test/libs
dalinaum Jan 14, 2016
b13105b
Introduce RealmRobolectricRule
dalinaum Jan 14, 2016
3036445
Add missing javadoc comments.
dalinaum Jan 14, 2016
337a6e1
Use REALM_ROBOLECTRIC to skip log libary instead of checking OS.
dalinaum Jan 14, 2016
a1e68df
Support coreSourcePath to build the static Realm Core lib.
dalinaum Jan 14, 2016
fd7cec4
Fix typo.
dalinaum Jan 14, 2016
72a6ef2
Merge branch 'master' into lk/robolectric
dalinaum Jan 14, 2016
d8f9bba
Fix typo
dalinaum Jan 14, 2016
26f0dc4
Provide groups for all new tasks.
dalinaum Jan 14, 2016
057f505
The task of Gradle plugin has inputs and outputs.
dalinaum Jan 14, 2016
99aca03
Split bit assembleRobolectric task into three tasks.
dalinaum Jan 14, 2016
af581ab
Fix copyright.
dalinaum Jan 14, 2016
5feff19
Fix copyright.
dalinaum Jan 14, 2016
cb47ccd
Fix typo
dalinaum Jan 14, 2016
ea13014
de.undercouch:gradle-download-task is moved to Gradle plugin.
dalinaum Jan 14, 2016
cb3028b
Apply @Rule for RealmRobolectricRule.
dalinaum Jan 14, 2016
74d57fe
Fix typo.
dalinaum Jan 15, 2016
18629ac
Merge branch 'master' into lk/robolectric
dalinaum Jan 15, 2016
88df7bd
PR feedback
dalinaum Jan 15, 2016
647adee
Merge branch 'master' into lk/robolectric
dalinaum Jan 15, 2016
3f0a3b0
Merge branch 'master' into lk/robolectric
dalinaum Jan 18, 2016
d8c0fca
PR feedback.
dalinaum Jan 18, 2016
bc7e919
Adding java.library.path instead overwritting its value.
dalinaum Jan 18, 2016
442af20
Fix a bug using string instead of variable.
dalinaum Jan 18, 2016
94e8927
Fix RealmRobolectricRule correctly.
dalinaum Jan 18, 2016
749d6c2
Fix style.
dalinaum Jan 19, 2016
60d2712
PR feedback
dalinaum Jan 19, 2016
31ee939
Fix checking System.env.REALM_CORE_HOME
dalinaum Jan 19, 2016
f9911ba
Fix checking REALM_CORE_HOME correctly.
dalinaum Jan 19, 2016
2f94973
Fix invoking RealmConfiguration.Builder.
dalinaum Jan 19, 2016
31163df
testapk is moved to Gradle plugin realm-android
dalinaum Jan 19, 2016
23c6d60
Merge branch 'master' into lk/robolectric
dalinaum Feb 23, 2016
4294d7d
Remove unnecessay plugin.
dalinaum Feb 23, 2016
8a79e81
Merge branch 'master' into lk/robolectric
dalinaum Mar 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ realm_version_check.timestamp

# Build artifacts
*.so
*.dylib
*.d
*.o

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Enhancements

* RealmObjectSchema.isPrimaryKey(String) (#2440)
* Added support for Robolectric on Max OS X (#1867).

### Bug fixes

Expand Down
30 changes: 30 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ task installRealmJava(type:Task) {
description = 'Install the Realm library and Gradle plugin into mavenLocal()'
}

task installRobolectric(type:GradleBuild) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now part of the Gradle plugin, so could be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for the development.

description = 'Install the Robolectric library into example'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide a group for all the new tasks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added groups.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When invoking ./gradlew installRobolectric, I got following error.
Did I do something wrong?

./gradlew installRealm works fine.

gcc -O3 -DNDEBUG -fPIC -DPIC -pthread -Wall -Wextra -ansi -pedantic -Wno-long-long -Wno-variadic-macros -DREALM_HAVE_CONFIG -DPIC -I/usr/local/include/realm/ -I/usr/local/include/ -I/System/Library/Frameworks/JavaVM.framework/Headers/ -Os -std=c++11 -ffunction-sections -fdata-sections -flto -MMD -MP -c util.cpp -o util-darwin.pic.o
columntypeutil.cpp:45:60: warning: unused parameter 'columnType' [-Wunused-parameter]
jobject GetJColumnTypeFromColumnType(JNIEnv* env, DataType columnType)
                                                           ^
io_realm_internal_table.cpp:679:26: warning: unused parameter 'jTableBase' [-Wunused-parameter]
    JNIEnv* env, jobject jTableBase, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex)
                         ^
io_realm_internal_table.cpp:694:26: warning: unused parameter 'jTableBase' [-Wunused-parameter]
    JNIEnv* env, jobject jTableBase, jlong nativeTablePtr, jlong columnIndex, jlong rowIndex)
                         ^
io_realm_internal_table.cpp:1586:79: warning: adding 'realm::DataType' to a string does not append to the string [-Wstring-plus-int]
            ThrowException(env, IllegalArgument, "Invalid primary key type: " + column_type);
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
io_realm_internal_table.cpp:1586:79: note: use array indexing to silence this warning
            ThrowException(env, IllegalArgument, "Invalid primary key type: " + column_type);
                                                                              ^
                                                 &                            [            ]
io_realm_internal_table.cpp:1709:45: error: no member named 'get_version_counter' in 'realm::Table'
        return (jlong) TBL(nativeTablePtr)->get_version_counter();
                       ~~~~~~~~~~~~~~~~~~~  ^
3 warnings and 1 error generated.
make: *** [io_realm_internal_table-darwin.pic.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated.
:realm:realm-jni:assembleRobolectric FAILED
:installRobolectric FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/zaki/fromgit/realm/realm-java/realm/realm-jni/build.gradle' line: 317

* What went wrong:
Execution failed for task ':realm-jni:assembleRobolectric'.
> Process 'command 'make'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zaki50 What version of realm-core do you use? I guess you are not using v0.95.7, or you installed another version on your /usr/local/include.
https://github.com/realm/realm-core/blob/fec030131b822f388b37630d60d1573aeb6a30d8/src/realm/table.hpp#L1420

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zaki50 Since I modified realm-android plugin and added realm-robolectric, I recommend using ./gradlew installRealmJava to install both plugins instead of ./gradlew installRealm.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dalinaum right. 0.95.0 is installed in /usr/local/include/.

How do I update that?

/usr/local/include/realm/version.hpp

#define REALM_VER_MAJOR 0
#define REALM_VER_MINOR 95
#define REALM_VER_PATCH 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can uninstall the old version using sh build.sh uninstall and install v0.95.7 then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zaki50 If you set coreSourcePath on realm.properties, assembleRobolectric will use this source path instead of the installed Core lib.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dalinaum thx!

group = 'Install'
buildFile = file('realm/build.gradle')
tasks = ['installRobolectric']
}

task assembleRobolectric(type:GradleBuild) {
description = 'Assemble the Robolectric support'
group = 'Build'
buildFile = file('realm/build.gradle')
tasks = ['assembleRobolectric']
}

task assembleExamples(type:GradleBuild) {
dependsOn installGradlePlugin
dependsOn installRealm
Expand Down Expand Up @@ -174,6 +188,16 @@ task distributionPackage(type:Zip) {
}
}

task createRobolectricDistributionPackages(type:Zip) {
description = 'Create the Robolectric distribution package'
dependsOn assembleRobolectric

archiveName = "realm-robolectric-darwin-${currentVersion}.zip"
destinationDir = file("${buildDir}/outputs/distribution")

from('realm/realm-jni/build/librealm-jni-darwin.dylib')
}

task cleanRealm(type:GradleBuild) {
description = 'Clean the Realm project'
group = 'Clean'
Expand Down Expand Up @@ -220,6 +244,12 @@ task uploadDistributionPackage(type: Exec) {
commandLine 's3cmd', 'put', "${buildDir}/outputs/distribution/realm-java-${currentVersion}.zip", 's3://static.realm.io/downloads/java/'
}

task uploadRobolectricDistributionPackage(type: Exec) {
description = 'Upload the Robolectric distribution package to S3'
dependsOn createRobolectricDistributionPackages
commandLine 's3cmd', 'put', "${buildDir}/outputs/distribution/realm-robolectric-darwin-${currentVersion}.zip", 's3://static.realm.io/downloads/java/'
}

task createEmptyFile(type: Exec) {
group = 'Release'
description = 'Create an empty file that will serve as a link on S3'
Expand Down
2 changes: 1 addition & 1 deletion examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ configurations.all {
}

allprojects {
def currentVersion = file("${rootDir}/../version.txt").text.trim()
ext.currentVersion = file("${rootDir}/../version.txt").text.trim()

buildscript {
repositories {
Expand Down
1 change: 1 addition & 0 deletions examples/robolectricExample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.zip
37 changes: 37 additions & 0 deletions examples/robolectricExample/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'android-command'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
apply plugin: 'realm-robolectric'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this as a separate plugin? I guess the main benefit is that people not using Robolectrics aren't forced to download any extra files, but on the downside they have to add this extra line. I'm a probably leaning towards this is OK, but what do you think @realm/java ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most developers does not need the support for Robolectric for Darwin. They can use other unit test tools, they can use Mockup objects or even they don't use any unit test tool. So I want this as a separate plugin not to bother other developers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the plugin will hopefully work for both Windows and Linux soon :), but I get your point. It is probably only a minority that wants to use Robolectrics.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate plugin +1


android {
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

defaultConfig {
applicationId 'io.realm.examples.robolectric'
targetSdkVersion 21
minSdkVersion 15
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}

command {
events 2000
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
testCompile 'io.reactivex:rxjava:1.1.0'
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.0"
}
23 changes: 23 additions & 0 deletions examples/robolectricExample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.realm.examples.robolectric" >

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2016 Realm Inc.
*
* 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 io.realm.examples.robolectric;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions examples/robolectricExample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email"/>

</android.support.design.widget.CoordinatorLayout>
20 changes: 20 additions & 0 deletions examples/robolectricExample/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main"
tools:context=".MainActivity">

<TextView
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
9 changes: 9 additions & 0 deletions examples/robolectricExample/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
</menu>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions examples/robolectricExample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
6 changes: 6 additions & 0 deletions examples/robolectricExample/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>
4 changes: 4 additions & 0 deletions examples/robolectricExample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="app_name">RobolectricTest</string>
<string name="action_settings">Settings</string>
</resources>
17 changes: 17 additions & 0 deletions examples/robolectricExample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2016 Realm Inc.
*
* 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 io.realm.examples.robolectric;

import android.app.Activity;
import android.content.Context;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import io.realm.examples.robolectric.entities.Person;
import io.realm.test.RealmRobolectricRule;
import io.realm.Realm;
import io.realm.RealmConfiguration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class)
public class RobolectricTest {

private Realm realm;
private Activity context;
private RealmConfiguration config;

@Rule
public RealmRobolectricRule realmRobolectricRule = new RealmRobolectricRule();

private Context getContext() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be below any fields (= below the @rule)

return context;
}

@Before
public void setUp() throws Exception {
context = Robolectric.setupActivity(MainActivity.class);
config = new RealmConfiguration.Builder(getContext()).build();
Realm.deleteRealm(config);
realm = Realm.getInstance(config);
}

@After
public void tearDown() throws Exception {
if (realm != null) {
realm.close();
}
}

@Test
public void testIsEmpty() {
assertTrue(realm.isEmpty());
Person person = new Person();
person.setName("Brad Pitt");
person.setAge(52);
realm.beginTransaction();
realm.copyToRealm(person);
realm.commitTransaction();
assertFalse(realm.isEmpty());
}
}
Loading