/*
 * Mutability Detector
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * Further licensing information for this project can be found in 
 * 		license/LICENSE.txt
 */

package org.mutabilitydetector.junit;

import java.util.Collection;

import org.mutabilitydetector.AnalysisSession;
import org.mutabilitydetector.CheckerReasonDetail;
import org.mutabilitydetector.IAnalysisSession;
import org.mutabilitydetector.IAnalysisSession.AnalysisResult;
import org.mutabilitydetector.IAnalysisSession.IsImmutable;

public class MutabilityAssert {

	private final static AssertionReporter reporter = new AssertionReporter();
	
	private static class AnalysisSessionHolder {
		static final IAnalysisSession assertionAnalysisSession = AnalysisSession.createWithCurrentClassPath();
	}
	
	public static void assertImmutable(Class<?> expectedImmutableClass) {
		String className = expectedImmutableClass.getName();
		AnalysisResult analysisResult = getResultFor(className);
		
		reporter.expectedImmutable(analysisResult);
	}

	private static AnalysisResult getResultFor(String className) {
		AnalysisResult analysisResult = AnalysisSessionHolder.assertionAnalysisSession.resultFor(className);
		return analysisResult;
	}

	public static String formatReasons(Collection<CheckerReasonDetail> reasons) {
		return reporter.formatReasons(reasons);
	}

	public static void assertImmutableStatusIs(IsImmutable expected, Class<?> forClass) {
		AnalysisResult analysisResult = getResultFor(forClass.getName());
		reporter.expectedIsImmutable(expected, analysisResult);
	}
	

}

@@ -307,38 +307,89 @@
 ort 
-java.util.Collection;%0A
+static org.mutabilitydetector.AnalysisSession.createWithCurrentClassPath;
 %0Aimport 
 org.
@@ -376,32 +376,39 @@
 assPath;%0Aimport 
+static 
 org.mutabilityde
@@ -406,32 +406,33 @@
 abilitydetector.
+I
 AnalysisSession;
@@ -422,33 +422,91 @@
 IAnalysisSession
-;
+.IsImmutable.DEFINITELY_NOT;%0A%0Aimport java.util.Collection;%0A
 %0Aimport org.muta
@@ -929,32 +929,16 @@
 ssion = 
-AnalysisSession.
 createWi
@@ -1740,12 +1740,442 @@
 t);%0A%09%7D%0A%09
+%0A%09public static class SingleMutabilityAssert %7B%0A%09%09%0A%09%09private final Class%3C?%3E clazz;%0A%0A%09%09public SingleMutabilityAssert(Class%3C?%3E clazz) %7B%0A%09%09%09this.clazz = clazz;%0A%09%09%7D%0A%09%09%0A%09%09public void isImmutable() %7B%0A%09%09%09assertImmutable(clazz);%0A%09%09%7D%0A%0A%09%09public void isNotImmutable() %7B%0A%09%09%09assertImmutableStatusIs(DEFINITELY_NOT, clazz);%0A%09%09%7D%0A%09%7D%0A%0A%09public static SingleMutabilityAssert assertThat(Class%3C?%3E clazz) %7B%0A%09%09return new SingleMutabilityAssert(clazz);%0A%09%7D
 %0A%0A%7D%0A

Allow a different style of asserting a class is immutable, which looks like: