// Path: deferred/src/main/java/com/tuenti/deferred/Promise.java
// enum State {
// 	/**
// 	 * The Promise is still pending - it could be created, submitted for execution,
// 	 * or currently running, but not yet finished.
// 	 */
// 	PENDING,
// 
// 	/**
// 	 * The Promise has finished running and a failure occurred.
// 	 * Thus, the Promise is rejected.
// 	 *
// 	 * @see Deferred#reject(Object)
// 	 */
// 	REJECTED,
// 
// 	/**
// 	 * The Promise has finished running successfully.
// 	 * Thus the Promise is resolved.
// 	 *
// 	 * @see Deferred#resolve(Object)
// 	 */
// 	RESOLVED
// }


import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Test;
import com.tuenti.deferred.Promise.State;
/*
 * Copyright 2013 Ray Tsang
 * 
 * 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 com.tuenti.deferred;





@SuppressWarnings({"unchecked", "rawtypes"})
public class FailureTest extends AbstractDeferredTest {


	@Test
	public void testBadCallback() {
		final AtomicInteger counter = new AtomicInteger();

		deferredManager.when(successCallable(100, 1000))
		.done(new DoneCallback() {
			public void onDone(Object result) {
				counter.incrementAndGet();
				throw new RuntimeException("this exception is expected");
			}
		}).done(new DoneCallback<Integer>() {
			@Override
			public void onDone(Integer result) {
				counter.incrementAndGet();
			}
		}).fail(new FailCallback() {
			public void onFail(Object result) {
				Assert.fail("Shouldn't be here");
			}
		}).always(new AlwaysCallback<Integer, Throwable>() {

			@Override
// Path: deferred/src/main/java/com/tuenti/deferred/Promise.java
// enum State {
// 	/**
// 	 * The Promise is still pending - it could be created, submitted for execution,
// 	 * or currently running, but not yet finished.
// 	 */
// 	PENDING,
// 
// 	/**
// 	 * The Promise has finished running and a failure occurred.
// 	 * Thus, the Promise is rejected.
// 	 *
// 	 * @see Deferred#reject(Object)
// 	 */
// 	REJECTED,
// 
// 	/**
// 	 * The Promise has finished running successfully.
// 	 * Thus the Promise is resolved.
// 	 *
// 	 * @see Deferred#resolve(Object)
// 	 */
// 	RESOLVED
// }


// Path: deferred/src/test/java/com/tuenti/deferred/FailureTest.java
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Test;
import com.tuenti.deferred.Promise.State;

/*
 * Copyright 2013 Ray Tsang
 * 
 * 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 com.tuenti.deferred;





@SuppressWarnings({"unchecked", "rawtypes"})
public class FailureTest extends AbstractDeferredTest {


	@Test
	public void testBadCallback() {
		final AtomicInteger counter = new AtomicInteger();

		deferredManager.when(successCallable(100, 1000))
		.done(new DoneCallback() {
			public void onDone(Object result) {
				counter.incrementAndGet();
				throw new RuntimeException("this exception is expected");
			}
		}).done(new DoneCallback<Integer>() {
			@Override
			public void onDone(Integer result) {
				counter.incrementAndGet();
			}
		}).fail(new FailCallback() {
			public void onFail(Object result) {
				Assert.fail("Shouldn't be here");
			}
		}).always(new AlwaysCallback<Integer, Throwable>() {

			@Override
			public void onAlways(State state, Integer resolved, Throwable rejected) {