@@ -14,6 +14,7 @@ import org.junit.Test
1414import  software.amazon.awssdk.regions.Region 
1515import  software.amazon.awssdk.services.codewhispererruntime.model.OptOutPreference 
1616import  software.amazon.awssdk.services.ssooidc.SsoOidcClient 
17+ import  software.aws.toolkits.core.utils.test.aStringWithLineCount 
1718import  software.aws.toolkits.jetbrains.core.MockClientManagerRule 
1819import  software.aws.toolkits.jetbrains.core.credentials.LegacyManagedBearerSsoConnection 
1920import  software.aws.toolkits.jetbrains.core.credentials.sono.Q_SCOPES 
@@ -119,83 +120,45 @@ class CodeWhispererUtilTest {
119120
120121    @Test
121122    fun  `toCodeChunk case_2`  () {
122-         val  psiFile =  fixture.configureByText(" Sample.java"  , codeSample33Lines)
123+         val  fakeCodeWith210Lines =  aStringWithLineCount(210 )
124+         val  psiFile =  fixture.configureByText(" Sample.java"  , fakeCodeWith210Lines)
123125
124126        val  result =  runBlocking {
125127            psiFile.virtualFile.toCodeChunk(" fake/path"  )
126128        }.toList()
127129
128-         assertThat(result).hasSize(5 )
130+         //  210 / 50 + 2
131+         assertThat(result).hasSize(6 )
129132
130133        //  0th
131-         assertThat(result[0 ].content).isEqualTo(
132-             """ public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
133-                 |    int middle = low  + ((high - low) / 2); 
134-             """  .trimMargin()
135-         )
134+         assertThat(result[0 ].content).isEqualTo(aStringWithLineCount(3 ))
136135        assertThat(result[0 ].path).isEqualTo(" fake/path"  )
137-         assertThat(result[0 ].nextChunk).isEqualTo(result[ 1 ].content )
136+         assertThat(result[0 ].nextChunk).isEqualTo(aStringWithLineCount( 50 , start  =   0 ) )
138137
139138        //  1st
140-         assertThat(result[1 ].content).isEqualTo(
141-             """ |public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
142-                     |    int middle = low  + ((high - low) / 2); 
143-                     |     
144-                     |    if (high < low) { 
145-                     |        return -1; 
146-                     |    } 
147-                     | 
148-                     |    if (key == sortedArray[middle]) { 
149-                     |        return middle; 
150-                     |    } else if (key < sortedArray[middle]) { 
151-             """  .trimMargin()
152-         )
139+         assertThat(result[1 ].content).isEqualTo(aStringWithLineCount(50 , start =  0 ))
153140        assertThat(result[1 ].path).isEqualTo(" fake/path"  )
154-         assertThat(result[1 ].nextChunk).isEqualTo(result[ 2 ].content )
141+         assertThat(result[1 ].nextChunk).isEqualTo(aStringWithLineCount( 50 , start  =   50 ) )
155142
156143        //  2nd
157-         assertThat(result[2 ].content).isEqualTo(
158-             """ |        return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
159-                |    } else { 
160-                |        return runBinarySearchRecursively(sortedArray, key, middle + 1, high); 
161-                |    } 
162-                |} 
163-                | 
164-                |public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) { 
165-                |    int index = Integer.MAX_VALUE; 
166-                |     
167-                |    while (low <= high) { 
168-             """  .trimMargin()
169-         )
144+         assertThat(result[2 ].content).isEqualTo(aStringWithLineCount(50 , start =  50 ))
170145        assertThat(result[2 ].path).isEqualTo(" fake/path"  )
171-         assertThat(result[2 ].nextChunk).isEqualTo(result[ 3 ].content )
146+         assertThat(result[2 ].nextChunk).isEqualTo(aStringWithLineCount( 50 , start  =   100 ) )
172147
173148        //  3rd
174-         assertThat(result[3 ].content).isEqualTo(
175-             """ |        int mid = low  + ((high - low) / 2);
176-        |        if (sortedArray[mid] < key) { 
177-        |            low = mid + 1; 
178-        |        } else if (sortedArray[mid] > key) { 
179-        |            high = mid - 1; 
180-        |        } else if (sortedArray[mid] == key) { 
181-        |            index = mid; 
182-        |            break; 
183-        |        } 
184-        |     } 
185-             """  .trimMargin()
186-         )
149+         assertThat(result[3 ].content).isEqualTo(aStringWithLineCount(50 , start =  100 ))
187150        assertThat(result[3 ].path).isEqualTo(" fake/path"  )
188-         assertThat(result[3 ].nextChunk).isEqualTo(result[ 4 ].content )
151+         assertThat(result[3 ].nextChunk).isEqualTo(aStringWithLineCount( 50 , start  =   150 ) )
189152
190153        //  4th
191-         assertThat(result[4 ].content).isEqualTo(
192-             """ |    
193-                |    return index; 
194-                |} 
195-             """  .trimMargin()
196-         )
154+         assertThat(result[4 ].content).isEqualTo(aStringWithLineCount(50 , start =  150 ))
197155        assertThat(result[4 ].path).isEqualTo(" fake/path"  )
198-         assertThat(result[4 ].nextChunk).isEqualTo(result[4 ].content)
156+         assertThat(result[4 ].nextChunk).isEqualTo(aStringWithLineCount(10 , start =  200 ))
157+ 
158+         //  5th
159+         assertThat(result[5 ].content).isEqualTo(aStringWithLineCount(10 , start =  200 ))
160+         assertThat(result[5 ].path).isEqualTo(" fake/path"  )
161+         assertThat(result[5 ].nextChunk).isEqualTo(aStringWithLineCount(10 , start =  200 ))
199162    }
200163
201164    @Test
@@ -230,40 +193,3 @@ class CodeWhispererUtilTest {
230193        assertThat(getTelemetryOptOutPreference()).isEqualTo(OptOutPreference .OPTOUT )
231194    }
232195}
233- 
234- private  val  codeSample33Lines = 
235-     """ public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
236-        |    int middle = low  + ((high - low) / 2); 
237-        |     
238-        |    if (high < low) { 
239-        |        return -1; 
240-        |    } 
241-        | 
242-        |    if (key == sortedArray[middle]) { 
243-        |        return middle; 
244-        |    } else if (key < sortedArray[middle]) { 
245-        |        return runBinarySearchRecursively(sortedArray, key, low, middle - 1); 
246-        |    } else { 
247-        |        return runBinarySearchRecursively(sortedArray, key, middle + 1, high); 
248-        |    } 
249-        |} 
250-        | 
251-        |public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) { 
252-        |    int index = Integer.MAX_VALUE; 
253-        |     
254-        |    while (low <= high) { 
255-        |        int mid = low  + ((high - low) / 2); 
256-        |        if (sortedArray[mid] < key) { 
257-        |            low = mid + 1; 
258-        |        } else if (sortedArray[mid] > key) { 
259-        |            high = mid - 1; 
260-        |        } else if (sortedArray[mid] == key) { 
261-        |            index = mid; 
262-        |            break; 
263-        |        } 
264-        |     } 
265-        |     
266-        |    return index; 
267-        |} 
268-        | 
269-     """  .trimMargin()
0 commit comments