Cannot import hamcrest matchers for some reason - hamcrest

I am super new to unit testing and java in general, so my apologies for the basic question. However, when I try to import import static org.hamcrest.Matchers.hasEntry; I get a message saying "cannot resolve symbol 'Matchers'. I'm trying to use hasEntry to unit test a method that returns a map.
Here are the imports I have
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
the top two are working fine, but I can't get the last one to work. If anyone has any suggestions as to how to fix the problem, or if there is another way I can import hasEntry, please let me know! Thank you

Which version of Hamcrest are you using?
It would be great if you put your pom.xml file here to facilitate the analysis.
Maybe you only need to trigger another import maven command (with force update snapshots) in your IDE, for example, to refresh your local dependencies.
Or you can try this:
mvn --batch-mode --update-snapshots clean package

Related

Flutter - Is there an effect on having a single import rather than multiple?

Basically I have a lot of widgets and services and stuff, like most people do, that I need to access throughout the app. I was wondering if have a single file with an export of every single file and then just simply importing that one file in every page/file i need to access something rather than just importing specific files that the page needs, will it slow down the app or cause any issues or increase file size, etc... or will it behave the same?
Example
login_page.dart
import '1.dart'
import '2.dart'
home_page.dart
import '2.dart'
import '3.dart'
import '9.dart'
import '10.dart'
settings_page.dart
import '1.dart'
import '2.dart'
import '9.dart'
import '10.dart'
or...
all_imports.dart:
export '1.dart'
export '2.dart'
export '3.dart'
... (up until)
export '10.dart'
in every dart file:
import 'all_imports.dart'
Using 'all_imports.dart' may cause unneeded dependencies but dart knows how to handle dependencies that called but not used.
Same implementation of 'all_imports.dart' is used by flutter team on 'material.dart'
You may wish to just make simple design but when you import 'material.dart' it brings everything to the table ('about.dart', 'app.dart', 'banner.dart') and many others.
I would advise you structure your application using 'all_import.dart' pattern
actually, it dosent make a difference, lets imagine this case
in login_page.dart
import '1.dart'
import '2.dart'
here you are being explicit about the dependencies of this module/file/widget, which means it only uses what it needs. which is better for maintenance and redablity of the modules dependanices.
the other case where you have all of your imports in one file
import 'all_imports.dart'
lets see what happens here:
Dart executes the file all_imports.dart
that file is importing every module that you have listed in that file
so the import calls happend again
which means that wont affect your software's performance if you dont have an all_imports.dart file.
actulally i find that this method(the all_imports.dart) will affect your program in a bad way if any.
why? lets say we have a module A that depends on both module B and module C , you would import them this way
moduleA.dart
import 'moduleB'
import 'moduleC'
the advantages is that the module is now explicit in its dependencies and anyone who looks at this module/file in the future will know what they are.
however
the other method where you have all of your imports in a single all_imports.dart file, will cause unneeded dependencies to be loaded for a certain module
lets have the same example above, module A depends on moduleB and moduleC and you listed them in the all_imports.dart file, it will look like this
export `moduleA'
export 'moduleB'
/// some other modules that you are exporting
and in the moduleA.dart file you import it this way
import 'all_imports.dart`
now
the module A has successfully imported moduleB and moduleC which it needs. BUT, now it has all the other dependancies that it dose not need loaded for it although it only needs moduleA and moduleB.

Error: Don't import implementation files from another package

I am trying to make a custom stepper in Flutter. I copied the implementation of stepper.dart, save my file to my own lib folder and fixed the imports to remove the errors.
import 'package:flutter/src/material/button_theme.dart';
import 'package:flutter/src/material/colors.dart';
import 'package:flutter/src/material/debug.dart';
import 'package:flutter/src/material/flat_button.dart';
import 'package:flutter/src/material/icons.dart';
import 'package:flutter/src/material/ink_well.dart';
import 'package:flutter/src/material/material.dart';
import 'package:flutter/src/material/material_localizations.dart';
import 'package:flutter/src/material/theme.dart';
import 'package:flutter/src/material/typography.dart';
Errors are removed but dart says that "Don't import implementation files from another package."
May I know if it's safe to proceed? OR is there another way to implement custom widgets? Or should I transfer the location of my custom stepper file? Thanks.
Flutter Material Widgets are not meant to be subclassed. Here is what I do to create a customized version of a Widget:
(1) Find the source file of the original widget and copy it to the lib directory of your project.
(you already did that)
(2) remove all import statements from the copied file and insert the line
import 'package:flutter/material.dart'; instead
(3) Check the Dart Analysis for missing packages. To add those click on the unknown (red underlined) class name in the copied source file then hit ALT+Enter and select the context menu entry that offers to add the missing dependency.
(4) Now modify the Widget to your hearts delight.
(5) to use the modified Widget in your project import it like this:
import 'stepper.dart' as my;
(6) You can now access your modified stepper as
my.Stepper stepper = my.Stepper(...);
lib/src from other packages is considered to be private by convention.
The analyzer explains that you shouldn't import such files.
Flutter exports everything it considers public under package:flutter/... anyway. Import these files instead.
See also https://www.dartlang.org/tools/pub/package-layout#implementation-files

could not find or load class org.testng.TestNg

I am trying to understand how to use Ant script and testNG. I am new to Ant
I am following this tutorial Link http://seleniumeasy.com/ant-tutorials/how-to-run-testng-tests-using-build-xml-file
The build seems to be successful however i get the following error in cmd :
Error: Could not find or load main class org.testing.Test
I'm guessing you have local code that declares a package of "org.testing"? Much better idea to ensure your classes belong to a namespace peculiar to you.
The Selenium imports are:
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

I see an angular2 'bind' function defined in angular2/angular2.d.ts - did it used to be in 'angular2/di.d.ts?

Many of the samples I have seen for angular2 have the following import statement:
import {bind} from 'angular2/di';
I am working in VS Code (with TypeScript) and it complains about not being able to find the angular2/di module.
However I do see a bind function defined in angular2/angular2.d.ts. If I change the import statement to the following, then the error goes away.
import {bind} from 'angular2/angular2';
Is the question in the title off-base and I am making some erroneous assumption?
If not, why do many samples reference one module to import the bind function from, yet I seem to be able to get it from a different module?
Most likely because you looked at versions from older alphas. Look at the angular2.ts file. Everything is exported from it. Also note that the d.ts is going to contain everything to resolve types in your IDE and at compilation time. What import does is actually importing the .js files.

Unable to import org.apache.common.collections.list

I am using Groovy Grails Tool Suite for my Grails project.
I am trying to use LazyList.decorate in one of my domain classes and so want to import org.apache.common.collections.list within the domain class.
I see that org.apache.commons.collections_3.2.0.v2013030210310.jar is available under the GGTS plugins folder.
However, the editor shows an error at the import statement saying "Groovy: Unable to resolve org.apache.common.collections.list".
Please help!
Since the question is missing a code snippet I suspect you have a line like this import org.apache.common.collections.list. You should do import org.apache.common.collections.list.* - or if only LazyList is what you want: import org.apache.common.collections.list.LazyList

Resources