/* 
 * Mutability Detector
 *
 * Copyright 2009 Graham Allan
 * 
 * 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.mutabilitydetector.benchmarks;

import static org.junit.Assert.assertEquals;
import static org.mutabilitydetector.ImmutableAssert.assertDefinitelyNotImmutable;
import static org.mutabilitydetector.ImmutableAssert.assertImmutable;

import org.junit.Before;
import org.junit.Test;
import org.mutabilitydetector.CheckerRunner;
import org.mutabilitydetector.checkers.IMutabilityChecker;
import org.mutabilitydetector.checkers.PublishedNonFinalFieldChecker;




public class PublishedNonFinalFieldCheckerTest {

	private IMutabilityChecker checker;
	
	@Before
	public void setUp() {
		checker = new PublishedNonFinalFieldChecker();
	}
	
	@Test
	public void testImmutableExamplePassesCheck() throws Exception {
		new CheckerRunner(null).run(checker, ImmutableExample.class);
		assertImmutable(checker.result());
		assertEquals(0, checker.reasons().size());
	}
	
	
	@Test
	public void testClassWithPublicNonFinalFieldFailsCheck() throws Exception {
		new CheckerRunner(null).run(checker, MutableByHavingPublicNonFinalField.class);
		assertDefinitelyNotImmutable(checker.result());
	}
	
	@Test
	public void testClassWithProtectedNonFinalFieldFailsCheck() throws Exception {
		new CheckerRunner(null).run(checker, MutableByHavingProtectedNonFinalField.class);
		assertDefinitelyNotImmutable(checker.result());
	}
	
	@Test
	public void testClassWithDefaultVisibleNonFinalFieldFailsCheck() throws Exception {
		new CheckerRunner(null).run(checker, MutableByHavingDefaultVisibleNonFinalField.class);
		assertDefinitelyNotImmutable(checker.result());
	}
	
	@Test
	public void testClassWithPublicFinalFieldPassesCheck() throws Exception {
		new CheckerRunner(null).run(checker, ImmutableWithPublicFinalField.class);
		assertImmutable(checker.result());
		assertEquals(0, checker.reasons().size());
	}
}

@@ -679,22 +679,32 @@
 tic org.
-junit.
+hamcrest.Matcher
 Assert.a
@@ -708,22 +708,20 @@
 t.assert
-Equals
+That
 ;%0Aimport
@@ -866,16 +866,138 @@
 mutable;
+%0Aimport static org.mutabilitydetector.TestMatchers.hasNoReasons;%0Aimport static org.mutabilitydetector.TestUtil.runChecker;
 %0A%0Aimport
@@ -1068,29 +1068,30 @@
 etector.
-CheckerRunner
+AnalysisResult
 ;%0Aimport
@@ -1214,19 +1214,16 @@
 ecker;%0A%0A
-%0A%0A%0A
 public c
@@ -1301,16 +1301,48 @@
 hecker;%0A
+%09private AnalysisResult result;%0A
 %09%0A%09@Befo
@@ -1343,18 +1343,17 @@
 %09@Before
-%0A%09
+ 
 public v
@@ -1418,34 +1418,33 @@
 r();%0A%09%7D%0A%09%0A%09@Test
-%0A%09
+ 
 public void test
@@ -1443,13 +1443,9 @@
 oid 
-testI
+i
 mmut
@@ -1494,35 +1494,27 @@
 %7B%0A%09%09
-new CheckerRunner(null).run
+result = runChecker
 (che
@@ -1540,32 +1540,33 @@
 ple.class);%0A
+%0A
 %09%09assert
 Immutable(ch
@@ -1557,79 +1557,63 @@
 sert
-Immutable(checker.result());%0A%09%09assertEquals(0, checker.reasons().size()
+That(checker, hasNoReasons());%0A%09%09assertImmutable(result
 );%0A%09
@@ -1616,34 +1616,33 @@
 );%0A%09%7D%0A%09%0A%09%0A%09@Test
-%0A%09
+ 
 public void test
@@ -1629,37 +1629,33 @@
 est public void 
-testC
+c
 lassWithPublicNo
@@ -1703,35 +1703,27 @@
 %7B%0A%09%09
-new CheckerRunner(null).run
+result = runChecker
 (che
@@ -1802,32 +1802,22 @@
 mutable(
-checker.
 result
-()
 );%0A%09%7D%0A%09%0A
@@ -1814,34 +1814,33 @@
 lt);%0A%09%7D%0A%09%0A%09@Test
-%0A%09
+ 
 public void test
@@ -1827,37 +1827,33 @@
 est public void 
-testC
+c
 lassWithProtecte
@@ -1904,35 +1904,27 @@
 %7B%0A%09%09
-new CheckerRunner(null).run
+result = runChecker
 (che
@@ -2006,32 +2006,22 @@
 mutable(
-checker.
 result
-()
 );%0A%09%7D%0A%09%0A
@@ -2018,34 +2018,33 @@
 lt);%0A%09%7D%0A%09%0A%09@Test
-%0A%09
+ 
 public void test
@@ -2031,37 +2031,33 @@
 est public void 
-testC
+c
 lassWithDefaultV
@@ -2113,35 +2113,27 @@
 %7B%0A%09%09
-new CheckerRunner(null).run
+result = runChecker
 (che
@@ -2220,32 +2220,22 @@
 mutable(
-checker.
 result
-()
 );%0A%09%7D%0A%09%0A
@@ -2240,18 +2240,17 @@
 %09%0A%09@Test
-%0A%09
+ 
 public v
@@ -2257,13 +2257,9 @@
 oid 
-testC
+c
 lass
@@ -2317,35 +2317,27 @@
 %7B%0A%09%09
-new CheckerRunner(null).run
+result = runChecker
 (che
@@ -2392,79 +2392,63 @@
 sert
-Immutable(checker.result());%0A%09%09assertEquals(0, checker.reasons().size()
+That(checker, hasNoReasons());%0A%09%09assertImmutable(result
 );%0A%09

Tidy up test.