Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #114 from grandcentrix/feature/removable_test
Browse files Browse the repository at this point in the history
Add tests for OneTimeRemovable
  • Loading branch information
StefMa authored Sep 26, 2017
2 parents 6bc2ef3 + 545fe12 commit 1c78acd
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2017 grandcentrix GmbH
* 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 net.grandcentrix.thirtyinch.internal;


import org.junit.Test;

import static org.assertj.core.api.Java6Assertions.assertThat;

public class OneTimeRemovableTest {

@Test
public void remove_once_calls_OnRemove() throws Exception {
final int[] called = new int[]{0};
final OneTimeRemovable removable = new OneTimeRemovable() {
@Override
public void onRemove() {
called[0]++;
}
};

assertThat(called[0]).isEqualTo(0);
assertThat(removable.isRemoved()).isFalse();

removable.remove();
assertThat(called[0]).isEqualTo(1);
assertThat(removable.isRemoved()).isTrue();
}

@Test
public void remove_twice_calls_OnRemove_once() throws Exception {
final int[] called = new int[]{0};
final OneTimeRemovable removable = new OneTimeRemovable() {
@Override
public void onRemove() {
called[0]++;
}
};

assertThat(called[0]).isEqualTo(0);
assertThat(removable.isRemoved()).isFalse();

removable.remove();
assertThat(called[0]).isEqualTo(1);
assertThat(removable.isRemoved()).isTrue();

removable.remove();
assertThat(called[0]).isEqualTo(1);
assertThat(removable.isRemoved()).isTrue();
}
}

0 comments on commit 1c78acd

Please sign in to comment.