// Path: src/com/thoughtworks/calabash/android/CalabashException.java
// public class CalabashException extends Exception {
// 
//     public CalabashException(String message, Exception e) {
//         super(message, e);
//     }
// 
//     public CalabashException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/com/thoughtworks/calabash/android/ConditionalWaiter.java
// public class ConditionalWaiter {
//     private final ICondition condition;
// 
//     public ConditionalWaiter(ICondition condition) {
//         this.condition = condition;
//     }
// 
//     public void run(int times, int sleepTimeInSec) throws CalabashException {
//         int timesTested = 0;
//         int sleepTimeInMilli = sleepTimeInSec * 1000;
//         while (!condition.test() && timesTested <= times) {
//             try {
//                 info("Retrying wait condition: " + condition.getDescription());
//                 Thread.sleep(sleepTimeInMilli);
//                 timesTested++;
//             } catch (InterruptedException e) {
//                 throw new RuntimeException(e);
//             }
//         }
//         if (timesTested > times)
//             throw new CalabashException("Wait condition failed : " + condition.getDescription());
// 
//     }
// 
//     public void run(int timeoutInMillis) throws CalabashException {
//         long startTime = System.currentTimeMillis();
//         do {
//             if (condition.test()) {
//                 return;
//             }
//         } while ((System.currentTimeMillis() - startTime) < timeoutInMillis);
//         throw new CalabashException(format("Wait condition (%s) timed out after %s ms", condition.getDescription(), timeoutInMillis));
//     }
// }
// 
// Path: src/com/thoughtworks/calabash/android/ICondition.java
// public abstract class ICondition {
//     private final String description;
// 
//     public ICondition(String description){
//         this.description = description;
//     }
// 
//     protected ICondition() {
//         description = null;
//     }
// 
//     public abstract boolean test() throws CalabashException;
// 
//     public String getDescription() {
//         return description;
//     }
// 
// }


import com.thoughtworks.calabash.android.CalabashException;
import com.thoughtworks.calabash.android.ConditionalWaiter;
import com.thoughtworks.calabash.android.ICondition;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
package com.thoughtworks.calabash.android.unit;


public class ConditionalWaiterTest {
    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    @Test
    public void shouldThrowExceptionWhenWaitFails() throws CalabashException {
        expectedException.expect(CalabashException.class);
        expectedException.expectMessage("Wait condition (wait description) timed out after 1000 ms");

// Path: src/com/thoughtworks/calabash/android/CalabashException.java
// public class CalabashException extends Exception {
// 
//     public CalabashException(String message, Exception e) {
//         super(message, e);
//     }
// 
//     public CalabashException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/com/thoughtworks/calabash/android/ConditionalWaiter.java
// public class ConditionalWaiter {
//     private final ICondition condition;
// 
//     public ConditionalWaiter(ICondition condition) {
//         this.condition = condition;
//     }
// 
//     public void run(int times, int sleepTimeInSec) throws CalabashException {
//         int timesTested = 0;
//         int sleepTimeInMilli = sleepTimeInSec * 1000;
//         while (!condition.test() && timesTested <= times) {
//             try {
//                 info("Retrying wait condition: " + condition.getDescription());
//                 Thread.sleep(sleepTimeInMilli);
//                 timesTested++;
//             } catch (InterruptedException e) {
//                 throw new RuntimeException(e);
//             }
//         }
//         if (timesTested > times)
//             throw new CalabashException("Wait condition failed : " + condition.getDescription());
// 
//     }
// 
//     public void run(int timeoutInMillis) throws CalabashException {
//         long startTime = System.currentTimeMillis();
//         do {
//             if (condition.test()) {
//                 return;
//             }
//         } while ((System.currentTimeMillis() - startTime) < timeoutInMillis);
//         throw new CalabashException(format("Wait condition (%s) timed out after %s ms", condition.getDescription(), timeoutInMillis));
//     }
// }
// 
// Path: src/com/thoughtworks/calabash/android/ICondition.java
// public abstract class ICondition {
//     private final String description;
// 
//     public ICondition(String description){
//         this.description = description;
//     }
// 
//     protected ICondition() {
//         description = null;
//     }
// 
//     public abstract boolean test() throws CalabashException;
// 
//     public String getDescription() {
//         return description;
//     }
// 
// }


// Path: tests/com/thoughtworks/calabash/android/unit/ConditionalWaiterTest.java
import com.thoughtworks.calabash.android.CalabashException;
import com.thoughtworks.calabash.android.ConditionalWaiter;
import com.thoughtworks.calabash.android.ICondition;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

package com.thoughtworks.calabash.android.unit;


public class ConditionalWaiterTest {
    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    @Test
    public void shouldThrowExceptionWhenWaitFails() throws CalabashException {
        expectedException.expect(CalabashException.class);
        expectedException.expectMessage("Wait condition (wait description) timed out after 1000 ms");

        ConditionalWaiter conditionalWaiter = new ConditionalWaiter(new ICondition("wait description") {