<commit_before>/*
 * Copyright 2010 the original author or authors.
 *
 * 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 org.powermock.utils;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.powermock.utils.Synchronizer.await;
import static org.powermock.utils.model.synchronizer.SynchronizerOperationOptions.atMost;
import static org.powermock.utils.model.synchronizer.SynchronizerOperationOptions.until;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.junit.Before;
import org.junit.Test;
import org.powermock.utils.classes.Asynch;
import org.powermock.utils.classes.ExceptionThrowingAsynch;
import org.powermock.utils.classes.ExceptionThrowingFakeRepository;
import org.powermock.utils.classes.FakeRepository;
import org.powermock.utils.classes.FakeRepositoryEqualsOne;
import org.powermock.utils.classes.FakeRepositoryImpl;
import org.powermock.utils.classes.FakeRepositoryValue;
import org.powermock.utils.model.synchronizer.BlockingSupportedOperation;
import org.powermock.utils.model.synchronizer.Condition;
import org.powermock.utils.model.synchronizer.ConditionSpecification;

public class SynchronizerTest {

	private FakeRepository fakeRepository;

	@Before
	public void setup() {
		fakeRepository = new FakeRepositoryImpl();
	}

	@Test(timeout = 2000)
	public void foreverConditionSpecificationWithDirectBlock() throws Exception {
		new Asynch(fakeRepository).perform();
		await(fakeRepositoryValueEqualsOne()).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000)
	public void foreverConditionSpecificationUsingUntilWithDirectBlock() throws Exception {
		new Asynch(fakeRepository).perform();
		await(until(fakeRepositoryValueEqualsOne())).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000)
	public void foreverConditionWithHamcrestMatchersWithDirectBlock() throws Exception {
		new Asynch(fakeRepository).perform();
		await(until(valueCondition(), equalTo(1))).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000, expected = TimeoutException.class)
	public void conditionBreaksAfterDurationTimeout() throws Exception {
		new Asynch(fakeRepository).perform();
		await(200, TimeUnit.MILLISECONDS, until(valueCondition(), equalTo(1))).block();
		assertEquals(1, fakeRepository.getValue());
	}
	
	@Test(timeout = 2000, expected = TimeoutException.class)
	public void conditionBreaksAfterDurationTimeoutWhenUsingAtMost() throws Exception {
		new Asynch(fakeRepository).perform();
		await(atMost(200, TimeUnit.MILLISECONDS), until(valueCondition(), equalTo(1))).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000, expected = IllegalStateException.class)
	public void uncaughtExceptionsArePropagatedToAwaitingThreadAndBreaksForeverBlockWhenSetToCatchAllUncaughtExceptions() throws Exception {
		BlockingSupportedOperation operation = await(until(valueCondition(), equalTo(1))).andCatchAllUncaughtExceptions();
		new ExceptionThrowingAsynch().perform();
		operation.block();
	}

	@Test(timeout = 2000, expected = IllegalStateException.class)
	public void exceptionsInValueConditionArePropagatedToAwaitingThreadAndBreaksForeverBlock() throws Exception {
		final ExceptionThrowingFakeRepository repository = new ExceptionThrowingFakeRepository();
		new Asynch(repository).perform();
		await(until(new FakeRepositoryValue(repository), equalTo(1))).block();
	}

	private ConditionSpecification fakeRepositoryValueEqualsOne() {
		return new FakeRepositoryEqualsOne(fakeRepository);
	}

	private Condition<Integer> valueCondition() {
		return new FakeRepositoryValue(fakeRepository);
	}
}<commit_msg>Minor method name change<commit_after>/*
 * Copyright 2010 the original author or authors.
 *
 * 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 org.powermock.utils;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.powermock.utils.Synchronizer.await;
import static org.powermock.utils.model.synchronizer.SynchronizerOperationOptions.atMost;
import static org.powermock.utils.model.synchronizer.SynchronizerOperationOptions.until;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.junit.Before;
import org.junit.Test;
import org.powermock.utils.classes.Asynch;
import org.powermock.utils.classes.ExceptionThrowingAsynch;
import org.powermock.utils.classes.ExceptionThrowingFakeRepository;
import org.powermock.utils.classes.FakeRepository;
import org.powermock.utils.classes.FakeRepositoryEqualsOne;
import org.powermock.utils.classes.FakeRepositoryImpl;
import org.powermock.utils.classes.FakeRepositoryValue;
import org.powermock.utils.model.synchronizer.BlockingSupportedOperation;
import org.powermock.utils.model.synchronizer.Condition;
import org.powermock.utils.model.synchronizer.ConditionSpecification;

public class SynchronizerTest {

	private FakeRepository fakeRepository;

	@Before
	public void setup() {
		fakeRepository = new FakeRepositoryImpl();
	}

	@Test(timeout = 2000)
	public void foreverConditionSpecificationWithDirectBlock() throws Exception {
		new Asynch(fakeRepository).perform();
		await(fakeRepositoryValueEqualsOne()).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000)
	public void foreverConditionSpecificationUsingUntilWithDirectBlock() throws Exception {
		new Asynch(fakeRepository).perform();
		await(until(fakeRepositoryValueEqualsOne())).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000)
	public void foreverConditionWithHamcrestMatchersWithDirectBlock() throws Exception {
		new Asynch(fakeRepository).perform();
		await(until(valueCondition(), equalTo(1))).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000, expected = TimeoutException.class)
	public void conditionBreaksAfterDurationTimeout() throws Exception {
		new Asynch(fakeRepository).perform();
		await(200, TimeUnit.MILLISECONDS, until(valueCondition(), equalTo(1))).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000, expected = TimeoutException.class)
	public void conditionBreaksAfterDurationTimeoutWhenUsingAtMost() throws Exception {
		new Asynch(fakeRepository).perform();
		await(atMost(200, TimeUnit.MILLISECONDS), until(valueCondition(), equalTo(1))).block();
		assertEquals(1, fakeRepository.getValue());
	}

	@Test(timeout = 2000, expected = IllegalStateException.class)
	public void uncaughtExceptionsArePropagatedToAwaitingThreadAndBreaksForeverBlockWhenSetToCatchAllUncaughtExceptions() throws Exception {
		BlockingSupportedOperation operation = await(until(valueCondition(), equalTo(1))).andCatchAllUncaughtExceptions();
		new ExceptionThrowingAsynch().perform();
		operation.block();
	}

	@Test(timeout = 2000, expected = IllegalStateException.class)
	public void exceptionsInConditionsArePropagatedToAwaitingThreadAndBreaksForeverBlock() throws Exception {
		final ExceptionThrowingFakeRepository repository = new ExceptionThrowingFakeRepository();
		new Asynch(repository).perform();
		await(until(new FakeRepositoryValue(repository), equalTo(1))).block();
	}

	private ConditionSpecification fakeRepositoryValueEqualsOne() {
		return new FakeRepositoryEqualsOne(fakeRepository);
	}

	private Condition<Integer> valueCondition() {
		return new FakeRepositoryValue(fakeRepository);
	}
}
{'fraction_non_alphanumeric': 0.09769303201506592, 'fraction_numerical': 0.01224105461393597, 'mean_word_length': 6.831336405529954, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3434605', 'n_tokens_mistral': 2464, 'n_tokens_neox': 2319, 'n_words': 527}