/* 
 * 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.assertTrue;
import static org.mutabilitydetector.ImmutableAssert.assertImmutable;
import static org.mutabilitydetector.ImmutableAssert.assertNotImmutable;

import org.junit.Before;
import org.junit.Test;
import org.mutabilitydetector.CheckerRunner;
import org.mutabilitydetector.benchmarks.types.EnumType;
import org.mutabilitydetector.checkers.FinalClassChecker;




public class FinalClassCheckerTest {


	private FinalClassChecker finalFieldsChecker;

	@Before
	public void createChecker() {
		finalFieldsChecker = new FinalClassChecker();
	}

	@Test
	public void testAnalyseAClassWhichIsNotFinalMakesIsImmutableReturnFalse() throws Exception {
		runChecker(MutableByNotBeingFinalClass.class);
		
		assertNotImmutable(finalFieldsChecker.result());
		assertTrue("There should be a reason given when the class is not immutable.", finalFieldsChecker.reasons().size() > 0);
	}

	private void runChecker(Class<?> classToCheck) {
		new CheckerRunner(null).run(finalFieldsChecker, classToCheck);
	}
	
	
	@Test
	public void testImmutableExampleIsReportedAsImmutable() throws Exception {
		runChecker(ImmutableExample.class);
		assertImmutable(finalFieldsChecker.result());
		
	}
	
	@Test
	public void testEnumTypeIsImmutable() throws Exception {
		runChecker(EnumType.class);
		assertImmutable(finalFieldsChecker.result());
	}
	
}

@@ -829,27 +829,29 @@
 ssert.assert
-Not
+Maybe
 Immutable;%0A%0A
@@ -848,16 +848,74 @@
 mutable;
+%0Aimport static org.mutabilitydetector.TestUtil.runChecker;
 %0A%0Aimport
@@ -960,53 +960,8 @@
 st;%0A
-import org.mutabilitydetector.CheckerRunner;%0A
 impo
@@ -1072,19 +1072,16 @@
 ecker;%0A%0A
-%0A%0A%0A
 public c
@@ -1110,17 +1110,16 @@
 Test %7B%0A%0A
-%0A
 %09private
@@ -1137,28 +1137,17 @@
 Checker 
-finalFieldsC
+c
 hecker;%0A
@@ -1155,18 +1155,17 @@
 %09@Before
-%0A%09
+ 
 public v
@@ -1188,28 +1188,17 @@
 r() %7B%0A%09%09
-finalFieldsC
+c
 hecker =
@@ -1229,26 +1229,25 @@
 ;%0A%09%7D%0A%0A%09@Test
-%0A%09
+ 
 public void 
@@ -1250,20 +1250,9 @@
 oid 
-testAnalyseA
+a
 Clas
@@ -1271,15 +1271,15 @@
 inal
-MakesIs
+IsMaybe
 Immu
@@ -1287,19 +1287,8 @@
 able
-ReturnFalse
 () t
@@ -1299,32 +1299,53 @@
 s Exception %7B%0A%09%09
+assertMaybeImmutable(
 runChecker(Mutab
@@ -1339,16 +1339,25 @@
 Checker(
+checker, 
 MutableB
@@ -1386,61 +1386,8 @@
 ass)
-;%0A%09%09%0A%09%09assertNotImmutable(finalFieldsChecker.result()
 );%0A%09
@@ -1465,28 +1465,17 @@
 able.%22, 
-finalFieldsC
+c
 hecker.r
@@ -1504,136 +1504,16 @@
 %09%7D%0A%0A
-%09private void runChecker(Class%3C?%3E classToCheck) %7B%0A%09%09new CheckerRunner(null).run(finalFieldsChecker, classToCheck);%0A%09%7D%0A%09%0A
 %09%0A%09@Test
 %0A%09pu
@@ -1500,34 +1500,33 @@
 0);%0A%09%7D%0A%0A%09%0A%09@Test
-%0A%09
+ 
 public void test
@@ -1525,13 +1525,9 @@
 oid 
-testI
+i
 mmut
@@ -1574,32 +1574,48 @@
 s Exception %7B%0A%09%09
+assertImmutable(
 runChecker(Immut
@@ -1609,16 +1609,25 @@
 Checker(
+checker, 
 Immutabl
@@ -1645,60 +1645,10 @@
 ass)
+)
 ;
-%0A%09%09assertImmutable(finalFieldsChecker.result());%0A%09%09
 %0A%09%7D%0A
@@ -1655,18 +1655,17 @@
 %09%0A%09@Test
-%0A%09
+ 
 public v
@@ -1672,13 +1672,9 @@
 oid 
-testE
+e
 numT
@@ -1715,80 +1715,58 @@
 %7B%0A%09%09
-runChecker(EnumType.class);%0A%09%09assertImmutable(finalFieldsChecker.result(
+assertImmutable(runChecker(checker, EnumType.class
 ));%0A

Tidy up test class.