<commit_before>// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/intellij/intellij.dart';
import 'package:test/test.dart';

import '../src/context.dart';

void main() {
  group('IntelliJ', () {
    group('plugins', () {
      testUsingContext('found', () async {
        final String pluginsPath =
            fs.path.join('test', 'data', 'intellij', 'plugins');
        final IntelliJPlugins plugins = new IntelliJPlugins(pluginsPath);

        final List<ValidationMessage> messages = <ValidationMessage>[];
        plugins.validatePackage(messages,
            <String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
            minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
        plugins.validatePackage(messages, <String>['Dart'], 'Dart');

        ValidationMessage message = messages
            .firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
        expect(message.message, 'Dart plugin version 162.2485');

        message = messages.firstWhere(
            (ValidationMessage m) => m.message.startsWith('Flutter '));
        expect(message.message, contains('Flutter plugin version 0.1.3'));
        expect(message.message, contains('recommended minimum version'));
      });

      testUsingContext('not found', () async {
        final String pluginsPath =
            fs.path.join('test', 'data', 'intellij', 'no_plugins');
        final IntelliJPlugins plugins = new IntelliJPlugins(pluginsPath);

        final List<ValidationMessage> messages = <ValidationMessage>[];
        plugins.validatePackage(messages,
            <String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
            minVersion: IntelliJPlugins.kMinFlutterPluginVersion);
        plugins.validatePackage(messages, <String>['Dart'], 'Dart');

        ValidationMessage message = messages
            .firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
        expect(message.message, contains('Dart plugin not installed'));

        message = messages.firstWhere(
            (ValidationMessage m) => m.message.startsWith('Flutter '));
        expect(message.message, contains('Flutter plugin not installed'));
      });
    });
  });
}<commit_msg>Make IntelliJPlugins tests use MemoryFileSystem. (#16341)<commit_after>// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';

import 'package:archive/archive.dart';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/intellij/intellij.dart';
import 'package:test/test.dart';

import '../src/context.dart';

void main() {
  FileSystem fs;

  void writeFileCreatingDirectories(String path, List<int> bytes) {
    final File file = fs.file(path);
    file.parent.createSync(recursive: true);
    file.writeAsBytesSync(bytes);
  }

  setUp(() {
    fs = new MemoryFileSystem();
  });

  group('IntelliJ', () {
    group('plugins', () {
      testUsingContext('found', () async {
        final IntelliJPlugins plugins = new IntelliJPlugins(_kPluginsPath);

        final Archive dartJarArchive =
            buildSingleFileArchive('META-INF/plugin.xml', r'''
<idea-plugin version="2">
  <name>Dart</name>
  <version>162.2485</version>
</idea-plugin>
''');
        writeFileCreatingDirectories(
            fs.path.join(_kPluginsPath, 'Dart', 'lib', 'Dart.jar'),
            new ZipEncoder().encode(dartJarArchive));

        final Archive flutterJarArchive =
            buildSingleFileArchive('META-INF/plugin.xml', r'''
<idea-plugin version="2">
  <name>Flutter</name>
  <version>0.1.3</version>
</idea-plugin>
''');
        writeFileCreatingDirectories(
            fs.path.join(_kPluginsPath, 'flutter-intellij.jar'),
            new ZipEncoder().encode(flutterJarArchive));

        final List<ValidationMessage> messages = <ValidationMessage>[];
        plugins.validatePackage(messages, <String>['Dart'], 'Dart');
        plugins.validatePackage(messages,
            <String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
            minVersion: IntelliJPlugins.kMinFlutterPluginVersion);

        ValidationMessage message = messages
            .firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
        expect(message.message, 'Dart plugin version 162.2485');

        message = messages.firstWhere(
            (ValidationMessage m) => m.message.startsWith('Flutter '));
        expect(message.message, contains('Flutter plugin version 0.1.3'));
        expect(message.message, contains('recommended minimum version'));
      }, overrides: <Type, Generator>{
        FileSystem: () => fs,
      });

      testUsingContext('not found', () async {
        final IntelliJPlugins plugins = new IntelliJPlugins(_kPluginsPath);

        final List<ValidationMessage> messages = <ValidationMessage>[];
        plugins.validatePackage(messages, <String>['Dart'], 'Dart');
        plugins.validatePackage(messages,
            <String>['flutter-intellij', 'flutter-intellij.jar'], 'Flutter',
            minVersion: IntelliJPlugins.kMinFlutterPluginVersion);

        ValidationMessage message = messages
            .firstWhere((ValidationMessage m) => m.message.startsWith('Dart '));
        expect(message.message, contains('Dart plugin not installed'));

        message = messages.firstWhere(
            (ValidationMessage m) => m.message.startsWith('Flutter '));
        expect(message.message, contains('Flutter plugin not installed'));
      }, overrides: <Type, Generator>{
        FileSystem: () => fs,
      });
    });
  });
}

const String _kPluginsPath = '/data/intellij/plugins';

Archive buildSingleFileArchive(String path, String content) {
  final Archive archive = new Archive();

  final List<int> bytes = utf8.encode(content);
  archive.addFile(new ArchiveFile(path, bytes.length, bytes));

  return archive;
}
{'fraction_non_alphanumeric': 0.13710572198446663, 'fraction_numerical': 0.00729117134252655, 'mean_word_length': 3.497505345687812, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '527379', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1784, 'n_words': 369}