Browsing 7239 questions and answers with Jon Skeet

Mockito: exception on mock InputStream#read(byte[] )

I want to get InputStream return the values I want. So I do: doAnswer(new Answer<Byte[]>() { @Override public Byte[] answer(InvocationOnMock invocationOnMock)...
Jon Skeet
people
quotationmark

You're trying to return a Byte[] from the call - but InputStream.read(byte[]) returns the number of bytes read, and stores the data in the byte array referenced by the parameter. So you'd need something like: doAnswer(new... more 6/17/2014 1:44:06 PM

people

Java Int Confusion

I understand that, in Java, there are no unsigned numbers, they're all signed with wizardry behind the scenes to make sense of it. So, I am puzzled by this, and it's probably...
Jon Skeet
people
quotationmark

This is specified in JLS section 3.10.1, which has different rules for decimal literals and literals of other bases: It is a compile-time error if a decimal literal of type int is larger than 2147483648 (231), or if the decimal literal... more 6/17/2014 1:39:24 PM

people

What does getNameCount() actually count?

My question has two parts - First, exactly what the title is - What is the Path.getNameCount() method actually counting? I read the little popup information that comes with it...
Jon Skeet
people
quotationmark

As documented, getNameCount() returns: the number of elements in the path, or 0 if this path only represents a root component So in your case, the elements are "Users", "Heather", "Desktop", "Testing" and "Testing2" - not the names... more 6/17/2014 1:23:59 PM

people

Java: Variable assignment issue

just a quick question and I'm probably gonna feel stupid for asking but still would like to know why it is so...! Anyways, quick example: x is a double. double conversion =...
Jon Skeet
people
quotationmark

The difference is between whether you do the multiplication first or the division first - and what the types of those operations are. This: (x - 32) * 5 / 9 is equivalent to: ((x - 32) * 5) / 9 So if the type of x is double, then... more 6/17/2014 12:41:26 PM

people

List Tuple more than 8 items

Can anyone help the following List Tuple more than 8 elements is not working: List<Tuple<int, string, double, string, int, string, double, Tuple<int, string>>>...
Jon Skeet
people
quotationmark

The problem is with the last argument to Tuple.Create. Look carefully at how the argument return value is defined: public static Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>> Create<T1, T2, T3, T4, T5, T6, T7, T8>( ... more 6/17/2014 12:29:06 PM

people

Mockito defining 'when' invokes the answer

I need to mock a JDBC update statement, and I want to make sure that the update string sent is the correct one. I have a MockConnectionManager that has the following method...
Jon Skeet
people
quotationmark

I suspect the problem is that your calls within the loop (when you call mockStatement.executeUpdate(expected)) match your earlier mock of when(mockStatement.executeUpdate(anyString())). Remember that the way the mock knows what you're... more 6/17/2014 11:44:04 AM

people

Calling an overridden superclass method from a subclass

public class F { protected int a=0, b=0; public F() { a = 2; b = 2; } public void increase() { upA(); } public void upA() { a = a + 1; } ...
Jon Skeet
people
quotationmark

All your methods are being called virtually, with overrides applying. So this code in F: public void increase() { upA(); } ... is invoking G.upA(), because the object it's calling upA() on is an instance of G. So the execution... more 6/17/2014 11:36:47 AM

people

System in a consolewriteline

I was studying for my test today and I came accross the sentence System.Console.WriteLine(); Could some one tell me what the System stands for cause when I remove it i dont...
Jon Skeet
people
quotationmark

System is just the namespace which contains the Console type. You almost certainly have a using directive like this in your code: using System; That imports every type within the namespace, so you can refer to it by its simple name.... more 6/17/2014 9:35:37 AM

people

Avoiding boxing in generic blackboard

A blackboard is an object that stores and fetches generic key-value pairs at runtime. It could be implemented by a Dictionary<object,object>. Some subsystem writes to the...
Jon Skeet
people
quotationmark

While I wouldn't want to do this (and I'd need persuading that the cost of boxing is really going to be significant), you could have your multiple stores and have a variable of type Dictionary<object, T> in your method - that way I... more 6/17/2014 8:50:03 AM

people

Compiler skipping foreach() loop during compilation?

I created a method in which i am configuring a networking device via telnet.The problem is that i have multiple values which i am configuring using foreach() loop but the compiler...
Jon Skeet
people
quotationmark

You're creating a new ObservableCollection<VLANSPropertyClass>(), but it's empty. Therefore when you iterate over it, you never end up in the body of the loop. You need to populate your collection somewhere, before it's useful to... more 6/17/2014 8:42:05 AM

people