<commit_before>/*******************************************************************************
 * Copyright (c) 2017 Red Hat, Inc and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.reddeer.workbench.condition;

import org.eclipse.reddeer.common.condition.AbstractWaitCondition;
import org.eclipse.reddeer.workbench.api.View;

/**
 * Wait condition for views checking whether specified view is open
 * 
 * @author <EMAIL>
 */
public class ViewIsOpen extends AbstractWaitCondition{
	
	private View view;
	private View resultView;
	
	/**
	 * Checks whether specified view is open
	 * @param view view to check if it is open
	 */
	public ViewIsOpen(View view) {
		this.view = view;
	}

	@Override
	public boolean test() {
		if (view.isOpen()) {
			this.resultView = view;
			return true;
		}
		return false;
	}
	
	@Override
	public String description() {
		return "'"+view.getTitle()+"' view is open";
	}
	
	@Override
	public String errorMessageUntil() {
		return "'"+view.getTitle()+"' view is not open";
	}
	
	
	@Override
	public String errorMessageWhile() {
		return "'"+view.getTitle()+"' view is still open";
	}
	
	@SuppressWarnings("unchecked")
	@Override <commit_msg>ViewIsOpen condition should not call getTitle() on closed views. Fixes #1817<commit_after>/*******************************************************************************
 * Copyright (c) 2017 Red Hat, Inc and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.reddeer.workbench.condition;

import org.eclipse.reddeer.common.condition.AbstractWaitCondition;
import org.eclipse.reddeer.workbench.api.View;

/**
 * Wait condition for views checking whether specified view is open
 * 
 * @author <EMAIL>
 */
public class ViewIsOpen extends AbstractWaitCondition{
	
	private View view;
	private View resultView;
	
	/**
	 * Checks whether specified view is open
	 * @param view view to check if it is open
	 */
	public ViewIsOpen(View view) {
		this.view = view;
	}

	@Override
	public boolean test() {
		if (view.isOpen()) {
			this.resultView = view;
			return true;
		}
		return false;
	}
	
	@Override
	public String description() {
		return "'"+view.getClass()+"' view is open";
	}
	
	@Override
	public String errorMessageUntil() {
		return "'"+view.getClass()+"' view is not open";
	}
	
	
	@Override
	public String errorMessageWhile() {
		return "'"+view.getTitle()+"' view is still open";
	}
	
	@SuppressWarnings("unchecked")
	@Override 
{'fraction_non_alphanumeric': 0.19690754181129694, 'fraction_numerical': 0.006311139160618492, 'mean_word_length': 4.3367003367003365, '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': '2659179', 'n_tokens_mistral': 932, 'n_tokens_neox': 849, 'n_words': 288}