// Path: src/main/java/cz/sigler/android/aavalidation/api/error/ValidationError.java
// public class ValidationError {
// 
// 	/** Database column name. */
// 	private String columnName;
// 
// 	/** Error message. */
// 	private String message;
// 
// 	/** Name of model field that caused the validation error. */
// 	private String fieldName;
// 
// 	/**
// 	 * Constructor.
// 	 *
// 	 * @param columnName
// 	 *			database column name
// 	 * @param fieldName
// 	 *			model field name
// 	 * @param message
// 	 *			error message
// 	 */
// 	public ValidationError(final String columnName, final String fieldName, final String message) {
// 		this.columnName = columnName;
// 		this.message = message;
// 		this.fieldName = fieldName;
// 	}
// 
// 	/**
// 	 * @return name of model field that caused the validation error
// 	 */
// 	public String getFieldName() {
// 		return fieldName;
// 	}
// 
// 	/**
// 	 * @return name of database column that is bound to the invalid field
// 	 */
// 	public String getColumnName() {
// 		return columnName;
// 	}
// 
// 	/**
// 	 * @return error message describing the error
// 	 */
// 	public String getMessage() {
// 		return message;
// 	}
// }
// 
// Path: src/test/java/cz/sigler/android/aavalidation/validator/UniqueValidatorTest.java
// public static class TestModel extends ValidatingModel {
// 
// 	@Column(name = COLUMN_NAME)
// 	@Unique(message = ERROR_MESSAGE)
// 	private Object testField;
// 
// 	public Object getTestField() {
// 		return testField;
// 	}
// 
// 	public void setTestField(Object testField) {
// 		this.testField = testField;
// 	}
// }
// 
// Path: src/main/java/cz/sigler/android/aavalidation/ValidatingModel.java
// public abstract class ValidatingModel extends Model implements IValidatingModel {
// 
// 	/** List of errors from last validation. */
// 	private List<ValidationError> errors = new LinkedList<ValidationError>();
// 
// 	/**
// 	 * {@inheritDoc }
// 	 */
// 	@Override
// 	public List<ValidationError> getErrors() {
// 		return new LinkedList<ValidationError>(errors);
// 	}
// 
// 	/**
// 	 * {@inheritDoc }
// 	 */
// 	@Override
// 	public boolean isValid() {
// 		ValidationExecutor executor = new ValidationExecutor(this);
// 		errors = executor.execute();
// 
// 		return errors.isEmpty();
// 	}
// 
// 	/**
// 	 * {@inheritDoc }
// 	 */
// 	@Override
// 	public void saveOrThrow() throws ValidationException {		
// 		if (isValid()) {
// 			save();
// 		} else {			
// 			throw new ValidationException(getErrors());
// 		}
// 	}
// }


import cz.sigler.android.aavalidation.api.error.ValidationError;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import android.content.ContentValues;
import com.activeandroid.annotation.Column;
import com.activeandroid.util.SQLiteUtils;
import cz.sigler.android.aavalidation.validator.UniqueValidatorTest.TestModel;
import cz.sigler.android.aavalidation.ValidatingModel;
import cz.sigler.android.aavalidation.rule.Unique;
import java.util.List;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
/*
 * Copyright (C) 2013 Vojtech Sigler.
 *
 * 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 cz.sigler.android.aavalidation.validator;



/**
 * Tests Unique constraint.
 */
@PrepareForTest({SQLiteUtils.class, TestModel.class, ContentValues.class})
public class UniqueValidatorTest extends ValidatorTestBase {

	@Override
	protected void onSetup() {
		PowerMockito.mockStatic(SQLiteUtils.class);

		TestModel model = PowerMockito.mock(TestModel.class);
		PowerMockito.when(model.getId()).thenReturn(ID);

		PowerMockito.when(SQLiteUtils.rawQuerySingle(eq(TestModel.class), anyString(), eq(new String[] {DUMMY}))).thenReturn(model);
		PowerMockito.when(SQLiteUtils.rawQuerySingle(eq(TestModel.class), anyString(), eq(new String[] {}))).thenReturn(model);
	}

	@Override
	protected ValidatingModel getModelNegative() {
		TestModel model = new TestModel();
		model.setTestField(DUMMY + 1);
		return model;
	}

	@Override
	protected ValidatingModel getModelPositive() {
		TestModel model = new TestModel();
		model.setTestField(DUMMY);
		return model;
	}

	/**
	 * Null is also considered for uniqueness.
	 * Tests case where the checked field is null and there already is an
	 * existing record with that field null.
	 */
	@Test
	public void testValidatePositive_NullMatch() {
// Path: src/main/java/cz/sigler/android/aavalidation/api/error/ValidationError.java
// public class ValidationError {
// 
// 	/** Database column name. */
// 	private String columnName;
// 
// 	/** Error message. */
// 	private String message;
// 
// 	/** Name of model field that caused the validation error. */
// 	private String fieldName;
// 
// 	/**
// 	 * Constructor.
// 	 *
// 	 * @param columnName
// 	 *			database column name
// 	 * @param fieldName
// 	 *			model field name
// 	 * @param message
// 	 *			error message
// 	 */
// 	public ValidationError(final String columnName, final String fieldName, final String message) {
// 		this.columnName = columnName;
// 		this.message = message;
// 		this.fieldName = fieldName;
// 	}
// 
// 	/**
// 	 * @return name of model field that caused the validation error
// 	 */
// 	public String getFieldName() {
// 		return fieldName;
// 	}
// 
// 	/**
// 	 * @return name of database column that is bound to the invalid field
// 	 */
// 	public String getColumnName() {
// 		return columnName;
// 	}
// 
// 	/**
// 	 * @return error message describing the error
// 	 */
// 	public String getMessage() {
// 		return message;
// 	}
// }
// 
// Path: src/test/java/cz/sigler/android/aavalidation/validator/UniqueValidatorTest.java
// public static class TestModel extends ValidatingModel {
// 
// 	@Column(name = COLUMN_NAME)
// 	@Unique(message = ERROR_MESSAGE)
// 	private Object testField;
// 
// 	public Object getTestField() {
// 		return testField;
// 	}
// 
// 	public void setTestField(Object testField) {
// 		this.testField = testField;
// 	}
// }
// 
// Path: src/main/java/cz/sigler/android/aavalidation/ValidatingModel.java
// public abstract class ValidatingModel extends Model implements IValidatingModel {
// 
// 	/** List of errors from last validation. */
// 	private List<ValidationError> errors = new LinkedList<ValidationError>();
// 
// 	/**
// 	 * {@inheritDoc }
// 	 */
// 	@Override
// 	public List<ValidationError> getErrors() {
// 		return new LinkedList<ValidationError>(errors);
// 	}
// 
// 	/**
// 	 * {@inheritDoc }
// 	 */
// 	@Override
// 	public boolean isValid() {
// 		ValidationExecutor executor = new ValidationExecutor(this);
// 		errors = executor.execute();
// 
// 		return errors.isEmpty();
// 	}
// 
// 	/**
// 	 * {@inheritDoc }
// 	 */
// 	@Override
// 	public void saveOrThrow() throws ValidationException {		
// 		if (isValid()) {
// 			save();
// 		} else {			
// 			throw new ValidationException(getErrors());
// 		}
// 	}
// }


// Path: src/test/java/cz/sigler/android/aavalidation/validator/UniqueValidatorTest.java
import cz.sigler.android.aavalidation.api.error.ValidationError;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import android.content.ContentValues;
import com.activeandroid.annotation.Column;
import com.activeandroid.util.SQLiteUtils;
import cz.sigler.android.aavalidation.validator.UniqueValidatorTest.TestModel;
import cz.sigler.android.aavalidation.ValidatingModel;
import cz.sigler.android.aavalidation.rule.Unique;
import java.util.List;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;

/*
 * Copyright (C) 2013 Vojtech Sigler.
 *
 * 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 cz.sigler.android.aavalidation.validator;



/**
 * Tests Unique constraint.
 */
@PrepareForTest({SQLiteUtils.class, TestModel.class, ContentValues.class})
public class UniqueValidatorTest extends ValidatorTestBase {

	@Override
	protected void onSetup() {
		PowerMockito.mockStatic(SQLiteUtils.class);

		TestModel model = PowerMockito.mock(TestModel.class);
		PowerMockito.when(model.getId()).thenReturn(ID);

		PowerMockito.when(SQLiteUtils.rawQuerySingle(eq(TestModel.class), anyString(), eq(new String[] {DUMMY}))).thenReturn(model);
		PowerMockito.when(SQLiteUtils.rawQuerySingle(eq(TestModel.class), anyString(), eq(new String[] {}))).thenReturn(model);
	}

	@Override
	protected ValidatingModel getModelNegative() {
		TestModel model = new TestModel();
		model.setTestField(DUMMY + 1);
		return model;
	}

	@Override
	protected ValidatingModel getModelPositive() {
		TestModel model = new TestModel();
		model.setTestField(DUMMY);
		return model;
	}

	/**
	 * Null is also considered for uniqueness.
	 * Tests case where the checked field is null and there already is an
	 * existing record with that field null.
	 */
	@Test
	public void testValidatePositive_NullMatch() {
		TestModel model = new TestModel();