package de.philipphager.disclosure.feature.analyzer.app;

import de.philipphager.disclosure.database.mocks.MockApp;
import de.philipphager.disclosure.feature.analyser.app.Apk;
import de.philipphager.disclosure.feature.analyser.app.ApkAnalyzer;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import rx.Observable;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class ApkAnalyzerShould {
  private final String mockClass = "com.facebook.android.sdk";
  private final String mockClassTwo = "com.mixpanel.android";
  private final String mockClassThree = "com.mixpanel.android.MainClass";
  private final List<String> classes = Arrays.asList(mockClass, mockClassTwo, mockClassThree);
  @Mock protected Apk mockApk;

  @Before public void setUp() throws Exception {
    when(mockApk.getApp()).thenReturn(MockApp.TEST);
  }

  @Test @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
  public void loadApkClassesOnInit() {
    when(mockApk.getUsedClasses()).thenReturn(Observable.just(classes));
    ApkAnalyzer apkAnalyzer = new ApkAnalyzer(mockApk);

    verify(mockApk).getUsedClasses();
  }

  @Test public void findLibraryIfApkContainsExactClassName() {
    when(mockApk.getUsedClasses()).thenReturn(Observable.just(classes));
    ApkAnalyzer apkAnalyzer = new ApkAnalyzer(mockApk);

    assertThat(apkAnalyzer.usesLibrary(mockClass)).isTrue();
  }

  @Test public void findLibraryIfApkContainsClassThatStartsWithName() {
    when(mockApk.getUsedClasses()).thenReturn(Observable.just(classes));
    ApkAnalyzer apkAnalyzer = new ApkAnalyzer(mockApk);

    String classPrefix = mockClass.substring(0, 10);

    assertThat(apkAnalyzer.usesLibrary(classPrefix)).isTrue();
  }

  @Test public void notFindLibraryIfClassNameIsNotContainedInApk() {
    when(mockApk.getUsedClasses()).thenReturn(Observable.just(classes));
    ApkAnalyzer apkAnalyzer = new ApkAnalyzer(mockApk);

    String mockClassNameInvalid = "this.class.is.not.in.the.apk";

    assertThat(apkAnalyzer.usesLibrary(mockClassNameInvalid)).isFalse();
  }

  @Test public void notFailIfApkContainsNoClasses() {
    when(mockApk.getUsedClasses()).thenReturn(Observable.just(Collections.EMPTY_LIST));
    ApkAnalyzer apkAnalyzer = new ApkAnalyzer(mockApk);

    assertThat(apkAnalyzer.usesLibrary(mockClass)).isFalse();
  }
}

@@ -702,32 +702,39 @@
 uld %7B%0A  private 
+static 
 final String moc
@@ -730,25 +730,26 @@
  String 
-mockClass
+MOCK_CLASS
  = %22com.
@@ -773,32 +773,39 @@
 sdk%22;%0A  private 
+static 
 final String moc
@@ -801,28 +801,30 @@
  String 
-mockClassTwo
+MOCK_CLASS_TWO
  = %22com.
@@ -848,24 +848,31 @@
 ;%0A  private 
+static 
 final String
@@ -872,30 +872,32 @@
  String 
-mockClassThree
+MOCK_CLASS_THREE
  = %22com.
@@ -982,47 +982,52 @@
 ist(
-mockClass, mockClassTwo, mockClassThree
+MOCK_CLASS, MOCK_CLASS_TWO, MOCK_CLASS_THREE
 );%0A 
@@ -1346,34 +1346,8 @@
 %0A   
- ApkAnalyzer apkAnalyzer =
  new
@@ -1641,33 +1641,34 @@
 usesLibrary(
-mockClass
+MOCK_CLASS
 )).isTrue();
@@ -1900,25 +1900,26 @@
 refix = 
-mockClass
+MOCK_CLASS
 .substri
@@ -2580,25 +2580,26 @@
 Library(
-mockClass
+MOCK_CLASS
 )).isFal

Fix PMD