-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
80% code coverage for StorIO-Common #461
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 0 additions & 82 deletions
82
...ommon/src/main/java/com/pushtorefresh/storio/operations/group/PreparedGroupOperation.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
storio-common/src/test/java/com/pushtorefresh/storio/StorIOExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.pushtorefresh.storio; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertSame; | ||
|
||
public class StorIOExceptionTest { | ||
|
||
@Test | ||
public void checkConstructorWithDetailMessage() { | ||
StorIOException storIOException = new StorIOException("test detail message"); | ||
assertEquals("test detail message", storIOException.getMessage()); | ||
} | ||
|
||
@Test | ||
public void checkConstructorWithDetailMessageAndThrowable() { | ||
Throwable testThrowable = new RuntimeException("yo"); | ||
StorIOException storIOException = new StorIOException("test detail message", testThrowable); | ||
|
||
assertEquals("test detail message", storIOException.getMessage()); | ||
assertSame(testThrowable, storIOException.getCause()); | ||
} | ||
|
||
@Test | ||
public void checkConstructorWithThrowable() { | ||
Throwable testThrowable = new RuntimeException("yo"); | ||
StorIOException storIOException = new StorIOException(testThrowable); | ||
|
||
assertSame(testThrowable, storIOException.getCause()); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
storio-common/src/test/java/com/pushtorefresh/storio/internal/ChangesBusTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.pushtorefresh.storio.internal; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import rx.Observable; | ||
import rx.observers.TestSubscriber; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.fail; | ||
|
||
public class ChangesBusTest { | ||
|
||
@Test | ||
public void asObservableShouldNotReturnNullIfRxJavaInClassPath() { | ||
ChangesBus<String> changesBus = new ChangesBus<String>(true); | ||
assertNotNull(changesBus.asObservable()); | ||
} | ||
|
||
@Test | ||
public void asObservableShouldReturnNullIfRxJavaIsNotInTheClassPath() { | ||
ChangesBus<String> changesBus = new ChangesBus<String>(false); | ||
assertNull(changesBus.asObservable()); | ||
} | ||
|
||
@Test | ||
public void onNextShouldNotThrowExceptionIfRxJavaIsNotInTheClassPath() { | ||
ChangesBus<String> changesBus = new ChangesBus<String>(false); | ||
|
||
try { | ||
changesBus.onNext("don't crash me bro"); | ||
} catch (Exception e) { | ||
fail("Yo, WTF dude?"); | ||
} | ||
} | ||
|
||
@Test | ||
public void onNextShouldSendMessagesToObserverIfRxJavaIsInTheClassPath() { | ||
ChangesBus<String> changesBus = new ChangesBus<String>(true); | ||
|
||
TestSubscriber<String> testSubscriber = new TestSubscriber<String>(); | ||
|
||
Observable<String> observable = changesBus.asObservable(); | ||
assertNotNull(observable); | ||
|
||
observable.subscribe(testSubscriber); | ||
|
||
List<String> messages = asList("My", "life", "my", "rules", "please?"); | ||
|
||
for (String message: messages) { | ||
changesBus.onNext(message); | ||
} | ||
|
||
testSubscriber.assertReceivedOnNext(messages); | ||
testSubscriber.assertNoTerminalEvent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
storio-common/src/test/java/com/pushtorefresh/storio/internal/EnvironmentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.pushtorefresh.storio.internal; | ||
|
||
import com.pushtorefresh.storio.test.PrivateConstructorChecker; | ||
|
||
import org.junit.Test; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static java.lang.reflect.Modifier.FINAL; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
public class EnvironmentTest { | ||
|
||
@Test | ||
public void constructorShouldBePrivateAndThrowException() { | ||
PrivateConstructorChecker | ||
.forClass(Environment.class) | ||
.expectedTypeOfException(IllegalStateException.class) | ||
.expectedExceptionMessage("No instances please") | ||
.check(); | ||
} | ||
|
||
@Test | ||
public void rxJavaShouldBeInClassPath() { | ||
assertTrue(Environment.RX_JAVA_IS_IN_THE_CLASS_PATH); | ||
} | ||
|
||
@Test | ||
public void shouldThrowExceptionIfRxJavaIsNotInTheClassPath() throws NoSuchFieldException, IllegalAccessException { | ||
Field field = Environment.class.getDeclaredField("RX_JAVA_IS_IN_THE_CLASS_PATH"); | ||
|
||
field.setAccessible(true); | ||
|
||
// Removing FINAL modifier | ||
Field modifiersFieldOfTheField = Field.class.getDeclaredField("modifiers"); | ||
modifiersFieldOfTheField.setAccessible(true); | ||
modifiersFieldOfTheField.setInt(field, field.getModifiers() & ~FINAL); | ||
|
||
final Object prevValue = field.get(null); | ||
|
||
field.set(null, false); // No Environment will think that RxJava is not in the ClassPath | ||
|
||
try { | ||
Environment.throwExceptionIfRxJavaIsNotAvailable("yolo"); | ||
fail(); | ||
} catch (IllegalStateException expected) { | ||
assertEquals("yolo requires RxJava in classpath," + | ||
" please add it as compile dependency to the application", | ||
expected.getMessage() | ||
); | ||
} finally { | ||
// Return previous value of the field | ||
field.set(null, prevValue); | ||
|
||
// Restoring FINAL modifier (for better tests performance) | ||
modifiersFieldOfTheField.setInt(field, field.getModifiers() & FINAL); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldNotThrowExceptionIfRxJavaIsInTheClassPath() { | ||
// Because RxJava should be in the ClassPath for tests | ||
Environment.throwExceptionIfRxJavaIsNotAvailable("no exceptions please"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should it be faster with
final
? As for me it's not uniquely (http://stackoverflow.com/a/4279442)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think it will be faster because of JIT.
27 июля 2015 г. 8:59 AM пользователь "Dmitrii Nikitin" <
notifications@github.com> написал: