Skip to content

Commit 7210fac

Browse files
authored
Merge pull request #1 from memoizr/infix
Optional infix notation
2 parents d69272f + 28814c5 commit 7210fac

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/.idea
2+
/build

src/main/kotlin/com/mvcoding/mvp/Presenter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ abstract class Presenter<VIEW : Presenter.View> {
88
private lateinit var viewSubscriptions: CompositeSubscription
99
private var view: View? = null
1010

11-
fun attach(view: VIEW) {
11+
infix fun attach(view: VIEW) {
1212
ensureViewIsNotAttached(view)
1313
this.view = view
1414
this.viewSubscriptions = CompositeSubscription()
1515
onViewAttached(view)
1616
}
1717

18-
fun detach(view: VIEW) {
18+
infix fun detach(view: VIEW) {
1919
ensureGivenViewIsAttached(view)
2020
this.view = null
2121
this.viewSubscriptions.unsubscribe()

src/test/kotlin/com/mvcoding/mvp/PresenterTest.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ class PresenterTest {
1414

1515
@Test(expected = IllegalStateException::class)
1616
fun throwsIllegalStateExceptionWhenViewIsAlreadyAttached() {
17-
presenter.attach(view)
18-
presenter.attach(view)
17+
presenter attach view
18+
presenter attach view
1919
}
2020

2121
@Test(expected = IllegalStateException::class)
2222
fun throwsIllegalStateExceptionWhenViewWasNotAttached() {
23-
presenter.detach(view)
23+
presenter detach view
2424
}
2525

2626
@Test(expected = IllegalStateException::class)
2727
fun throwsIllegalStateExceptionWhenViewWasAlreadyDetached() {
28-
presenter.attach(view)
29-
presenter.detach(view)
30-
presenter.detach(view)
28+
presenter attach view
29+
presenter detach view
30+
presenter detach view
3131
}
3232

3333
@Test(expected = IllegalStateException::class)
3434
fun throwsIllegalStateExceptionWhenTryingToDetachDifferentView() {
35-
presenter.attach(view)
36-
presenter.detach(mock<Presenter.View>())
35+
presenter attach view
36+
presenter detach mock<Presenter.View>()
3737
}
3838

3939
@Test
@@ -44,8 +44,8 @@ class PresenterTest {
4444
val events = just(Unit).doOnSubscribe { isSubscribed = true }.doOnUnsubscribe { isSubscribed = false }
4545
whenever(view.events()).thenReturn(events)
4646

47-
presenter.attach(view)
48-
presenter.detach(view)
47+
presenter attach view
48+
presenter detach view
4949

5050
assertFalse { isSubscribed }
5151
}

0 commit comments

Comments
 (0)