<commit_before>/*
 * Copyright (c) OSGi Alliance (2019). All Rights Reserved.
 * 
 * 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.osgi.test.assertj.promise;

import static org.assertj.core.api.Assertions.*;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractThrowableAssert;
import org.assertj.core.api.ObjectAssert;
import org.osgi.util.promise.Promise;

public abstract class AbstractPromiseAssert<SELF extends AbstractPromiseAssert<SELF,RESULT>, RESULT>
		extends AbstractAssert<SELF,Promise<RESULT>> {

	public AbstractPromiseAssert(Promise<RESULT> actual, Class< ? > selfType) {
		super(actual, selfType);
	}

	public SELF isDone() {
		isNotNull();
		if (!actual.isDone()) {
			failWithMessage("%nExpecting%n  <%s>%nto be done.", actual);
		}
		return myself;
	}

	public SELF isNotDone() {
		isNotNull();
		if (actual.isDone()) {
			failWithMessage("%nExpecting%n  <%s>%nto not be done.", actual);
		}
		return myself;
	}

	public SELF doesResolve(long timeout, TimeUnit unit) {
		isNotNull();
		if (!actual.isDone()) {
			final CountDownLatch latch = new CountDownLatch(1);
			actual.onResolve(latch::countDown);
			try {
				if (!latch.await(timeout, unit)) {
					failWithMessage("%nExpecting%n  <%s>%nto have resolved.",
							actual);
				}
			} catch (InterruptedException e) {
				fail("unexpected exception", e);
			}
			isDone();
		}
		return myself;
	}

	public SELF doesNotResolve(long timeout, TimeUnit unit) {
		isNotDone();
		final CountDownLatch latch = new CountDownLatch(1);
		try {
			latch.await(timeout, unit);
		} catch (InterruptedException e) {
			fail("unexpected exception", e);
		}
		isNotDone();
		return myself;
	}<commit_msg>promise: Minor fix to PromiseAssert testing<commit_after>/*
 * Copyright (c) OSGi Alliance (2019). All Rights Reserved.
 * 
 * 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.osgi.test.assertj.promise;

import static org.assertj.core.api.Assertions.*;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractThrowableAssert;
import org.assertj.core.api.ObjectAssert;
import org.osgi.util.promise.Promise;

public abstract class AbstractPromiseAssert<SELF extends AbstractPromiseAssert<SELF,RESULT>, RESULT>
		extends AbstractAssert<SELF,Promise<RESULT>> {

	public AbstractPromiseAssert(Promise<RESULT> actual, Class< ? > selfType) {
		super(actual, selfType);
	}

	public SELF isDone() {
		isNotNull();
		if (!actual.isDone()) {
			failWithMessage("%nExpecting%n  <%s>%nto be done.", actual);
		}
		return myself;
	}

	public SELF isNotDone() {
		isNotNull();
		if (actual.isDone()) {
			failWithMessage("%nExpecting%n  <%s>%nto not be done.", actual);
		}
		return myself;
	}

	public SELF doesResolve(long timeout, TimeUnit unit) {
		isNotNull();
		if (!actual.isDone()) {
			final CountDownLatch latch = new CountDownLatch(1);
			actual.onResolve(latch::countDown);
			try {
				if (!latch.await(timeout, unit)) {
					failWithMessage("%nExpecting%n  <%s>%nto have resolved.",
							actual);
				}
			} catch (InterruptedException e) {
				fail("unexpected exception", e);
			}
			isDone();
		}
		return myself;
	}

	public SELF doesNotResolve(long timeout, TimeUnit unit) {
		isNotDone();
		final CountDownLatch latch = new CountDownLatch(1);
		actual.onResolve(latch::countDown);
		try {
			if (latch.await(timeout, unit)) {
				failWithMessage("%nExpecting%n  <%s>%nto not resolve.", actual);
			}
		} catch (InterruptedException e) {
			fail("unexpected exception", e);
		}
		isNotDone();
		return myself;
	}
{'fraction_non_alphanumeric': 0.11758732737611698, 'fraction_numerical': 0.004061738424045491, 'mean_word_length': 4.278670953912111, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '5047390', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1528, 'n_words': 428}